From 3a600e37c733c1f031bf717874fea95e92b4c324 Mon Sep 17 00:00:00 2001 From: "philip.cline" Date: Mon, 6 Nov 2023 16:59:22 -0500 Subject: [PATCH] refactor(ExportPatternsModal): allow pattern export for snapshots --- i18n/english.yml | 8 ++- i18n/german.yml | 2 +- i18n/polish.yml | 2 +- lib/common/components/ExportPatternsModal.js | 62 +++++++++++++++++++ .../components/EditorFeedSourcePanel.js | 18 ++++-- lib/manager/actions/versions.js | 5 +- 6 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 lib/common/components/ExportPatternsModal.js diff --git a/i18n/english.yml b/i18n/english.yml index c9ac264d3..0cb0e5cce 100644 --- a/i18n/english.yml +++ b/i18n/english.yml @@ -88,7 +88,7 @@ components: publishNewVersion: label: Publish snapshot as new feed version publishProprietaryFiles: - helpText: Proprietary files allow you to maintain Datatools certain proprietary features across feed version, e.g. Pattern names. + helpText: Proprietary files allow you to maintain certain proprietary Datatools features across feed version, e.g. Pattern names. label: Publish new feed version with proprietary (extra) datatools files. confirmPublishWithUnapproved: label: Confirm publish with unapproved routes @@ -291,6 +291,7 @@ components: load: Load for Editing loadLatest: Load latest for editing name: Name + noOtherSnapshots: No other snapshots noSnapshotsExist: No snapshots currently exist for this feed. Snapshots can be created within the Editor. Click "Edit Feed" to enter editing mode. noVersions: (No Versions) noVersionsExist: No versions exist for this feed source. @@ -337,6 +338,11 @@ components: deleteRange: Delete range ExceptionValidationErrorsList: andOtherErrors: ...and %errors% other errors + ExportPatternsModal: + exportPatterns: Publish version with proprietary patterns? + exportPatternsBody: A lot of text + yes: Yes + no: No FeedFetchFrequency: DAYS: days fetchFeedEvery: Fetch feed every diff --git a/i18n/german.yml b/i18n/german.yml index 7249dc09c..380bd0488 100644 --- a/i18n/german.yml +++ b/i18n/german.yml @@ -81,7 +81,7 @@ components: publishNewVersion: label: Veröffentliche Schnappschuss als neue Feed-Version publishProprietaryFiles: - helpText: Proprietary files allow you to maintain Datatools certain proprietary features across feed version, e.g. Pattern names. + helpText: Proprietary files allow you to maintain certain proprietary Datatools features across feed version, e.g. Pattern names. label: Publish new feed version with proprietary (extra) datatools files. missingNameAlert: Gültiger Schnappschuss-Name erforderlich! ok: OK diff --git a/i18n/polish.yml b/i18n/polish.yml index 6a0e197a9..93e0c54c1 100644 --- a/i18n/polish.yml +++ b/i18n/polish.yml @@ -80,7 +80,7 @@ components: publishNewVersion: label: Publikuj migawkę jako nowa wersja pliku publishProprietaryFiles: - helpText: Proprietary files allow you to maintain Datatools certain proprietary features across feed version, e.g. Pattern names. + helpText: Proprietary files allow you to maintain certain proprietary Datatools features across feed version, e.g. Pattern names. label: Publish new feed version with proprietary (extra) datatools files. missingNameAlert: Migawce należy nadać prawidłową nazwę! ok: OK diff --git a/lib/common/components/ExportPatternsModal.js b/lib/common/components/ExportPatternsModal.js new file mode 100644 index 000000000..c3ca2038d --- /dev/null +++ b/lib/common/components/ExportPatternsModal.js @@ -0,0 +1,62 @@ +// @flow + +import React from 'react' +import { Modal, Button } from 'react-bootstrap' + +import {getComponentMessages} from '../../common/util/config' +import * as versionActions from '../../manager/actions/versions' +import type { Feed, Snapshot } from '../../types' +import type { ItemProps } from '../../editor/components/EditorFeedSourcePanel' + +type Props = { + createFeedVersionFromSnapshot: typeof versionActions.createFeedVersionFromSnapshot, + feedSource: Feed, +} + +type State = { + showModal: boolean, + snapshot: ?Snapshot +} + +export default class ExportPatternsModal extends React.Component { + messages = getComponentMessages('ExportPatternsModal') + + state = { + showModal: false, + snapshot: null + } + + publish (publishProprietaryFiles: boolean) { + const { createFeedVersionFromSnapshot, feedSource } = this.props + this.state.snapshot && createFeedVersionFromSnapshot(feedSource, this.state.snapshot.id, publishProprietaryFiles) + this.close() + } + + close () { + this.setState({showModal: false}) + } + + // Open is called by the SnapshotItem class + open (props: ItemProps) { + this.setState({showModal: true, snapshot: props.snapshot}) + } + + render () { + const {Body, Title} = Modal + const buttonStyle = {marginLeft: '10px', width: '50px'} + + return ( + + + {this.messages('exportPatterns')} + + + + + ) + } +} diff --git a/lib/editor/components/EditorFeedSourcePanel.js b/lib/editor/components/EditorFeedSourcePanel.js index f1425a6cf..21366f104 100644 --- a/lib/editor/components/EditorFeedSourcePanel.js +++ b/lib/editor/components/EditorFeedSourcePanel.js @@ -8,6 +8,7 @@ import moment from 'moment' import * as snapshotActions from '../actions/snapshots.js' import ConfirmModal from '../../common/components/ConfirmModal' +import ExportPatternsModal from '../../common/components/ExportPatternsModal.js' import {getComponentMessages, getConfigProperty} from '../../common/util/config' import CreateSnapshotModal from '../../editor/components/CreateSnapshotModal' import * as versionActions from '../../manager/actions/versions' @@ -63,6 +64,11 @@ export default class EditorFeedSourcePanel extends Component { ref='snapshotModal' /> + {feedSource.editorSnapshots && feedSource.editorSnapshots.length ?
@@ -73,13 +79,13 @@ export default class EditorFeedSourcePanel extends Component { {snapshots.length === 0 - ? No other snapshots + ? {this.messages('noOtherSnapshots')} : snapshots.map(s => { return ( ) @@ -122,7 +128,7 @@ export default class EditorFeedSourcePanel extends Component { } } -type ItemProps = { +export type ItemProps = { createFeedVersionFromSnapshot: typeof versionActions.createFeedVersionFromSnapshot, deleteSnapshot: typeof snapshotActions.deleteSnapshot, disabled: boolean, @@ -142,8 +148,10 @@ class SnapshotItem extends Component { } _onClickExport = () => { - const {createFeedVersionFromSnapshot, feedSource, snapshot} = this.props - createFeedVersionFromSnapshot(feedSource, snapshot.id) + this.props.modal.open({ + body: this.messages('exportPatternsBody'), + snapshot: this.props.snapshot + }) } _onDeleteSnapshot = () => { diff --git a/lib/manager/actions/versions.js b/lib/manager/actions/versions.js index a89fdb7df..fe0bc9d35 100644 --- a/lib/manager/actions/versions.js +++ b/lib/manager/actions/versions.js @@ -543,10 +543,11 @@ export function downloadFeedViaToken ( */ export function createFeedVersionFromSnapshot ( feedSource: Feed, - snapshotId: string + snapshotId: string, + publishProprietaryFiles: boolean ) { return function (dispatch: dispatchFn, getState: getStateFn) { - const url = `${SECURE_API_PREFIX}feedversion/fromsnapshot?feedSourceId=${feedSource.id}&snapshotId=${snapshotId}` + const url = `${SECURE_API_PREFIX}feedversion/fromsnapshot?feedSourceId=${feedSource.id}&snapshotId=${snapshotId}&publishProprietaryFiles=${publishProprietaryFiles.toString()}` return dispatch(secureFetch(url, 'post')) .then(res => dispatch(handleJobResponse(res, 'Error downloading snapshot'))) }