import _ from 'lodash' import { Dialog } from '@reach/dialog' import { action } from 'mobx' import { observer, useLocalStore } from 'mobx-react' // @ts-ignore import Tooltip from '@cypress/react-tooltip' import cs from 'classnames' import React from 'react' import VisuallyHidden from '@reach/visually-hidden' import EditorPicker from './editor-picker' import { Editor } from './file-model' interface Props { chosenEditor: Editor editors: Editor[] isOpen: boolean onClose: (() => void) onSetChosenEditor: ((editor: Editor) => void) onSetEditor: ((editor: Editor) => void) } const validate = (chosenEditor: Editor) => { let isValid = !!chosenEditor && !!chosenEditor.id let validationMessage = 'Please select a preference' if (isValid && chosenEditor.isOther && !chosenEditor.openerId) { isValid = false validationMessage = 'Please enter the path for the "Other" editor' } return { isValid, validationMessage, } } const EditorPickerModal = observer(({ chosenEditor, editors, isOpen, onClose, onSetChosenEditor, onSetEditor }: Props) => { const state = useLocalStore((external) => ({ setOtherPath: action((otherPath: string) => { const otherOption = _.find(external.editors, { isOther: true }) if (otherOption) { otherOption.openerId = otherPath } }), }), { editors }) const setEditor = () => { const { isValid } = validate(chosenEditor) if (!isValid) return onSetEditor(chosenEditor) } if (!editors.length) return null const { isValid, validationMessage } = validate(chosenEditor) return (

File Opener Preference

Please select your preference for opening files on your system.

We will use your selected preference to open files in the future. You can change your preference in the Settings tab of the Cypress Test Runner.

) }) export default EditorPickerModal