Skip to content

Commit

Permalink
load simulation datasets relevant to snapshot
Browse files Browse the repository at this point in the history
auto select latest available simulation
add simulation dataset id to URL when choosing dataset or snapshot
  • Loading branch information
duranb committed Sep 18, 2023
1 parent 6ea0acf commit 3937cba
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/modals/CreatePlanSnapshotModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
const dispatch = createEventDispatcher();
let snapshotName: string = `${plan.name} - Snapshot`;
let snapshotName: string = '';
let createButtonDisabled: boolean = true;
$: createButtonDisabled = snapshotName === '';
Expand Down Expand Up @@ -44,7 +44,7 @@
<label for="name">Name of snapshot</label>
<input
bind:value={snapshotName}
placeholder="Name of snapshot"
placeholder={`${plan.name} - Snapshot`}
autocomplete="off"
class="st-input w-100"
name="name"
Expand Down
2 changes: 1 addition & 1 deletion src/components/plan/PlanMergeReview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const mockInitialPlan: Plan = {
parent_plan: null,
revision: 3,
scheduling_specifications: [{ id: 1 }],
simulations: [{ simulation_datasets: [{ id: 1 }] }],
simulations: [{ simulation_datasets: [{ id: 1, plan_revision: 3 }] }],
start_time: '2023-02-16T00:00:00',
start_time_doy: '2023-047T00:00:00',
tags: [],
Expand Down
21 changes: 19 additions & 2 deletions src/components/simulation/SimulationPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<script lang="ts">
import PlanLeftArrow from '@nasa-jpl/stellar/icons/plan_with_left_arrow.svg?component';
import PlanRightArrow from '@nasa-jpl/stellar/icons/plan_with_right_arrow.svg?component';
import { SearchParameters } from '../../enums/searchParameters';
import { field } from '../../stores/form';
import { plan, planEndTimeMs, planStartTimeMs } from '../../stores/plan';
import { planSnapshot } from '../../stores/planSnapshots';
import {
enableSimulation,
simulation,
Expand All @@ -25,6 +27,7 @@
import type { GqlSubscribable } from '../../types/subscribable';
import type { ViewGridSection } from '../../types/view';
import effects from '../../utilities/effects';
import { setQueryParam } from '../../utilities/generic';
import gql from '../../utilities/gql';
import { getArguments, getFormParameters } from '../../utilities/parameters';
import { permissionHandler } from '../../utilities/permissionHandler';
Expand Down Expand Up @@ -59,6 +62,7 @@
let startTimeDoyField: FieldStore<string>;
let modelParametersMap: ParametersMap = {};
let simulationDatasets: GqlSubscribable<SimulationDataset[]>;
let filteredSimulationDatasets: SimulationDataset[] = [];
$: if (user !== null && $plan !== null) {
hasRunPermission = featurePermissions.simulation.canRun(user, $plan);
Expand Down Expand Up @@ -116,6 +120,18 @@
);
}
$: if ($simulationDatasets?.length) {
if ($planSnapshot) {
filteredSimulationDatasets = $simulationDatasets.filter(
simulationDataset => simulationDataset.plan_revision === $planSnapshot?.revision,
);
} else {
filteredSimulationDatasets = $simulationDatasets;
}
} else {
filteredSimulationDatasets = [];
}
async function onChangeFormParameters(event: CustomEvent<FormParameter>) {
if ($simulation !== null) {
const { detail: formParameter } = event;
Expand Down Expand Up @@ -367,10 +383,10 @@
<fieldset>
<Collapse title="Simulation History">
<div class="simulation-history">
{#if !$simulationDatasets || !$simulationDatasets.length}
{#if !filteredSimulationDatasets || !filteredSimulationDatasets.length}
<div>No Simulation Datasets</div>
{:else}
{#each $simulationDatasets as simDataset (simDataset.id)}
{#each filteredSimulationDatasets as simDataset (simDataset.id)}
<SimulationHistoryDataset
queuePosition={getSimulationQueuePosition(simDataset, $simulationDatasetsAll)}
simulationDataset={simDataset}
Expand All @@ -379,6 +395,7 @@
checked={simDataset.id === $simulationDatasetId}
on:click={() => {
simulationDatasetId.set(simDataset.id);
setQueryParam(SearchParameters.SIMULATION_DATASET_ID, `${$simulationDatasetId}`);
}}
on:cancel={onCancelSimulation}
/>
Expand Down
15 changes: 13 additions & 2 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
import type { ActivityDirective } from '../../../types/activity';
import type { ViewSaveEvent, ViewToggleEvent } from '../../../types/view';
import effects from '../../../utilities/effects';
import { removeQueryParam } from '../../../utilities/generic';
import { getSearchParameterNumber, removeQueryParam, setQueryParam } from '../../../utilities/generic';
import { isSaveEvent } from '../../../utilities/keyboardEvents';
import { closeActiveModal, showPlanLockedModal } from '../../../utilities/modal';
import { featurePermissions } from '../../../utilities/permissions';
Expand Down Expand Up @@ -138,7 +138,6 @@
const querySimulationDatasetId = $page.url.searchParams.get(SearchParameters.SIMULATION_DATASET_ID);
if (querySimulationDatasetId) {
$simulationDatasetId = parseInt(querySimulationDatasetId);
removeQueryParam(SearchParameters.SIMULATION_DATASET_ID);
} else {
$simulationDatasetId = data.initialPlan.simulations[0]?.simulation_datasets[0]?.id ?? -1;
}
Expand Down Expand Up @@ -167,6 +166,18 @@
planSnapshotActivityDirectives = directives;
}
});
const currentPlanSnapshotSimulation = data.initialPlan.simulations[0]?.simulation_datasets.find(simulation => {
return simulation.id === getSearchParameterNumber(SearchParameters.SIMULATION_DATASET_ID);
});
const latestPlanSnapshotSimulation = data.initialPlan.simulations[0]?.simulation_datasets.find(simulation => {
return simulation.plan_revision === $planSnapshot?.revision;
});
if (!currentPlanSnapshotSimulation && latestPlanSnapshotSimulation) {
$simulationDatasetId = latestPlanSnapshotSimulation.id;
setQueryParam(SearchParameters.SIMULATION_DATASET_ID, `${$simulationDatasetId}`);
}
}
$: if (data.initialView) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export type PlanSchema = {
parent_plan: Pick<PlanSchema, 'id' | 'name'> | null;
revision: number;
scheduling_specifications: Pick<SchedulingSpec, 'id'>[];
simulations: [{ simulation_datasets: [{ id: number }] }];
simulations: [{ simulation_datasets: [{ id: number; plan_revision: number }] }];
start_time: string;
tags: { tag: Tag }[];
updated_at: string;
Expand Down
4 changes: 3 additions & 1 deletion src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,9 @@ const gql = {
id
}
simulations(order_by: { id: desc }, limit: 1) {
simulation_datasets(order_by: { id: desc }, limit: 1) {
simulation_datasets(order_by: { id: desc }) {
id
plan_revision
}
}
start_time
Expand Down Expand Up @@ -1844,6 +1845,7 @@ const gql = {
simulation_datasets(order_by: { id: desc }) {
canceled
id
plan_revision
requested_at
requested_by
simulation_end_time
Expand Down

0 comments on commit 3937cba

Please sign in to comment.