Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/external dataset subscription #1081

Merged
merged 6 commits into from
Jan 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export let layer: Layer;
export let values: string[];
export let options: string[];
export let options: string[] = [];
const dispatch = createEventDispatcher();
Expand Down
10 changes: 6 additions & 4 deletions src/components/timeline/form/TimelineEditorPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
viewUpdateRow,
viewUpdateTimeline,
} from '../../../stores/views';
import type { ActivityType } from '../../../types/activity';
import type {
ActivityLayer,
Axis,
Expand Down Expand Up @@ -431,15 +432,16 @@
return [];
}

function getFilterOptionsForLayer(layer: Layer) {
function getFilterOptionsForLayer(layer: Layer, activityTypes: ActivityType[], externalResourceNames: string[]) {
if (layer.chartType === 'activity') {
return $activityTypes.map(t => t.name);
return activityTypes.map(t => t.name);
} else if (layer.chartType === 'line' || layer.chartType === 'x-range') {
return $resourceTypes
.map(t => t.name)
.concat($externalResourceNames)
.concat(externalResourceNames)
.sort();
}

return [];
}

Expand Down Expand Up @@ -945,7 +947,7 @@
</span>
<TimelineEditorLayerFilter
values={getFilterValuesForLayer(layer)}
options={getFilterOptionsForLayer(layer)}
options={getFilterOptionsForLayer(layer, $activityTypes, $externalResourceNames)}
{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
Loading