-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): allow custom labware dir to be opened and reset to default (…
- Loading branch information
Showing
38 changed files
with
662 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ module.exports = { | |
|
||
shell: { | ||
moveItemToTrash: jest.fn(), | ||
openItem: jest.fn(), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/components/AddLabwareCard/ConfirmResetPathModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @flow | ||
import * as React from 'react' | ||
|
||
import { AlertModal } from '@opentrons/components' | ||
import { Portal } from '../portal' | ||
|
||
// TODO(mc, 2019-11-20): i18n | ||
// buttons | ||
const CANCEL = 'cancel' | ||
const RESET_SOURCE = 'reset source' | ||
|
||
// headings | ||
const RESET_CUSTOM_LABWARE_SOURCE = 'Reset Custom Labware source directory?' | ||
|
||
// copy | ||
const CLICK_RESET_SOURCE_TO_RESET_YOUR_CUSTOM_LABWARE_DIRECTORY = | ||
'Click "Reset Source" to reset your custom labware directory to its default location.' | ||
|
||
const LABWARE_FILES_IN_YOUR_CURRENT_DIRECTORY_WILL_NOT_BE_MOVED = | ||
'Labware in your current source directory will not be moved nor deleted.' | ||
|
||
// button names | ||
export const CANCEL_NAME = 'cancel' | ||
export const RESET_SOURCE_NAME = 'reset-source' | ||
|
||
export type ConfirmResetPathModalProps = {| | ||
onCancel: () => mixed, | ||
onConfirm: () => mixed, | ||
|} | ||
|
||
export const ConfirmResetPathModalTemplate = ({ | ||
onCancel, | ||
onConfirm, | ||
}: ConfirmResetPathModalProps) => ( | ||
<AlertModal | ||
alertOverlay | ||
heading={RESET_CUSTOM_LABWARE_SOURCE} | ||
buttons={[ | ||
{ name: CANCEL_NAME, children: CANCEL, onClick: onCancel }, | ||
{ name: RESET_SOURCE_NAME, children: RESET_SOURCE, onClick: onConfirm }, | ||
]} | ||
> | ||
<p>{CLICK_RESET_SOURCE_TO_RESET_YOUR_CUSTOM_LABWARE_DIRECTORY}</p> | ||
<p>{LABWARE_FILES_IN_YOUR_CURRENT_DIRECTORY_WILL_NOT_BE_MOVED}</p> | ||
</AlertModal> | ||
) | ||
|
||
export const ConfirmResetPathModal = (props: ConfirmResetPathModalProps) => ( | ||
<Portal> | ||
<ConfirmResetPathModalTemplate {...props} /> | ||
</Portal> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,83 @@ | ||
// @flow | ||
|
||
import * as React from 'react' | ||
import React, { useReducer } from 'react' | ||
|
||
import { LabeledButton, InputField } from '@opentrons/components' | ||
import { IconCta } from '../IconCta' | ||
import { ConfirmResetPathModal } from './ConfirmResetPathModal' | ||
import styles from './styles.css' | ||
|
||
// TODO(mc, 2019-11-18): i18n | ||
const CUSTOM_LABWARE_DEFINITIONS_FOLDER = 'Custom Labware Definitions Folder' | ||
const CHANGE_SOURCE = 'Change Source' | ||
const RESET_SOURCE = 'Reset Source' | ||
const OPEN_SOURCE = 'Open Source' | ||
|
||
// button names | ||
export const OPEN_SOURCE_NAME = 'open-source' | ||
export const CHANGE_SOURCE_NAME = 'change-source' | ||
export const RESET_SOURCE_NAME = 'reset-source' | ||
|
||
export type ManagePathProps = {| | ||
path: string, | ||
onChangePath: () => mixed, | ||
onResetPath: () => mixed, | ||
onOpenPath: () => mixed, | ||
|} | ||
|
||
const handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) => { | ||
e.currentTarget.select() | ||
} | ||
|
||
export function ManagePath(props: ManagePathProps) { | ||
const { path, onChangePath } = props | ||
const handleFocus = (e: SyntheticFocusEvent<HTMLInputElement>) => { | ||
e.currentTarget.select() | ||
const { path, onChangePath, onResetPath, onOpenPath } = props | ||
const [confirmResetIsOpen, toggleConfirmResetIsOpen] = useReducer( | ||
open => !open, | ||
false | ||
) | ||
const handleResetPath = () => { | ||
toggleConfirmResetIsOpen() | ||
onResetPath() | ||
} | ||
|
||
return ( | ||
<LabeledButton | ||
label={CUSTOM_LABWARE_DEFINITIONS_FOLDER} | ||
buttonProps={{ | ||
onClick: onChangePath, | ||
children: CHANGE_SOURCE, | ||
}} | ||
> | ||
<InputField | ||
readOnly | ||
value={path} | ||
type="text" | ||
onFocus={handleFocus} | ||
className={styles.labeled_value} | ||
/> | ||
</LabeledButton> | ||
<> | ||
<LabeledButton | ||
label={CUSTOM_LABWARE_DEFINITIONS_FOLDER} | ||
buttonProps={{ | ||
name: OPEN_SOURCE_NAME, | ||
onClick: onOpenPath, | ||
children: OPEN_SOURCE, | ||
}} | ||
> | ||
<InputField | ||
readOnly | ||
value={path} | ||
type="text" | ||
onFocus={handleFocus} | ||
className={styles.labeled_value} | ||
/> | ||
<div className={styles.flex_bar}> | ||
<IconCta | ||
name={CHANGE_SOURCE_NAME} | ||
iconName="folder-open" | ||
text={CHANGE_SOURCE} | ||
onClick={onChangePath} | ||
/> | ||
<IconCta | ||
name={RESET_SOURCE_NAME} | ||
iconName="refresh" | ||
text={RESET_SOURCE} | ||
onClick={toggleConfirmResetIsOpen} | ||
/> | ||
</div> | ||
</LabeledButton> | ||
{confirmResetIsOpen && ( | ||
<ConfirmResetPathModal | ||
onCancel={toggleConfirmResetIsOpen} | ||
onConfirm={handleResetPath} | ||
/> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.