Skip to content

Commit

Permalink
Scheduling goal and condition loading states within a plan
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronPlave committed Jan 17, 2025
1 parent 4b2e2dd commit 733bf1e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
const includesName = condition.name.toLocaleLowerCase().includes(filterTextLowerCase);
return includesId || includesName;
});
$: selectedConditions = $allowedSchedulingConditionSpecs.reduce(
$: selectedConditions = ($allowedSchedulingConditionSpecs || []).reduce(
(prevBooleanMap: Record<string, boolean>, schedulingConditionPlanSpec: SchedulingConditionPlanSpecification) => {
return {
...prevBooleanMap,
Expand Down Expand Up @@ -205,6 +205,7 @@
}
}
// TODO BUG scheduling condition management not working within a plan, something broke it in this PR.
async function onUpdateCondition(selectedConditions: Record<number, boolean>) {
if ($plan && $schedulingPlanSpecification) {
const conditionPlanSpecUpdates: {
Expand All @@ -220,7 +221,7 @@
) => {
const conditionId = parseInt(selectedConditionId);
const isSelected = selectedConditions[conditionId];
const conditionPlanSpec = $allowedSchedulingConditionSpecs[conditionId];
const conditionPlanSpec = ($allowedSchedulingConditionSpecs || [])[conditionId]; // TODO how does this work? it is an array not a map here?
if (isSelected && $schedulingPlanSpecification !== null) {
if (!conditionPlanSpec || conditionPlanSpec.condition_metadata?.owner === user?.id) {
Expand Down
18 changes: 15 additions & 3 deletions src/components/scheduling/SchedulingConditionsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { plan, planReadOnly } from '../../stores/plan';
import {
allowedSchedulingConditionSpecs,
schedulingConditionResponses,
schedulingConditionSpecifications,
schedulingConditionsMap,
} from '../../stores/scheduling';
Expand All @@ -16,6 +17,7 @@
import { permissionHandler } from '../../utilities/permissionHandler';
import { featurePermissions, isAdminRole } from '../../utilities/permissions';
import CollapsibleListControls from '../CollapsibleListControls.svelte';
import Loading from '../Loading.svelte';
import GridMenu from '../menus/GridMenu.svelte';
import Panel from '../ui/Panel.svelte';
import SchedulingCondition from './conditions/SchedulingCondition.svelte';
Expand All @@ -30,7 +32,7 @@
let visibleSchedulingConditionSpecs: SchedulingConditionPlanSpecification[] = [];
// TODO: remove this after db merge as it becomes redundant
$: visibleSchedulingConditionSpecs = $allowedSchedulingConditionSpecs.filter(
$: visibleSchedulingConditionSpecs = ($allowedSchedulingConditionSpecs || []).filter(
({ condition_metadata: conditionMetadata }) => {
if (conditionMetadata) {
const { public: isPublic, owner } = conditionMetadata;
Expand All @@ -47,7 +49,8 @@
const includesName = spec.condition_metadata?.name.toLocaleLowerCase().includes(filterTextLowerCase);
return includesName;
});
$: numOfPrivateConditions = $schedulingConditionSpecifications.length - visibleSchedulingConditionSpecs.length;
$: numOfPrivateConditions =
($schedulingConditionSpecifications || []).length - visibleSchedulingConditionSpecs.length;
function onManageConditions() {
effects.managePlanSchedulingConditions(user);
Expand Down Expand Up @@ -83,6 +86,10 @@
activeElement.focus();
}
});
$: console.log('$schedulingConditionSpecifications :>> ', $schedulingConditionSpecifications);
$: console.log('filteredSchedulingConditionSpecs :>> ', filteredSchedulingConditionSpecs);
$: console.log('$schedulingConditionsMap :>> ', $schedulingConditionsMap);
</script>

<Panel>
Expand Down Expand Up @@ -112,7 +119,12 @@
</svelte:fragment>
</CollapsibleListControls>
<div class="pt-2">
{#if !filteredSchedulingConditionSpecs.length}
<!-- 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}
<div class="pt-1">
<Loading />
</div>
{:else if !filteredSchedulingConditionSpecs.length}
<div class="pt-1 st-typography-label">No scheduling conditions found</div>
<div class="private-label">
{#if numOfPrivateConditions > 0}
Expand Down
9 changes: 7 additions & 2 deletions src/components/scheduling/SchedulingGoalsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { permissionHandler } from '../../utilities/permissionHandler';
import { featurePermissions, isAdminRole } from '../../utilities/permissions';
import CollapsibleListControls from '../CollapsibleListControls.svelte';
import Loading from '../Loading.svelte';
import GridMenu from '../menus/GridMenu.svelte';
import Panel from '../ui/Panel.svelte';
import PanelHeaderActionButton from '../ui/PanelHeaderActionButton.svelte';
Expand Down Expand Up @@ -65,7 +66,7 @@
}
return 0;
});
$: numOfPrivateGoals = $schedulingGoalSpecifications.length - visibleSchedulingGoalSpecs.length;
$: numOfPrivateGoals = ($schedulingGoalSpecifications || []).length - visibleSchedulingGoalSpecs.length;
$: if ($plan) {
hasAnalyzePermission =
featurePermissions.schedulingGoalsPlanSpec.canAnalyze(user, $plan, $plan.model) && !$planReadOnly;
Expand Down Expand Up @@ -207,7 +208,11 @@
</svelte:fragment>
</CollapsibleListControls>
<div class="pt-2">
{#if !filteredSchedulingGoalSpecs.length}
{#if !$schedulingGoalSpecifications}
<div class="pt-1">
<Loading />
</div>
{:else if !filteredSchedulingGoalSpecs.length}
<div class="pt-1 st-typography-label">No scheduling goals found</div>
<div class="private-label">
{#if numOfPrivateGoals > 0}
Expand Down
20 changes: 11 additions & 9 deletions src/stores/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,28 @@ export const schedulingGoalsMap: Readable<Record<string, SchedulingGoalMetadata>

export const schedulingConditionSpecifications = derived(
[schedulingPlanSpecification],
([$schedulingPlanSpecification]) => $schedulingPlanSpecification?.conditions ?? [],
([$schedulingPlanSpecification]) => $schedulingPlanSpecification?.conditions ?? null,
);

export const schedulingGoalSpecifications = derived(
[schedulingPlanSpecification],
([$schedulingPlanSpecification]) => $schedulingPlanSpecification?.goals ?? [],
([$schedulingPlanSpecification]) => $schedulingPlanSpecification?.goals ?? null,
);

export const allowedSchedulingConditionSpecs: Readable<SchedulingConditionPlanSpecification[]> = derived(
export const allowedSchedulingConditionSpecs: Readable<SchedulingConditionPlanSpecification[] | null> = derived(
[schedulingConditionSpecifications],
([$schedulingConditionSpecifications]) =>
$schedulingConditionSpecifications.filter(
({ condition_metadata: conditionMetadata }) => conditionMetadata !== null,
),
$schedulingConditionSpecifications
? $schedulingConditionSpecifications.filter(
({ condition_metadata: conditionMetadata }) => conditionMetadata !== null,
)
: null,
);

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

export const latestSchedulingGoalAnalyses = derived(
Expand All @@ -162,7 +164,7 @@ export const latestSchedulingGoalAnalyses = derived(
const analysisIdToSpecGoalMap: Record<number, SchedulingGoalAnalysis[]> = {};
let latestAnalysisId = -1;

$schedulingGoalSpecifications.forEach(schedulingSpecGoal => {
($schedulingGoalSpecifications || []).forEach(schedulingSpecGoal => {
let analyses: SchedulingGoalAnalysis[] = [];
if (schedulingSpecGoal.goal_definition != null) {
analyses = schedulingSpecGoal.goal_definition.analyses ?? [];
Expand Down Expand Up @@ -278,7 +280,7 @@ export const schedulingAnalysisStatus = derived(
export const enableScheduling: Readable<boolean> = derived(
[schedulingGoalSpecifications],
([$schedulingGoalSpecifications]) => {
return $schedulingGoalSpecifications.filter(schedulingSpecGoal => schedulingSpecGoal.enabled).length > 0;
return ($schedulingGoalSpecifications || []).filter(schedulingSpecGoal => schedulingSpecGoal.enabled).length > 0;
},
);

Expand Down

0 comments on commit 733bf1e

Please sign in to comment.