Skip to content

Commit

Permalink
Added a subscription for external datasets so you don't have to refre…
Browse files Browse the repository at this point in the history
…sh the UI for them to appear
  • Loading branch information
cohansen committed Jan 18, 2024
1 parent f11ce78 commit 611d745
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 67 deletions.
17 changes: 16 additions & 1 deletion src/components/timeline/form/TimelineEditorLayerFilter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
<script lang="ts">
import SearchIcon from '@nasa-jpl/stellar/icons/search.svg?component';
import { createEventDispatcher } from 'svelte';
import { activityTypes } from '../../../stores/plan';
import { externalResourceNames, resourceTypes } from '../../../stores/simulation';
import type { Layer } from '../../../types/timeline';
import Input from '../../form/Input.svelte';
import Menu from '../../menus/Menu.svelte';
import MenuHeader from '../../menus/MenuHeader.svelte';
export let layer: Layer;
export let values: string[];
export let options: string[];
const dispatch = createEventDispatcher();
Expand All @@ -20,6 +21,7 @@
let filteredValues: string[] = [];
let menuTitle: string = '';
let selectedValuesMap: Record<string, boolean> = {};
let options: string[] = [];
$: if (layer) {
selectedValuesMap = listToMap(values);
Expand All @@ -39,6 +41,19 @@
filteredValues = options.slice();
}
$: if ($activityTypes || $externalResourceNames) {
if (layer.chartType === 'activity') {
options = $activityTypes.map(t => t.name);
} else if (layer.chartType === 'line' || layer.chartType === 'x-range') {
options = $resourceTypes
.map(t => t.name)
.concat($externalResourceNames)
.sort();
} else {
options = [];
}
}
function listToMap(list: string[]): Record<string, boolean> {
return list.reduce((map: Record<string, true>, item) => {
if (!map[item]) {
Expand Down
22 changes: 2 additions & 20 deletions src/components/timeline/form/TimelineEditorPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
import { onMount } from 'svelte';
import { dndzone } from 'svelte-dnd-action';
import { ViewConstants } from '../../../enums/view';
import { activityTypes, maxTimeRange, viewTimeRange } from '../../../stores/plan';
import {
externalResourceNames,
resourceTypes,
resourcesByViewLayerId,
simulationDataset,
} from '../../../stores/simulation';
import { maxTimeRange, viewTimeRange } from '../../../stores/plan';
import { resourcesByViewLayerId, simulationDataset } from '../../../stores/simulation';
import {
selectedRow,
selectedRowId,
Expand Down Expand Up @@ -431,18 +426,6 @@
return [];
}
function getFilterOptionsForLayer(layer: Layer) {
if (layer.chartType === 'activity') {
return $activityTypes.map(t => t.name);
} else if (layer.chartType === 'line' || layer.chartType === 'x-range') {
return $resourceTypes
.map(t => t.name)
.concat($externalResourceNames)
.sort();
}
return [];
}
onMount(() => {
if ($selectedTimelineId === null) {
const firstTimeline = $view?.definition.plan.timelines[0];
Expand Down Expand Up @@ -945,7 +928,6 @@
</span>
<TimelineEditorLayerFilter
values={getFilterValuesForLayer(layer)}
options={getFilterOptionsForLayer(layer)}
{layer}
on:change={event => {
const { values } = event.detail;
Expand Down
18 changes: 11 additions & 7 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
activityTypes,
maxTimeRange,
plan,
planDatasets,
planEndTimeMs,
planId,
planLocked,
Expand Down Expand Up @@ -157,7 +158,6 @@
let windowWidth = 0;
let simulationDataAbortController: AbortController;
let resourcesExternalAbortController: AbortController;
let externalDatasetNamesAbortController: AbortController;
$: ({ invalidActivityCount, ...activityErrorCounts } = $activityErrorRollups.reduce(
(prevCounts, activityErrorRollup) => {
Expand Down Expand Up @@ -290,12 +290,16 @@
initializeView({ ...data.initialView });
}
$: if ($plan) {
externalDatasetNamesAbortController?.abort();
externalDatasetNamesAbortController = new AbortController();
effects
.getExternalDatasetNames($plan.id, data.user, externalDatasetNamesAbortController.signal)
.then(names => ($externalResourceNames = names));
$: if ($plan && $planDatasets) {
let datasetNames = [];
for (const dataset of $planDatasets) {
for (const profile of dataset.dataset.profiles) {
datasetNames.push(profile.name);
}
}
$externalResourceNames = [...new Set(datasetNames)];
resourcesExternalAbortController?.abort();
resourcesExternalAbortController = new AbortController();
Expand Down
3 changes: 3 additions & 0 deletions src/stores/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { derived, writable, type Readable, type Writable } from 'svelte/store';
import type { ActivityType } from '../types/activity';
import type { ModelSlim } from '../types/model';
import type { Plan, PlanMergeRequest, PlanMergeRequestSchema } from '../types/plan';
import type { PlanDataset } from '../types/simulation';
import type { Tag } from '../types/tags';
import type { TimeRange } from '../types/timeline';
import gql from '../utilities/gql';
Expand Down Expand Up @@ -47,6 +48,8 @@ export const planTags = gqlSubscribable<Tag[]>(gql.SUB_PLAN_TAGS, { planId }, []

export const models = gqlSubscribable<ModelSlim[]>(gql.SUB_MODELS, {}, [], null);

export const planDatasets = gqlSubscribable<PlanDataset[]>(gql.SUB_PLAN_DATASET, { planId }, [], null);

export const planLocked = gqlSubscribable<boolean>(
gql.SUB_PLAN_LOCKED,
{ planId },
Expand Down
39 changes: 0 additions & 39 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ import type {
} from '../types/sequencing';
import type {
PlanDataset,
PlanDatasetNames,
Profile,
Resource,
ResourceType,
Expand Down Expand Up @@ -2580,44 +2579,6 @@ const effects = {
}
},

async getExternalDatasetNames(
planId: number,
user: User | null,
signal: AbortSignal | undefined = undefined,
): Promise<string[]> {
try {
const data = await reqHasura<PlanDatasetNames[]>(
gql.GET_PROFILES_EXTERNAL_NAMES,
{
planId,
},
user,
signal,
);
const { plan_dataset: plan_datasets } = data;

if (plan_datasets != null) {
const resourceNames: string[] = [];

for (const dataset of plan_datasets) {
for (const profile of dataset.dataset.profiles) {
resourceNames.push(profile.name);
}
}

return [...new Set(resourceNames)];
} else {
throw Error('Unable to get external resource names');
}
} catch (e) {
const error = e as Error;
if (error.name !== 'AbortError') {
catchError(error);
}
return [];
}
},

async getModels(user: User | null): Promise<ModelSlim[]> {
try {
const data = await reqHasura<ModelSlim[]>(gql.GET_MODELS, {}, user);
Expand Down
17 changes: 17 additions & 0 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,23 @@ const gql = {
}
`,

SUB_PLAN_DATASET: `#graphql
subscription SubPlanDatasets($planId: Int!) {
plan_dataset(where: {plan_id: {_eq: $planId}}) {
dataset_id
simulation_dataset_id
dataset {
profiles {
duration
id
name
type
}
}
}
}
`,

SUB_PLAN_LOCKED: `#graphql
subscription SubPlanLocked($planId: Int!) {
planLocked: plan_by_pk(id: $planId) {
Expand Down

0 comments on commit 611d745

Please sign in to comment.