Skip to content

Commit

Permalink
feat(protocol-designer): make settings tab always active
Browse files Browse the repository at this point in the history
Closes #2697
  • Loading branch information
IanLondon committed Nov 19, 2018
1 parent ad00dd8 commit 67b9b5d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions protocol-designer/src/containers/ConnectedNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<TabbedNavBar
topChildren={
Expand All @@ -26,13 +29,13 @@ function Nav (props: Props) {
<NavTab
iconName='water'
title={i18n.t('nav.tab_name.liquids')}
disabled={props.currentPage === 'file-splash'}
disabled={noCurrentProtocol}
selected={props.currentPage === 'liquids'}
onClick={props.handleClick('liquids')} />
<NavTab
iconName='ot-design'
title={i18n.t('nav.tab_name.design')}
disabled={props.currentPage === 'file-splash'}
disabled={noCurrentProtocol}
selected={props.currentPage === 'steplist'}
onClick={props.handleClick('steplist')} />
</React.Fragment>
Expand All @@ -46,7 +49,6 @@ function Nav (props: Props) {
<NavTab
iconName='settings'
title={i18n.t('nav.tab_name.settings')}
disabled={props.currentPage === 'file-splash'}
selected={props.currentPage === 'settings-privacy'}
onClick={props.handleClick('settings-privacy')} />
</React.Fragment>
Expand All @@ -58,6 +60,7 @@ function Nav (props: Props) {
function mapStateToProps (state: BaseState) {
return {
currentPage: selectors.currentPage(state),
currentProtocolExists: fileSelectors.getCurrentProtocolExists(state),
}
}

Expand Down
8 changes: 8 additions & 0 deletions protocol-designer/src/file-data/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -61,11 +67,13 @@ const fileMetadata = handleActions({
}, defaultFields)

export type RootState = {
currentProtocolExists: boolean,
unsavedMetadataForm: FileMetadataFields,
fileMetadata: FileMetadataFields,
}

const _allReducers = {
currentProtocolExists,
unsavedMetadataForm,
fileMetadata,
}
Expand Down
5 changes: 5 additions & 0 deletions protocol-designer/src/file-data/selectors/fileFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67b9b5d

Please sign in to comment.