From 036e2ee885cb7192c14b36bb460bf604c7a1cfe2 Mon Sep 17 00:00:00 2001 From: Ian London Date: Tue, 20 Nov 2018 13:23:14 -0500 Subject: [PATCH] feat(protocol-designer): make settings tab always active (#2700) Closes #2697 --- protocol-designer/src/containers/ConnectedNav.js | 9 ++++++--- protocol-designer/src/file-data/reducers/index.js | 8 ++++++++ protocol-designer/src/file-data/selectors/fileFields.js | 5 +++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/protocol-designer/src/containers/ConnectedNav.js b/protocol-designer/src/containers/ConnectedNav.js index a9e5a40850c..af3cd07b2ad 100644 --- a/protocol-designer/src/containers/ConnectedNav.js +++ b/protocol-designer/src/containers/ConnectedNav.js @@ -7,13 +7,16 @@ import {KNOWLEDGEBASE_ROOT_URL} from '../components/KnowledgeBaseLink' import {NavTab, TabbedNavBar, OutsideLinkTab} from '@opentrons/components' import i18n from '../localization' import {type Page, actions, selectors} from '../navigation' +import {selectors as fileSelectors} from '../file-data' type Props = { currentPage: Page, + currentProtocolExists: boolean, handleClick: Page => (e: ?SyntheticEvent<>) => void, } function Nav (props: Props) { + const noCurrentProtocol = !props.currentProtocolExists return ( @@ -46,7 +49,6 @@ function Nav (props: Props) { @@ -58,6 +60,7 @@ function Nav (props: Props) { function mapStateToProps (state: BaseState) { return { currentPage: selectors.currentPage(state), + currentProtocolExists: fileSelectors.getCurrentProtocolExists(state), } } diff --git a/protocol-designer/src/file-data/reducers/index.js b/protocol-designer/src/file-data/reducers/index.js index 36030716f91..791b6c09f97 100644 --- a/protocol-designer/src/file-data/reducers/index.js +++ b/protocol-designer/src/file-data/reducers/index.js @@ -23,6 +23,12 @@ const updateMetadataFields = ( return metadata } +// track if a protocol has been created or loaded +const currentProtocolExists = handleActions({ + LOAD_FILE: () => true, + CREATE_NEW_PROTOCOL: () => true, +}, false) + function newProtocolMetadata ( state: FileMetadataFields, action: {payload: NewProtocolFields} @@ -61,11 +67,13 @@ const fileMetadata = handleActions({ }, defaultFields) export type RootState = { + currentProtocolExists: boolean, unsavedMetadataForm: FileMetadataFields, fileMetadata: FileMetadataFields, } const _allReducers = { + currentProtocolExists, unsavedMetadataForm, fileMetadata, } diff --git a/protocol-designer/src/file-data/selectors/fileFields.js b/protocol-designer/src/file-data/selectors/fileFields.js index 544ae5fa7d9..3cbbee38ba8 100644 --- a/protocol-designer/src/file-data/selectors/fileFields.js +++ b/protocol-designer/src/file-data/selectors/fileFields.js @@ -6,6 +6,11 @@ import type {RootState} from '../reducers' export const rootSelector = (state: BaseState): RootState => state.fileData +export const getCurrentProtocolExists = createSelector( + rootSelector, + (rootState) => rootState.currentProtocolExists +) + export const fileFormValues = createSelector( rootSelector, state => state.unsavedMetadataForm