Skip to content

Commit

Permalink
Change scheduling_specifications to scheduling_specification (#1144)
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb authored Mar 6, 2024
1 parent b665378 commit 4bbc97f
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/plan/PlanMergeReview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const mockInitialPlan: Plan = {
owner: 'spacecaptain',
parent_plan: null,
revision: 3,
scheduling_specifications: [{ id: 1 }],
scheduling_specification: { id: 1 },
simulations: [{ simulation_datasets: [{ id: 1, plan_revision: 3 }] }],
start_time: '2023-02-16T00:00:00',
start_time_doy: '2023-047T00:00:00',
Expand Down
4 changes: 2 additions & 2 deletions src/components/scheduling/Scheduling.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
async function deleteCondition(condition: SchedulingCondition) {
const { scheduling_specification_conditions } = condition;
const specification_id = scheduling_specification_conditions[0].specification_id;
const plan = plans?.find(plan => plan.scheduling_specifications[0]?.id === specification_id);
const plan = plans?.find(plan => plan.scheduling_specification?.id === specification_id);
if (plan) {
const success = await effects.deleteSchedulingCondition(condition, plan, user);
Expand All @@ -58,7 +58,7 @@
let plan = null;
if (scheduling_specification_goal) {
const specification_id = scheduling_specification_goal.specification_id;
plan = plans?.find(plan => plan.scheduling_specifications[0]?.id === specification_id) ?? null;
plan = plans?.find(plan => plan.scheduling_specification?.id === specification_id) ?? null;
}
const success = await effects.deleteSchedulingGoal(goal, plan, user);
if (success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
$: planOptions = plans
.filter(plan => plan.model_id === conditionModelId)
.map(({ scheduling_specifications, ...plan }) => ({
.map(({ scheduling_specification, ...plan }) => ({
...plan,
scheduling_specifications,
specId: scheduling_specifications?.[0] ? scheduling_specifications[0].id : null,
scheduling_specification,
specId: scheduling_specification ? scheduling_specification.id : null,
}));
$: selectedPlan = planOptions.find(({ specId: planSpecId }) => planSpecId === specId);
$: specId = planOptions.some(plan => plan.specId === specId) ? specId : null; // Null the specId value if the filtered plan list no longer includes the chosen spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
let plan = null;
if (condition.scheduling_specification_conditions.length > 0) {
const specification_id = condition.scheduling_specification_conditions[0].specification_id;
plan = plans?.find(plan => plan.scheduling_specifications[0]?.id === specification_id) ?? null;
plan = plans?.find(plan => plan.scheduling_specification?.id === specification_id) ?? null;
}
return plan;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/scheduling/goals/SchedulingGoalForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
$: planOptions = plans
.filter(plan => plan.model_id === goalModelId)
.map(({ scheduling_specifications, ...plan }) => ({
.map(({ scheduling_specification, ...plan }) => ({
...plan,
specId: (scheduling_specifications && scheduling_specifications[0]?.id) || null,
specId: (scheduling_specification && scheduling_specification.id) || null,
}));
$: selectedPlan = planOptions.find(({ specId: planSpecId }) => planSpecId === specId);
$: specId = planOptions.some(plan => plan.specId === specId) ? specId : null; // Null the specId value if the filtered plan list no longer includes the chosen spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@ const plans: PlanSchedulingSpec[] = [
model_id: 1,
name: 'Plan With Scheduling Spec',
owner: 'foo',
scheduling_specifications: [
{
id: 1,
},
],
scheduling_specification: {
id: 1,
},
},
{
collaborators: [],
id: 2,
model_id: 1,
name: 'Plan Without Scheduling Spec',
owner: 'foo',
scheduling_specifications: [],
scheduling_specification: null,
},
];

Expand Down
2 changes: 1 addition & 1 deletion src/components/scheduling/goals/SchedulingGoals.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
const {
scheduling_specification_goal: { specification_id },
} = goal;
plan = plans?.find(plan => plan.scheduling_specifications[0]?.id === specification_id) ?? null;
plan = plans?.find(plan => plan.scheduling_specification?.id === specification_id) ?? null;
}
return plan;
}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/plans/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const load: PageLoad = async ({ parent, params, url }) => {
}

// if plan doesn't have a scheduling spec, create one at this point
if (!initialPlan.scheduling_specifications.length) {
if (!initialPlan.scheduling_specification) {
const { start_time_doy, end_time_doy, revision } = initialPlan;
const schedulingSpec = await effects.createSchedulingSpec(
{
Expand All @@ -36,7 +36,7 @@ export const load: PageLoad = async ({ parent, params, url }) => {

initialPlan = {
...initialPlan,
scheduling_specifications: schedulingSpec ? [schedulingSpec] : [],
scheduling_specification: schedulingSpec ? schedulingSpec : null,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/stores/scheduling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const schedulingGoalsColumns: Writable<string> = writable('1fr 3px 2fr');

/* Derived. */

export const selectedSpecId = derived(plan, $plan => $plan?.scheduling_specifications[0]?.id ?? null);
export const selectedSpecId = derived(plan, $plan => $plan?.scheduling_specification?.id ?? null);

/* Subscriptions. */

Expand Down
4 changes: 2 additions & 2 deletions src/types/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type PlanSchema = {
owner: UserId;
parent_plan: Pick<PlanSchema, 'id' | 'name' | 'owner' | 'collaborators'> | null;
revision: number;
scheduling_specifications: Pick<SchedulingSpec, 'id'>[];
scheduling_specification: Pick<SchedulingSpec, 'id'> | null;
simulations: [{ simulation_datasets: [{ id: number; plan_revision: number }] }];
start_time: string;
tags: { tag: Tag }[];
Expand Down Expand Up @@ -114,5 +114,5 @@ export type PlanSlimmer = Pick<PlanSlim, 'id' | 'start_time' | 'end_time_doy'>;

export type PlanSchedulingSpec = Pick<
Plan,
'id' | 'name' | 'scheduling_specifications' | 'model_id' | 'owner' | 'collaborators'
'id' | 'name' | 'scheduling_specification' | 'model_id' | 'owner' | 'collaborators'
>;
4 changes: 2 additions & 2 deletions src/utilities/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ const gql = {
}
}
revision
scheduling_specifications {
scheduling_specification {
id
}
simulations(order_by: { id: desc }, limit: 1) {
Expand Down Expand Up @@ -1020,7 +1020,7 @@ const gql = {
collaborators {
collaborator
}
scheduling_specifications {
scheduling_specification {
id
}
model_id
Expand Down

0 comments on commit 4bbc97f

Please sign in to comment.