Skip to content

Commit f6e725c

Browse files
committed
feat: add effect to fetch multiple execution trees and update state accordingly
1 parent 4a994da commit f6e725c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

  • apps/chaingraph-frontend/src/store/execution-tree

apps/chaingraph-frontend/src/store/execution-tree/stores.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ export const fetchExecutionDetailsFx = executionDomain.createEffect(
134134
},
135135
)
136136

137+
// Fetch multiple execution trees (for refreshing expanded trees)
138+
export const fetchMultipleExecutionTreesFx = executionDomain.createEffect(
139+
async (executionIds: string[]) => {
140+
const promises = executionIds.map(id => fetchExecutionTreeFx(id))
141+
return await Promise.all(promises)
142+
},
143+
)
144+
137145
// ============================================================================
138146
// STORE UPDATES
139147
// ============================================================================
@@ -162,6 +170,16 @@ $loadingTrees
162170
newSet.delete(executionId)
163171
return newSet
164172
})
173+
.on(fetchMultipleExecutionTreesFx, (state, executionIds) => {
174+
const newSet = new Set(state)
175+
executionIds.forEach(id => newSet.add(id))
176+
return newSet
177+
})
178+
.on(fetchMultipleExecutionTreesFx.finally, (state, { params: executionIds }) => {
179+
const newSet = new Set(state)
180+
executionIds.forEach(id => newSet.delete(id))
181+
return newSet
182+
})
165183

166184
// Store for selected execution details
167185
export const $selectedExecutionDetails = executionDomain
@@ -225,9 +243,14 @@ $executionTreeError
225243
message: error.message,
226244
code: 'FETCH_DETAILS_ERROR',
227245
}))
246+
.on(fetchMultipleExecutionTreesFx.failData, (_, error) => ({
247+
message: error.message,
248+
code: 'FETCH_MULTIPLE_TREES_ERROR',
249+
}))
228250
.reset(fetchRootExecutionsFx)
229251
.reset(fetchExecutionTreeFx)
230252
.reset(fetchExecutionDetailsFx)
253+
.reset(fetchMultipleExecutionTreesFx)
231254

232255
// ============================================================================
233256
// SAMPLES (Event connections)
@@ -271,6 +294,15 @@ sample({
271294
target: fetchRootExecutionsFx,
272295
})
273296

297+
// Refresh expanded trees
298+
sample({
299+
clock: refreshExecutionTree,
300+
source: $expandedTrees,
301+
filter: expandedTrees => expandedTrees.size > 0,
302+
fn: expandedTrees => Array.from(expandedTrees.keys()),
303+
target: fetchMultipleExecutionTreesFx,
304+
})
305+
274306
// Fetch details when selecting an execution
275307
sample({
276308
clock: $selectedExecutionId,

0 commit comments

Comments
 (0)