Skip to content

Commit 1f9f064

Browse files
committed
Improve state management of the project context
- Update workflow page context management - Update project page context management
1 parent cdd7bf7 commit 1f9f064

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/lib/stores/projectStores.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export const modalProject = writable({})
88
// Context project store
99
export const contextProject = writable({
1010
project: undefined,
11-
workflows: undefined,
12-
datasets: undefined
11+
workflows: [],
12+
datasets: []
1313
})

src/routes/projects/[id]/+page.svelte

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
let workflows
1414
let projectUpdatesSuccess = undefined
1515
16-
$: project = $contextProject.project
17-
$: workflows = $contextProject.workflows
16+
// Subscribe to the project context store
17+
contextProject.subscribe((context) => {
18+
project = context.project
19+
workflows = context.workflows
20+
})
1821
1922
onMount(async () => {
20-
project = undefined
21-
workflows = []
2223
await loadProjectContext($page.params.id)
2324
})
2425

src/routes/projects/[id]/workflows/[workflowId]/+page.svelte

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { enhance } from '$app/forms'
55
import { goto } from '$app/navigation'
66
import { page } from '$app/stores'
7+
import { loadProjectContext } from '$lib/components/projects/controller'
78
import { contextProject } from '$lib/stores/projectStores'
89
import { getWorkflow, updateWorkflow, reorderWorkflow, exportWorkflow, createWorkflowTask, deleteWorkflowTask, applyWorkflow } from '$lib/api/v1/workflow/workflow_api'
910
import { listTasks } from '$lib/api/v1/task/task_api'
@@ -13,15 +14,13 @@
1314
import MetaPropertiesForm from '$lib/components/workflow/MetaPropertiesForm.svelte'
1415
1516
let workflow = undefined
16-
let project = $contextProject.project
17-
let datasets = $contextProject.datasets || []
18-
19-
$: updatableWorkflowList = workflow ? workflow.task_list : []
2017
// List of available tasks to be inserted into workflow
2118
let availableTasks = []
19+
// Project context properties
20+
let project
21+
let datasets = []
2222
2323
let workflowTaskContext = writable(undefined)
24-
2524
let workflowTabContextId = 0
2625
2726
let selectedWorkflowTask = undefined
@@ -30,6 +29,14 @@
3029
let outputDatasetControl = ''
3130
let workerInitControl = ''
3231
32+
$: updatableWorkflowList = workflow?.task_list || []
33+
34+
35+
contextProject.subscribe((context) => {
36+
project = context.project
37+
datasets = context.datasets
38+
})
39+
3340
workflowTaskContext.subscribe((value) => {
3441
selectedWorkflowTask = value
3542
})
@@ -42,7 +49,8 @@
4249
}
4350
4451
onMount(async () => {
45-
await loadWorkflow();
52+
await loadWorkflow()
53+
await loadProjectContext($page.params.id)
4654
})
4755
4856
async function handleExportWorkflow(event) {
@@ -387,9 +395,9 @@
387395
</div>
388396
<div class="modal-body">
389397
390-
{#if workflow != undefined && updatableWorkflowList.length == 0 }
398+
{#if workflow !== undefined && updatableWorkflowList.length == 0 }
391399
<p class="text-center mt-3">No workflow tasks yet, add one.</p>
392-
{:else if workflow != undefined}
400+
{:else if workflow !== undefined}
393401
<ul class="list-group list-group-flush">
394402
{#each updatableWorkflowList as workflowTask, i }
395403
<li class="list-group-item" data-fs-target={workflowTask.id}>

0 commit comments

Comments
 (0)