Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for publishing patterns #991

Merged
merged 8 commits into from
Nov 21, 2023
4 changes: 4 additions & 0 deletions __tests__/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,10 @@ describe('end-to-end', () => {

// wait for snapshots tab to load and publish snapshot
await waitForAndClick('[data-test-id="publish-snapshot-button"]')

// wait for snapshot export modal and click "no" to proprietary file export
await waitForAndClick('[data-test-id="export-patterns-modal-no"]')
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved

// wait for version to get created
await waitAndClearCompletedJobs()

Expand Down
8 changes: 8 additions & 0 deletions i18n/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ components:
placeholder: Additional information (optional)
publishNewVersion:
label: Publish snapshot as new feed version
publishProprietaryFiles:
helpText: Proprietary files allow you to maintain certain proprietary Datatools features across feed version, e.g. Pattern names.
philip-cline marked this conversation as resolved.
Show resolved Hide resolved
label: Publish new feed version with proprietary (extra) datatools files.
philip-cline marked this conversation as resolved.
Show resolved Hide resolved
confirmPublishWithUnapproved:
label: Confirm publish with unapproved routes
unapprovedRoutesHeader: "The following routes are not approved"
Expand Down Expand Up @@ -288,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 @@ -334,6 +338,10 @@ components:
deleteRange: Delete range
ExceptionValidationErrorsList:
andOtherErrors: ...and %errors% other errors
ExportPatternsModal:
exportPatterns: Publish version with proprietary patterns?
no: No
yes: Yes
FeedFetchFrequency:
DAYS: days
fetchFeedEvery: Fetch feed every
Expand Down
8 changes: 8 additions & 0 deletions i18n/german.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ components:
placeholder: Name des Schnappschusses (erforderlich)
publishNewVersion:
label: Veröffentliche Schnappschuss als neue Feed-Version
publishProprietaryFiles:
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
title: Neuen Schnappschuss erstellen
Expand Down Expand Up @@ -295,6 +298,7 @@ components:
load: Zur Bearbeitung laden
loadLatest: Aktuellsten zur Bearbeitung herunterladen
name: Name
noOtherSnapshots: No other snapshots
noSnapshotsExist: Für diese Feed-Quelle existieren noch keine Schnappschüsse.
Schnappschüsse können im Editor erstellt werden. Wählen Sie "Feed bearbeiten"
um den Bearbeitungsmodus zu starten.
Expand Down Expand Up @@ -346,6 +350,10 @@ components:
deleteRange: Delete range
ExceptionValidationErrorsList:
andOtherErrors: ...and %errors% other errors
ExportPatternsModal:
exportPatterns: Publish version with proprietary patterns?
no: No
yes: Yes
FeedActionsDropdown:
delete: Löschen
deleteFeedSource: Feed-Quelle löschen?
Expand Down
8 changes: 8 additions & 0 deletions i18n/polish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ components:
placeholder: Nazwa migawki (wymagana)
publishNewVersion:
label: Publikuj migawkę jako nowa wersja pliku
publishProprietaryFiles:
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
title: Utwórz nową migawkę
Expand Down Expand Up @@ -293,6 +296,7 @@ components:
load: Wczytaj do edycji
loadLatest: Załaduj najnowszy do edycji
name: Nazwa
noOtherSnapshots: No other snapshots
noSnapshotsExist: Obecnie nie istnieją żadne zrzuty tego kanału. Migawki można
tworzyć w Edytorze. Kliknij „Edytuj kanał”, aby przejść do trybu edycji.
noVersions: (Brak wersji)
Expand Down Expand Up @@ -341,6 +345,10 @@ components:
deleteRange: Delete range
ExceptionValidationErrorsList:
andOtherErrors: ...and %errors% other errors
ExportPatternsModal:
exportPatterns: Publish version with proprietary patterns?
no: No
yes: Yes
FeedActionsDropdown:
delete: Delete
deleteFeedSource: Delete Feed Source?
Expand Down
69 changes: 69 additions & 0 deletions lib/common/components/ExportPatternsModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// @flow
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved

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
data-test-id='export-patterns-modal-no'
onClick={() => this.publish(false)}
style={buttonStyle}
>
{this.messages('no')}
</Button>
</Body>
</Modal>
)
}
}
5 changes: 2 additions & 3 deletions lib/editor/actions/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {createAction, type ActionType} from 'redux-actions'
import {secureFetch} from '../../common/actions'
import {getConfigProperty} from '../../common/util/config'
import {handleJobResponse} from '../../manager/actions/status'

import type {Feed, Snapshot} from '../../types'
import type {dispatchFn, getStateFn} from '../../types/reducers'

Expand Down Expand Up @@ -87,9 +86,9 @@ export function downloadSnapshotViaCredentials (snapshot: Snapshot, isPublic: bo
/**
* Create a new snapshot from the data currently present in the editor buffer.
*/
export function createSnapshot (feedSource: Feed, name: string, comment?: ?string, publishNewVersion?: boolean) {
export function createSnapshot (feedSource: Feed, name: string, comment?: ?string, publishNewVersion?: boolean, publishProprietaryFiles?: boolean) {
return function (dispatch: dispatchFn, getState: getStateFn) {
const url = `/api/editor/secure/snapshot?feedId=${feedSource.id}${publishNewVersion ? '&publishNewVersion=true' : ''}`
const url = `/api/editor/secure/snapshot?feedId=${feedSource.id}${publishNewVersion ? '&publishNewVersion=true' : ''}${publishProprietaryFiles ? '&publishProprietaryFiles=true' : ''}`
const snapshot = {
feedId: feedSource.id,
name,
Expand Down
33 changes: 29 additions & 4 deletions lib/editor/components/CreateSnapshotModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
ControlLabel,
FormGroup,
FormControl,
Modal
Modal,
OverlayTrigger,
Tooltip
} from 'react-bootstrap'
import {connect} from 'react-redux'

Expand All @@ -34,6 +36,7 @@ type State = {
loading: boolean,
name: ?string,
publishNewVersion: boolean,
publishProprietaryFiles: boolean,
showModal: boolean,
}

Expand All @@ -42,6 +45,7 @@ function getDefaultState () {
comment: null,
name: formatTimestamp(),
publishNewVersion: false,
publishProprietaryFiles: false,
confirmPublishWithUnapproved: false,
showModal: false,
loading: false
Expand All @@ -54,6 +58,12 @@ class CreateSnapshotModal extends Component<Props, State> {
messages = getComponentMessages('CreateSnapshotModal')

_onTogglePublish = (e: SyntheticInputEvent<HTMLInputElement>) => {
// If unchecking publishNewVersion, we need to also uncheck publishProprietaryFiles
if (!e.target.checked) this.setState({publishProprietaryFiles: false})
this.setState({[e.target.name]: e.target.checked})
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
}

_onTogglePublishProprietaryFiles = (e: SyntheticInputEvent<HTMLInputElement>) => {
this.setState({[e.target.name]: e.target.checked})
}

Expand Down Expand Up @@ -91,9 +101,9 @@ class CreateSnapshotModal extends Component<Props, State> {

ok = () => {
const {createSnapshot, feedSource} = this.props
const {comment, name, publishNewVersion} = this.state
const {comment, name, publishNewVersion, publishProprietaryFiles} = this.state
if (!name) return window.alert(this.messages('missingNameAlert'))
createSnapshot(feedSource, name, comment, publishNewVersion)
createSnapshot(feedSource, name, comment, publishNewVersion, publishProprietaryFiles)
this.close()
}

Expand All @@ -105,6 +115,7 @@ class CreateSnapshotModal extends Component<Props, State> {
loading,
name,
publishNewVersion,
publishProprietaryFiles,
showModal
} = this.state
const {routes} = this.props
Expand Down Expand Up @@ -142,13 +153,27 @@ class CreateSnapshotModal extends Component<Props, State> {
placeholder={this.messages('fields.comment.placeholder')}
/>
</FormGroup>
<FormGroup>
<FormGroup style={{width: 'fit-content'}}>
<Checkbox
name='publishNewVersion'
checked={publishNewVersion}
onChange={this._onTogglePublish}>
{this.messages('fields.publishNewVersion.label')}
</Checkbox>
{publishNewVersion &&
<OverlayTrigger overlay={<Tooltip>{this.messages('fields.publishProprietaryFiles.helpText')}</Tooltip>}>
<span>
<Checkbox
name='publishProprietaryFiles'
checked={publishProprietaryFiles}
onChange={this._onTogglePublishProprietaryFiles}
style={{marginLeft: 10}}
>
{this.messages('fields.publishProprietaryFiles.label')}
</Checkbox>
</span>
</OverlayTrigger>
}
</FormGroup>
{loading && <Icon type='spinner' className='fa-pulse' />}
{unapprovedRoutes.length > 0 &&
Expand Down
15 changes: 10 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,7 @@ class SnapshotItem extends Component<ItemProps> {
}

_onClickExport = () => {
const {createFeedVersionFromSnapshot, feedSource, snapshot} = this.props
createFeedVersionFromSnapshot(feedSource, snapshot.id)
this.props.modal.open({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
Loading