Skip to content

Commit

Permalink
Scheduling goal and condition loading refactor and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronPlave committed Jan 22, 2025
1 parent 60dae05 commit bed7eab
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import {
allowedSchedulingConditionSpecs,
schedulingConditions,
schedulingConditionsLoading,
schedulingPlanSpecification,
} from '../../stores/scheduling';
import type { User } from '../../types/app';
Expand Down Expand Up @@ -287,10 +288,11 @@
</div>
<hr />
<div class="conditions-modal-table-container">
{#if filteredConditions.length}
{#if $schedulingConditionsLoading || filteredConditions.length}
<DataGrid
bind:this={dataGrid}
{columnDefs}
loading={$schedulingConditionsLoading}
rowData={filteredConditions}
on:cellEditingStopped={onToggleCondition}
/>
Expand Down
21 changes: 16 additions & 5 deletions src/components/modals/ManagePlanSchedulingGoalsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import { PlanStatusMessages } from '../../enums/planStatusMessages';
import { SearchParameters } from '../../enums/searchParameters';
import { plan, planReadOnly } from '../../stores/plan';
import { allowedSchedulingGoalSpecs, schedulingGoals, schedulingPlanSpecification } from '../../stores/scheduling';
import {
allowedSchedulingGoalSpecs,
schedulingGoals,
schedulingGoalsLoading,
schedulingPlanSpecification,
} from '../../stores/scheduling';
import type { User } from '../../types/app';
import type { DataGridColumnDef } from '../../types/data-grid';
import type {
Expand Down Expand Up @@ -116,7 +121,7 @@
const includesName = goal.name.toLocaleLowerCase().includes(filterTextLowerCase);
return includesId || includesName;
});
$: selectedGoals = $allowedSchedulingGoalSpecs.reduce(
$: selectedGoals = ($allowedSchedulingGoalSpecs || []).reduce(
(prevBooleanMap: Record<string, boolean>, schedulingGoalPlanSpec: SchedulingGoalPlanSpecification) => {
return {
...prevBooleanMap,
Expand Down Expand Up @@ -202,7 +207,7 @@
}
async function onUpdateGoals(selectedGoals: Record<number, boolean>) {
if ($plan && $schedulingPlanSpecification) {
if ($plan && $schedulingPlanSpecification && $allowedSchedulingGoalSpecs) {
const goalPlanSpecUpdates: {
goalPlanSpecIdsToDelete: number[];
goalPlanSpecsToAdd: SchedulingGoalPlanSpecInsertInput[];
Expand Down Expand Up @@ -288,8 +293,14 @@
</div>
<hr />
<div class="goals-modal-table-container">
{#if filteredGoals.length}
<DataGrid bind:this={dataGrid} {columnDefs} rowData={filteredGoals} on:cellEditingStopped={onToggleGoal} />
{#if $schedulingGoalsLoading || filteredGoals.length}
<DataGrid
bind:this={dataGrid}
{columnDefs}
rowData={filteredGoals}
on:cellEditingStopped={onToggleGoal}
loading={$schedulingGoalsLoading}
/>
{:else}
<div class="p1 st-typography-label">No Scheduling Goals Found</div>
{/if}
Expand Down
9 changes: 2 additions & 7 deletions src/components/scheduling/SchedulingConditionsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { plan, planReadOnly } from '../../stores/plan';
import {
allowedSchedulingConditionSpecs,
schedulingConditionResponses,
schedulingConditionSpecifications,
schedulingConditionsLoading,
schedulingConditionsMap,
} from '../../stores/scheduling';
import type { User } from '../../types/app';
Expand Down Expand Up @@ -86,10 +86,6 @@
activeElement.focus();
}
});
$: console.log('$schedulingConditionSpecifications :>> ', $schedulingConditionSpecifications);
$: console.log('filteredSchedulingConditionSpecs :>> ', filteredSchedulingConditionSpecs);
$: console.log('$schedulingConditionsMap :>> ', $schedulingConditionsMap);
</script>

<Panel>
Expand Down Expand Up @@ -119,8 +115,7 @@
</svelte:fragment>
</CollapsibleListControls>
<div class="pt-2">
<!-- TODO should we instead have the schedulingConditionsMap be nullable or should the pattern be to look at the responses? Or do we do another derived store to say if these things have been loaded? -->
{#if !$allowedSchedulingConditionSpecs || !$schedulingConditionResponses}
{#if $schedulingConditionsLoading}
<div class="pt-1">
<Loading />
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/components/scheduling/SchedulingGoalsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
enableScheduling,
schedulingAnalysisStatus,
schedulingGoalSpecifications,
schedulingGoalsLoading,
schedulingGoalsMap,
} from '../../stores/scheduling';
import type { User } from '../../types/app';
Expand Down Expand Up @@ -41,7 +42,7 @@
let visibleSchedulingGoalSpecs: SchedulingGoalPlanSpecification[] = [];
// TODO: remove this after db merge as it becomes redundant
$: visibleSchedulingGoalSpecs = $allowedSchedulingGoalSpecs.filter(({ goal_metadata: goalMetadata }) => {
$: visibleSchedulingGoalSpecs = ($allowedSchedulingGoalSpecs || []).filter(({ goal_metadata: goalMetadata }) => {
if (goalMetadata) {
const { public: isPublic, owner } = goalMetadata;
if (!isPublic && !isAdminRole(user?.activeRole)) {
Expand Down Expand Up @@ -208,7 +209,7 @@
</svelte:fragment>
</CollapsibleListControls>
<div class="pt-2">
{#if !$schedulingGoalSpecifications}
{#if $schedulingGoalsLoading}
<div class="pt-1">
<Loading />
</div>
Expand Down
16 changes: 15 additions & 1 deletion src/stores/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,26 @@ export const allowedSchedulingConditionSpecs: Readable<SchedulingConditionPlanSp
: null,
);

export const allowedSchedulingGoalSpecs: Readable<SchedulingGoalPlanSpecification[]> = derived(
export const allowedSchedulingGoalSpecs: Readable<SchedulingGoalPlanSpecification[] | null> = derived(
[schedulingGoalSpecifications],
([$schedulingGoalSpecifications]) =>
($schedulingGoalSpecifications || []).filter(({ goal_metadata: goalMetadata }) => goalMetadata !== null),
);

export const schedulingGoalsLoading = derived(
[schedulingGoalSpecifications, schedulingGoalResponses],
([$schedulingGoalSpecifications, $schedulingGoalResponses]) => {
return !$schedulingGoalSpecifications || !$schedulingGoalResponses;
},
);

export const schedulingConditionsLoading = derived(
[schedulingConditionSpecifications, schedulingConditionResponses],
([$schedulingConditionSpecifications, $schedulingConditionResponses]) => {
return !$schedulingConditionSpecifications || !$schedulingConditionResponses;
},
);

export const latestSchedulingGoalAnalyses = derived(
[selectedSpecId, schedulingGoalSpecifications],
([$selectedSpecId, $schedulingGoalSpecifications]) => {
Expand Down

0 comments on commit bed7eab

Please sign in to comment.