Skip to content

Commit 5bf6a6c

Browse files
committed
Fix 'Send to Workspace' to work with new Sequencing Workspaces
1 parent de5da65 commit 5bf6a6c

File tree

4 files changed

+60
-71
lines changed

4 files changed

+60
-71
lines changed

src/components/expansion/ExpansionPanel.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@
169169
}
170170
171171
if (expandedResult !== null) {
172-
// TODO: remove this after expansion runs are made to work in new workspaces
173-
// await effects.sendSequenceToWorkspace(sequence, expandedResult, user);
172+
await effects.sendSequenceToWorkspace(sequence, expandedResult, user);
174173
}
175174
}
176175

src/components/modals/ExpansionPanelModal.svelte

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import { Label, Select } from '@nasa-jpl/stellar-svelte';
55
import { createEventDispatcher } from 'svelte';
66
import { field } from '../../stores/form';
7-
import { parcels } from '../../stores/sequencing';
87
import { workspaces } from '../../stores/workspaces';
9-
import type { Parcel } from '../../types/sequencing';
108
import type { Workspace } from '../../types/workspace';
119
import { min } from '../../utilities/validators';
1210
import Field from '../form/Field.svelte';
@@ -20,24 +18,24 @@
2018
2119
const dispatch = createEventDispatcher<{
2220
close: void;
23-
save: { parcelId: number; workspaceId: number };
21+
save: { workspaceId: number; workspaceName: string };
2422
}>();
2523
2624
let workspaceIdField = field<number>(-1, [min(1, 'Field is required')]);
25+
let workspaceIdFieldName: string;
2726
let selectedWorkspace: Workspace | undefined;
2827
29-
let parcelIdField = field<number>(-1, [min(1, 'Field is required')]);
30-
let selectedParcel: Parcel | undefined;
31-
3228
let saveButtonDisabled: boolean = true;
3329
34-
$: saveButtonDisabled = $workspaceIdField.value === -1 || $parcelIdField.value === -1;
30+
$: saveButtonDisabled = $workspaceIdField.value === -1;
3531
$: selectedWorkspace = $workspaces.find(({ id }) => $workspaceIdField.value === id);
36-
$: selectedParcel = $parcels.find(({ id }) => $parcelIdField.value === id);
32+
$: if ($workspaceIdField.value) {
33+
workspaceIdFieldName = $workspaces.find(workspace => workspace.id === $workspaceIdField.value)?.name ?? '';
34+
}
3735
3836
function save() {
3937
if (!saveButtonDisabled) {
40-
dispatch('save', { parcelId: $parcelIdField.value, workspaceId: $workspaceIdField.value });
38+
dispatch('save', { workspaceId: $workspaceIdField.value, workspaceName: workspaceIdFieldName });
4139
}
4240
}
4341
@@ -55,13 +53,6 @@
5553
}
5654
return `${workspace.name} (${workspace.id})`;
5755
}
58-
59-
function getDisplayNameForParcel(parcel?: Parcel) {
60-
if (!parcel) {
61-
return '';
62-
}
63-
return `${parcel.name} (${parcel.id})`;
64-
}
6556
</script>
6657

6758
<svelte:window on:keydown={onKeydown} />
@@ -97,23 +88,6 @@
9788
<Select.Input type="number" name="workspace-id" aria-label="Select Workspace hidden input" />
9889
</Select.Root>
9990
</Field>
100-
<Field field={parcelIdField}>
101-
<Label size="sm" for="parcel-id" class="pb-0.5">Parcel Id</Label>
102-
<Select.Root selected={{ label: getDisplayNameForParcel(selectedParcel), value: selectedParcel?.id ?? '' }}>
103-
<Select.Trigger class="min-w-[124px]" value={selectedParcel?.id} size="xs" aria-labelledby={null}>
104-
<Select.Value aria-label="Select a parcel" placeholder="Select a parcel" />
105-
</Select.Trigger>
106-
<Select.Content class="z-[10000]">
107-
{#each $parcels as parcel}
108-
<Select.Item size="xs" value={parcel.id} label={getDisplayNameForParcel(parcel)} class="flex gap-1">
109-
{parcel.name}
110-
<div class="whitespace-nowrap text-muted-foreground">(Id: {parcel.id})</div>
111-
</Select.Item>
112-
{/each}
113-
</Select.Content>
114-
<Select.Input type="number" name="parcel-id" aria-label="Select Parcel hidden input" />
115-
</Select.Root>
116-
</Field>
11791
</fieldset>
11892
</ModalContent>
11993

src/utilities/effects.ts

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ import {
264264
showDeleteExternalEventSourceTypeModal,
265265
showDeleteExternalSourceModal,
266266
showEditViewModal,
267+
showExpansionPanelModal,
267268
showImportWorkspaceFileModal,
268269
showLibrarySequenceModel,
269270
showManagePlanConstraintsModal,
@@ -6805,45 +6806,60 @@ const effects = {
68056806
}
68066807
},
68076808

6808-
// TODO: remove this after expansion runs are made to work in new workspaces
6809-
// async sendSequenceToWorkspace(
6810-
// sequence: ExpansionSequence | null,
6811-
// expandedSequence: string | null,
6812-
// user: User | null,
6813-
// ): Promise<void> {
6814-
// if (sequence === null) {
6815-
// showFailureToast("Sequence Doesn't Exist");
6816-
// return;
6817-
// }
6809+
async sendSequenceToWorkspace(
6810+
sequence: ExpansionSequence | null,
6811+
expandedSequence: string | null,
6812+
user: User | null,
6813+
): Promise<string | null> {
6814+
try {
6815+
if (sequence === null) {
6816+
throw new Error("Sequence Doesn't Exist");
6817+
}
6818+
if (expandedSequence === null) {
6819+
throw new Error("Expanded Sequence Doesn't Exist");
6820+
}
68186821

6819-
// if (expandedSequence === null) {
6820-
// showFailureToast("Expanded Sequence Doesn't Exist");
6821-
// return;
6822-
// }
6822+
const { confirm: confirmWorkspace, value: valueWorkspace } = await showExpansionPanelModal();
68236823

6824-
// const { confirm, value } = await showExpansionPanelModal();
6824+
if (!confirmWorkspace || !valueWorkspace) {
6825+
throw new Error('Unable To Find The Specified Workspace');
6826+
}
68256827

6826-
// if (!confirm || !value) {
6827-
// return;
6828-
// }
6828+
const { workspaceId, workspaceName } = valueWorkspace;
68296829

6830-
// try {
6831-
// const createUserSequenceInsertInput: UserSequenceInsertInput = {
6832-
// definition: expandedSequence,
6833-
// is_locked: false,
6834-
// name: sequence.seq_id,
6835-
// parcel_id: value.parcelId,
6836-
// seq_json: '',
6837-
// workspace_id: value.workspaceId,
6838-
// };
6839-
// const userSequenceCreated = await this.createUserSequence(createUserSequenceInsertInput, user);
6840-
// if (!userSequenceCreated) {
6841-
// throw Error('Sequence Import Failed');
6842-
// }
6843-
// } catch (e) {
6844-
// catchError(e as Error);
6845-
// }
6846-
// },
6830+
const workspaceContents = await effects.getWorkspaceContents(workspaceId, user);
6831+
if (!workspaceContents) {
6832+
throw new Error('Unable To Find The Specified Workspace');
6833+
}
6834+
6835+
const workspaceTree: WorkspaceTreeNode = {
6836+
contents: workspaceContents,
6837+
name: workspaceName,
6838+
type: WorkspaceContentType.Workspace,
6839+
};
6840+
workspaceTree;
6841+
6842+
const { confirm: confirmNewFile, value: confirmNewFileValue } = await showNewWorkspaceSequenceModal(
6843+
workspaceId,
6844+
workspaceTree,
6845+
'',
6846+
user,
6847+
);
6848+
6849+
if (confirmNewFile && confirmNewFileValue) {
6850+
const { filePath: newFilePath } = confirmNewFileValue;
6851+
const body = createWorkspaceSequenceFileFormData(newFilePath, expandedSequence);
6852+
await reqWorkspace<Workspace>(`${workspaceId}/${newFilePath}?type=file`, 'PUT', body, user, undefined, false);
6853+
showSuccessToast('Workspace File Created Successfully');
6854+
} else {
6855+
throw new Error('Workspace File Creation Failed');
6856+
}
6857+
} catch (e) {
6858+
catchError('Workspace file was unable to be created', e as Error);
6859+
showFailureToast('Workspace File Creation Failed');
6860+
}
6861+
return null;
6862+
},
68476863

68486864
async session(user: BaseUser | null): Promise<ReqSessionResponse> {
68496865
try {

src/utilities/modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ export async function showExpansionPanelModal(): Promise<ModalElementValue> {
15701570
expansionPanelModal.$destroy();
15711571
});
15721572

1573-
expansionPanelModal.$on('save', (e: CustomEvent<{ parcelId: number; workspaceId: number }>) => {
1573+
expansionPanelModal.$on('save', (e: CustomEvent<{ workspaceId: number }>) => {
15741574
target.replaceChildren();
15751575
target.resolve = null;
15761576
resolve({ confirm: true, value: e.detail });

0 commit comments

Comments
 (0)