diff --git a/src/components/expansion/ExpansionPanel.svelte b/src/components/expansion/ExpansionPanel.svelte index 7be82f2a3d..5d80ab7346 100644 --- a/src/components/expansion/ExpansionPanel.svelte +++ b/src/components/expansion/ExpansionPanel.svelte @@ -169,8 +169,7 @@ } if (expandedResult !== null) { - // TODO: remove this after expansion runs are made to work in new workspaces - // await effects.sendSequenceToWorkspace(sequence, expandedResult, user); + await effects.sendSequenceToWorkspace(sequence, expandedResult, user); } } diff --git a/src/components/modals/ExpansionPanelModal.svelte b/src/components/modals/ExpansionPanelModal.svelte index c7fdeea8f0..1ff4ee8044 100644 --- a/src/components/modals/ExpansionPanelModal.svelte +++ b/src/components/modals/ExpansionPanelModal.svelte @@ -4,9 +4,7 @@ import { Label, Select } from '@nasa-jpl/stellar-svelte'; import { createEventDispatcher } from 'svelte'; import { field } from '../../stores/form'; - import { parcels } from '../../stores/sequencing'; import { workspaces } from '../../stores/workspaces'; - import type { Parcel } from '../../types/sequencing'; import type { Workspace } from '../../types/workspace'; import { min } from '../../utilities/validators'; import Field from '../form/Field.svelte'; @@ -20,24 +18,24 @@ const dispatch = createEventDispatcher<{ close: void; - save: { parcelId: number; workspaceId: number }; + save: { workspaceId: number; workspaceName: string }; }>(); let workspaceIdField = field(-1, [min(1, 'Field is required')]); + let workspaceIdFieldName: string; let selectedWorkspace: Workspace | undefined; - let parcelIdField = field(-1, [min(1, 'Field is required')]); - let selectedParcel: Parcel | undefined; - let saveButtonDisabled: boolean = true; - $: saveButtonDisabled = $workspaceIdField.value === -1 || $parcelIdField.value === -1; + $: saveButtonDisabled = $workspaceIdField.value === -1; $: selectedWorkspace = $workspaces.find(({ id }) => $workspaceIdField.value === id); - $: selectedParcel = $parcels.find(({ id }) => $parcelIdField.value === id); + $: if ($workspaceIdField.value) { + workspaceIdFieldName = $workspaces.find(workspace => workspace.id === $workspaceIdField.value)?.name ?? ''; + } function save() { if (!saveButtonDisabled) { - dispatch('save', { parcelId: $parcelIdField.value, workspaceId: $workspaceIdField.value }); + dispatch('save', { workspaceId: $workspaceIdField.value, workspaceName: workspaceIdFieldName }); } } @@ -55,13 +53,6 @@ } return `${workspace.name} (${workspace.id})`; } - - function getDisplayNameForParcel(parcel?: Parcel) { - if (!parcel) { - return ''; - } - return `${parcel.name} (${parcel.id})`; - } @@ -97,23 +88,6 @@ - - - - - - - - {#each $parcels as parcel} - - {parcel.name} -
(Id: {parcel.id})
-
- {/each} -
- -
-
diff --git a/src/utilities/effects.ts b/src/utilities/effects.ts index 79bead0d75..336f4792e7 100644 --- a/src/utilities/effects.ts +++ b/src/utilities/effects.ts @@ -264,6 +264,7 @@ import { showDeleteExternalEventSourceTypeModal, showDeleteExternalSourceModal, showEditViewModal, + showExpansionPanelModal, showImportWorkspaceFileModal, showLibrarySequenceModel, showManagePlanConstraintsModal, @@ -6805,45 +6806,60 @@ const effects = { } }, - // TODO: remove this after expansion runs are made to work in new workspaces - // async sendSequenceToWorkspace( - // sequence: ExpansionSequence | null, - // expandedSequence: string | null, - // user: User | null, - // ): Promise { - // if (sequence === null) { - // showFailureToast("Sequence Doesn't Exist"); - // return; - // } + async sendSequenceToWorkspace( + sequence: ExpansionSequence | null, + expandedSequence: string | null, + user: User | null, + ): Promise { + try { + if (sequence === null) { + throw new Error("Sequence Doesn't Exist"); + } + if (expandedSequence === null) { + throw new Error("Expanded Sequence Doesn't Exist"); + } - // if (expandedSequence === null) { - // showFailureToast("Expanded Sequence Doesn't Exist"); - // return; - // } + const { confirm: confirmWorkspace, value: valueWorkspace } = await showExpansionPanelModal(); - // const { confirm, value } = await showExpansionPanelModal(); + if (!confirmWorkspace || !valueWorkspace) { + throw new Error('Unable To Find The Specified Workspace'); + } - // if (!confirm || !value) { - // return; - // } + const { workspaceId, workspaceName } = valueWorkspace; - // try { - // const createUserSequenceInsertInput: UserSequenceInsertInput = { - // definition: expandedSequence, - // is_locked: false, - // name: sequence.seq_id, - // parcel_id: value.parcelId, - // seq_json: '', - // workspace_id: value.workspaceId, - // }; - // const userSequenceCreated = await this.createUserSequence(createUserSequenceInsertInput, user); - // if (!userSequenceCreated) { - // throw Error('Sequence Import Failed'); - // } - // } catch (e) { - // catchError(e as Error); - // } - // }, + const workspaceContents = await effects.getWorkspaceContents(workspaceId, user); + if (!workspaceContents) { + throw new Error('Unable To Find The Specified Workspace'); + } + + const workspaceTree: WorkspaceTreeNode = { + contents: workspaceContents, + name: workspaceName, + type: WorkspaceContentType.Workspace, + }; + workspaceTree; + + const { confirm: confirmNewFile, value: confirmNewFileValue } = await showNewWorkspaceSequenceModal( + workspaceId, + workspaceTree, + '', + user, + ); + + if (confirmNewFile && confirmNewFileValue) { + const { filePath: newFilePath } = confirmNewFileValue; + const body = createWorkspaceSequenceFileFormData(newFilePath, expandedSequence); + await reqWorkspace(`${workspaceId}/${newFilePath}?type=file`, 'PUT', body, user, undefined, false); + showSuccessToast('Workspace File Created Successfully'); + } else { + throw new Error('Workspace File Creation Failed'); + } + } catch (e) { + catchError('Workspace file was unable to be created', e as Error); + showFailureToast('Workspace File Creation Failed'); + } + return null; + }, async session(user: BaseUser | null): Promise { try { diff --git a/src/utilities/modal.ts b/src/utilities/modal.ts index f7af4b679f..d00273c3fe 100644 --- a/src/utilities/modal.ts +++ b/src/utilities/modal.ts @@ -1570,7 +1570,7 @@ export async function showExpansionPanelModal(): Promise { expansionPanelModal.$destroy(); }); - expansionPanelModal.$on('save', (e: CustomEvent<{ parcelId: number; workspaceId: number }>) => { + expansionPanelModal.$on('save', (e: CustomEvent<{ workspaceId: number }>) => { target.replaceChildren(); target.resolve = null; resolve({ confirm: true, value: e.detail });