Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/expansion/ExpansionPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
40 changes: 7 additions & 33 deletions src/components/modals/ExpansionPanelModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,24 +18,24 @@
const dispatch = createEventDispatcher<{
close: void;
save: { parcelId: number; workspaceId: number };
save: { workspaceId: number; workspaceName: string };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to pass the workspace name in this save event? It doesn't look like you're using it. I think ideally, the workspaceId should be enough.

}>();
let workspaceIdField = field<number>(-1, [min(1, 'Field is required')]);
let workspaceIdFieldName: string;
let selectedWorkspace: Workspace | undefined;
let parcelIdField = field<number>(-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 });
}
}
Expand All @@ -55,13 +53,6 @@
}
return `${workspace.name} (${workspace.id})`;
}
function getDisplayNameForParcel(parcel?: Parcel) {
if (!parcel) {
return '';
}
return `${parcel.name} (${parcel.id})`;
}
</script>

<svelte:window on:keydown={onKeydown} />
Expand Down Expand Up @@ -97,23 +88,6 @@
<Select.Input type="number" name="workspace-id" aria-label="Select Workspace hidden input" />
</Select.Root>
</Field>
<Field field={parcelIdField}>
<Label size="sm" for="parcel-id" class="pb-0.5">Parcel Id</Label>
<Select.Root selected={{ label: getDisplayNameForParcel(selectedParcel), value: selectedParcel?.id ?? '' }}>
<Select.Trigger class="min-w-[124px]" value={selectedParcel?.id} size="xs" aria-labelledby={null}>
<Select.Value aria-label="Select a parcel" placeholder="Select a parcel" />
</Select.Trigger>
<Select.Content class="z-[10000]">
{#each $parcels as parcel}
<Select.Item size="xs" value={parcel.id} label={getDisplayNameForParcel(parcel)} class="flex gap-1">
{parcel.name}
<div class="whitespace-nowrap text-muted-foreground">(Id: {parcel.id})</div>
</Select.Item>
{/each}
</Select.Content>
<Select.Input type="number" name="parcel-id" aria-label="Select Parcel hidden input" />
</Select.Root>
</Field>
</fieldset>
</ModalContent>

Expand Down
86 changes: 51 additions & 35 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ import {
showDeleteExternalEventSourceTypeModal,
showDeleteExternalSourceModal,
showEditViewModal,
showExpansionPanelModal,
showImportWorkspaceFileModal,
showLibrarySequenceModel,
showManagePlanConstraintsModal,
Expand Down Expand Up @@ -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<void> {
// if (sequence === null) {
// showFailureToast("Sequence Doesn't Exist");
// return;
// }
async sendSequenceToWorkspace(
sequence: ExpansionSequence | null,
expandedSequence: string | null,
user: User | null,
): Promise<string | null> {
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<Workspace>(`${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<ReqSessionResponse> {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ export async function showExpansionPanelModal(): Promise<ModalElementValue> {
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 });
Expand Down
Loading