Skip to content

Commit

Permalink
refactor(ExportPatternsModal): allow pattern export for snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-cline committed Nov 6, 2023
1 parent fcd3253 commit 3a600e3
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 10 deletions.
8 changes: 7 additions & 1 deletion i18n/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion i18n/german.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion i18n/polish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions lib/common/components/ExportPatternsModal.js
Original file line number Diff line number Diff line change
@@ -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<Props, State> {
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 (
<Modal show={this.state.showModal} onHide={this.close}>
<Body style={{display: 'flex'}}>
<Title>{this.messages('exportPatterns')}</Title>
<Button onClick={() => this.publish(true)} style={buttonStyle}>
{this.messages('yes')}
</Button>
<Button onClick={() => this.publish(false)} style={buttonStyle}>
{this.messages('no')}
</Button>
</Body>
</Modal>
)
}
}
18 changes: 13 additions & 5 deletions lib/editor/components/EditorFeedSourcePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -63,6 +64,11 @@ export default class EditorFeedSourcePanel extends Component<Props> {
ref='snapshotModal'
/>
<ConfirmModal ref='confirmModal' />
<ExportPatternsModal
createFeedVersionFromSnapshot={this.props.createFeedVersionFromSnapshot}
feedSource={feedSource}
ref='exportPatternsModal'
/>
<Col xs={9}>
{feedSource.editorSnapshots && feedSource.editorSnapshots.length
? <div>
Expand All @@ -73,13 +79,13 @@ export default class EditorFeedSourcePanel extends Component<Props> {
</Panel.Title></Panel.Heading>
<ListGroup>
{snapshots.length === 0
? <ListGroupItem>No other snapshots</ListGroupItem>
? <ListGroupItem>{this.messages('noOtherSnapshots')}</ListGroupItem>
: snapshots.map(s => {
return (
<SnapshotItem
disabled={disabled}
key={s.id}
modal={this.refs.confirmModal}
modal={this.refs.exportPatternsModal}
snapshot={s}
{...this.props} />
)
Expand Down Expand Up @@ -122,7 +128,7 @@ export default class EditorFeedSourcePanel extends Component<Props> {
}
}

type ItemProps = {
export type ItemProps = {
createFeedVersionFromSnapshot: typeof versionActions.createFeedVersionFromSnapshot,
deleteSnapshot: typeof snapshotActions.deleteSnapshot,
disabled: boolean,
Expand All @@ -142,8 +148,10 @@ class SnapshotItem extends Component<ItemProps> {
}

_onClickExport = () => {
const {createFeedVersionFromSnapshot, feedSource, snapshot} = this.props
createFeedVersionFromSnapshot(feedSource, snapshot.id)
this.props.modal.open({
body: this.messages('exportPatternsBody'),
snapshot: this.props.snapshot
})
}

_onDeleteSnapshot = () => {
Expand Down
5 changes: 3 additions & 2 deletions lib/manager/actions/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
}
Expand Down

0 comments on commit 3a600e3

Please sign in to comment.