Skip to content

Commit

Permalink
remove pd changes
Browse files Browse the repository at this point in the history
  • Loading branch information
b-cooper committed Jun 21, 2024
1 parent 5b21330 commit f9a2d48
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 146 deletions.
18 changes: 1 addition & 17 deletions app/src/redux/config/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,4 @@ export type ConfigV21 = Omit<ConfigV20, 'version'> & {
version: 21
}

export type ConfigV22 = Omit<ConfigV20, 'version'> & {
version: 22
protocolEditorUi: {
width: number
height: number
minWidth: number
url: {
protocol: UrlProtocol
path: string
}
webPreferences: {
webSecurity: boolean
}
}
}

export type Config = ConfigV22
export type Config = ConfigV21
13 changes: 1 addition & 12 deletions app/src/redux/protocol-storage/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export const ANALYZE_PROTOCOL_FAILURE: 'protocolStorage:ANALYZE_PROTOCOL_FAILURE
export const VIEW_PROTOCOL_SOURCE_FOLDER: 'protocolStorage:VIEW_PROTOCOL_SOURCE_FOLDER' =
'protocolStorage:VIEW_PROTOCOL_SOURCE_FOLDER'

export const EDIT_PROTOCOL: 'protocolStorage:EDIT_PROTOCOL' =
'protocolStorage:EDIT_PROTOCOL'

// action meta literals

export const POLL = 'poll' as const
Expand Down Expand Up @@ -132,16 +129,8 @@ export const analyzeProtocolFailure = (

export const viewProtocolSourceFolder = (
protocolKey: string
): Types.ViewProtocolSourceFolderAction => ({
): Types.ViewProtocolSourceFolder => ({
type: VIEW_PROTOCOL_SOURCE_FOLDER,
payload: { protocolKey },
meta: { shell: true },
})

export const editProtocol = (
protocolKey: string
): Types.EditProtocolAction => ({
type: EDIT_PROTOCOL,
payload: { protocolKey },
meta: { shell: true },
})
11 changes: 2 additions & 9 deletions app/src/redux/protocol-storage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,12 @@ export interface AnalyzeProtocolFailureAction {
meta: { shell: true }
}

export interface ViewProtocolSourceFolderAction {
export interface ViewProtocolSourceFolder {
type: 'protocolStorage:VIEW_PROTOCOL_SOURCE_FOLDER'
payload: { protocolKey: string }
meta: { shell: true }
}

export interface EditProtocolAction {
type: 'protocolStorage:EDIT_PROTOCOL'
payload: { protocolKey: string }
meta: { shell: true }
}

export type ProtocolStorageAction =
| FetchProtocolsAction
| UpdateProtocolListAction
Expand All @@ -123,5 +117,4 @@ export type ProtocolStorageAction =
| AnalyzeProtocolAction
| AnalyzeProtocolSuccessAction
| AnalyzeProtocolFailureAction
| ViewProtocolSourceFolderAction
| EditProtocolAction
| ViewProtocolSourceFolder
70 changes: 25 additions & 45 deletions protocol-designer/src/components/FileSidebar/FileSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ export function FileSidebar(): JSX.Element {
const savedStepForms = useSelector(stepFormSelectors.getSavedStepForms)
const newProtocolModal = useSelector(selectors.getNewProtocolModal)
const hasUnsavedChanges = useSelector(loadFileSelectors.getHasUnsavedChanges)
const hasNativeFileSystemAccess = useSelector(loadFileSelectors.getHasNativeFileSystemAccess)
const canCreateNew = !newProtocolModal
const dispatch: ThunkDispatch<any> = useDispatch()

Expand Down Expand Up @@ -413,49 +412,6 @@ export function FileSidebar(): JSX.Element {
dispatch(loadFileActions.saveProtocolFile())
},
})


const sidebarContents = hasNativeFileSystemAccess ? (
<div className={styles.button}>
<DeprecatedPrimaryButton
onClick={() => {
dispatch(loadFileActions.saveToFileSystem())
}}
disabled={!canDownload}
>
{t('save')}
</DeprecatedPrimaryButton>
</div>
) : (
<>
<OutlineButton onClick={createNewFile} className={styles.button}>
{t('create_new')}
</OutlineButton>

<OutlineButton Component="label" className={cx(styles.upload_button)}>
{t('import')}
<input type="file" onChange={loadFile} />
</OutlineButton>

<div className={styles.button}>
<DeprecatedPrimaryButton
onClick={() => {
if (hasWarning) {
resetScrollElements()
setShowExportWarningModal(true)
} else {
resetScrollElements()
setShowBlockingHint(true)
}
}}
disabled={!canDownload}
>
{t('export')}
</DeprecatedPrimaryButton>
</div>
</>
)

return (
<>
{blockingExportHint}
Expand Down Expand Up @@ -487,7 +443,31 @@ export function FileSidebar(): JSX.Element {
)}
<SidePanel title="Protocol File">
<div className={styles.file_sidebar}>
{sidebarContents}
<OutlineButton onClick={createNewFile} className={styles.button}>
{t('create_new')}
</OutlineButton>

<OutlineButton Component="label" className={cx(styles.upload_button)}>
{t('import')}
<input type="file" onChange={loadFile} />
</OutlineButton>

<div className={styles.button}>
<DeprecatedPrimaryButton
onClick={() => {
if (hasWarning) {
resetScrollElements()
setShowExportWarningModal(true)
} else {
resetScrollElements()
setShowBlockingHint(true)
}
}}
disabled={!canDownload}
>
{t('export')}
</DeprecatedPrimaryButton>
</div>
</div>
</SidePanel>
</>
Expand Down
4 changes: 0 additions & 4 deletions protocol-designer/src/file-data/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ const fileMetadata = handleActions(
// NOTE: 'last-modified' is updated "on-demand", in response to user clicking "save/export"
return { ...state, lastModified: Date.now() }
},
SAVE_TO_FILE_SYSTEM: (state: FileMetadataFields): FileMetadataFields => {
// NOTE: 'last-modified' is updated "on-demand", in response to user clicking "save"
return { ...state, lastModified: Date.now() }
},
},
defaultFields
)
Expand Down
9 changes: 0 additions & 9 deletions protocol-designer/src/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { selectors as loadFileSelectors } from './load-file'
import { loadFileAction } from './load-file/actions'
import { remote } from './shell/remote'
import type { PDProtocolFile } from './file-types'
import type { BaseState } from './types'

// TODO(Jr, 1/18/24): use i18n here!
Expand All @@ -16,10 +13,4 @@ export const initialize = (store: Record<string, any>): void => {
: undefined
}
}
remote.ipcRenderer.on(
'open-protocol-in-designer',
(_ipcEvent, protocolSource) => {
store.dispatch(loadFileAction(protocolSource as PDProtocolFile, true))
}
)
}
29 changes: 2 additions & 27 deletions protocol-designer/src/load-file/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import type {
FileUploadMessage,
LoadFileAction,
NewProtocolFields,
OpenFileAction,
} from './types'
import { remote } from '../shell/remote'
export interface FileUploadMessageAction {
type: 'FILE_UPLOAD_MESSAGE'
payload: FileUploadMessage
Expand All @@ -28,12 +26,9 @@ export const dismissFileUploadMessage = (): DismissFileUploadMessageAction => ({
type: 'DISMISS_FILE_UPLOAD_MESSAGE',
})
// expects valid, parsed JSON protocol.
export const loadFileAction = (protocolFile: PDProtocolFile, hasFileSystemAccess: boolean = false): LoadFileAction => ({
export const loadFileAction = (payload: PDProtocolFile): LoadFileAction => ({
type: 'LOAD_FILE',
payload: {
...migration(protocolFile),
hasFileSystemAccess
},
payload: migration(payload),
})
// load file thunk, handles file loading errors
export const loadProtocolFile = (
Expand Down Expand Up @@ -115,23 +110,3 @@ export const saveProtocolFile: () => ThunkAction<SaveProtocolFileAction> = () =>
const fileName = `${protocolName}.json`
saveFile(fileData, fileName)
}

export interface SaveToFileSystemAction {
type: 'SAVE_TO_FILE_SYSTEM'
}
export const saveToFileSystem: () => ThunkAction<SaveToFileSystemAction> = () => (
dispatch,
getState
) => {
// dispatching this should update the state, eg lastModified timestamp
dispatch({
type: 'SAVE_TO_FILE_SYSTEM',
})
const state = getState()
const fileData = fileDataSelectors.createFile(state)
const protocolName =
fileDataSelectors.getFileMetadata(state).protocolName || 'untitled'
const fileName = `${protocolName}.json`
remote.ipcRenderer.send('save-protocol-file-to-filesystem', fileName, fileData)
}

19 changes: 0 additions & 19 deletions protocol-designer/src/load-file/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const unsavedChanges = (
return action.payload.didMigrate // no unsaved changes unless migration happened
}

case 'SAVE_TO_FILE_SYSTEM':
case 'SAVE_PROTOCOL_FILE':
return false

Expand Down Expand Up @@ -78,31 +77,13 @@ const unsavedChanges = (
}
}

const hasNativeFileSystemAccess = (
state: boolean = false,
action: {
type: string
payload: any
}
): boolean => {
switch (action.type) {
case 'LOAD_FILE': {
return action.payload.hasFileSystemAccess
}
default:
return state
}
}

export const _allReducers = {
fileUploadMessage,
unsavedChanges,
hasNativeFileSystemAccess,
}
export interface RootState {
fileUploadMessage: FileUploadMessageState
unsavedChanges: boolean
hasNativeFileSystemAccess: boolean
}
export const rootReducer: Reducer<RootState, Action> = combineReducers(
_allReducers
Expand Down
3 changes: 0 additions & 3 deletions protocol-designer/src/load-file/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ export const getFileUploadMessages: Selector<
export const getHasUnsavedChanges: Selector<
RootState['unsavedChanges']
> = createSelector(rootSelector, s => s.unsavedChanges)
export const getHasNativeFileSystemAccess: Selector<
RootState['hasNativeFileSystemAccess']
> = createSelector(rootSelector, s => s.hasNativeFileSystemAccess)
1 change: 0 additions & 1 deletion protocol-designer/src/load-file/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export interface LoadFileAction {
file: PDProtocolFile
didMigrate: boolean
migrationsRan: string[]
hasFileSystemAccess: boolean
}
}

0 comments on commit f9a2d48

Please sign in to comment.