Skip to content

Commit 9c7e1d6

Browse files
authored
Merge pull request #138 from badaitech/fix/global-reset
global reset event
2 parents a51d873 + c3aeddd commit 9c7e1d6

23 files changed

Lines changed: 114 additions & 24 deletions

File tree

apps/chaingraph-backend/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# @badaitech/chaingraph-backend
22

3+
## 0.1.20
4+
5+
### Patch Changes
6+
7+
- Bump version
8+
- Updated dependencies
9+
- @badaitech/chaingraph-nodes@0.1.20
10+
- @badaitech/chaingraph-trpc@0.1.20
11+
- @badaitech/chaingraph-types@0.1.20
12+
313
## 0.1.19
414

515
### Patch Changes

apps/chaingraph-backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@badaitech/chaingraph-backend",
33
"type": "module",
4-
"version": "0.1.19",
4+
"version": "0.1.20",
55
"private": false,
66
"description": "Backend server for the Chaingraph project",
77
"license": "BUSL-1.1",

apps/chaingraph-frontend/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# @badaitech/chaingraph-frontend
22

3+
## 0.1.20
4+
5+
### Patch Changes
6+
7+
- Bump version
8+
- Updated dependencies
9+
- @badaitech/chaingraph-nodes@0.1.20
10+
- @badaitech/chaingraph-trpc@0.1.20
11+
- @badaitech/chaingraph-types@0.1.20
12+
313
## 0.1.19
414

515
### Patch Changes

apps/chaingraph-frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@badaitech/chaingraph-frontend",
33
"type": "module",
4-
"version": "0.1.19",
4+
"version": "0.1.20",
55
"private": false,
66
"description": "Frontend application for the Chaingraph project",
77
"license": "BUSL-1.1",

apps/chaingraph-frontend/src/providers/RootProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ export function RootProvider({
9696
}
9797

9898
return () => {
99-
reset()
99+
if (isInitializedRef.current)
100+
reset()
100101
}
101102
}, [nodeRegistry, sessionToken, superjsonCustom, trpcURL])
102103

apps/chaingraph-frontend/src/store/categories/stores.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { CategorizedNodes, CategoryMetadata } from '@badaitech/chaingraph-t
1010
import type { FetchCategoriesError } from './types'
1111
import { NODE_CATEGORIES } from '@badaitech/chaingraph-nodes'
1212
import { combine } from 'effector'
13+
import { globalReset } from '../common'
1314
import { categoriesDomain } from '../domains'
1415
import { $trpcClient } from '../trpc/store'
1516

@@ -29,6 +30,7 @@ export const fetchCategorizedNodesFx = categoriesDomain.createEffect(() => {
2930
const $categorizedNodes = categoriesDomain.createStore<CategorizedNodes[]>([])
3031
.on(fetchCategorizedNodesFx.doneData, (_, nodes) => nodes)
3132
.reset(resetCategories)
33+
.reset(globalReset)
3234

3335
export const $categoryMetadata = categoriesDomain.createStore<Map<string, CategoryMetadata>>(new Map())
3436
.on(fetchCategorizedNodesFx.doneData, (_, nodes) => {
@@ -39,6 +41,7 @@ export const $categoryMetadata = categoriesDomain.createStore<Map<string, Catego
3941
return map
4042
})
4143
.reset(resetCategories)
44+
.reset(globalReset)
4245

4346
const $isLoading = fetchCategorizedNodesFx.pending
4447

@@ -48,6 +51,7 @@ const $error = categoriesDomain.createStore<FetchCategoriesError | null>(null)
4851
timestamp: new Date(),
4952
}))
5053
.reset(fetchCategorizedNodesFx.doneData)
54+
.reset(globalReset)
5155

5256
// Computed stores
5357
export const $categoriesState = combine({
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2025 BadLabs
3+
*
4+
* Use of this software is governed by the Business Source License 1.1 included in the file LICENSE.txt.
5+
*
6+
* As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0.
7+
*/
8+
9+
import { createEvent } from 'effector'
10+
11+
export const globalReset = createEvent()

apps/chaingraph-frontend/src/store/edges/stores.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { Edge } from '@xyflow/react'
1111
import type { AddEdgeEventData, EdgeData, RemoveEdgeEventData } from './types'
1212
import { edgesDomain } from '@/store/domains'
1313
import { attach, combine, sample } from 'effector'
14+
import { globalReset } from '../common'
1415
import { $executionNodes, $executionState, $highlightedEdgeId, $highlightedNodeId } from '../execution'
1516
import { $xyflowNodes } from '../nodes'
1617
import { $trpcClient } from '../trpc/store'
@@ -71,6 +72,7 @@ export const $edges = edgesDomain.createStore<EdgeData[]>([])
7172
edge => edge.edgeId !== event.edgeId,
7273
))
7374
.reset(resetEdges)
75+
.reset(globalReset)
7476
// .reset(clearActiveFlow)
7577

7678
/**

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
} from './types'
1818
import { ExecutionEventEnum } from '@badaitech/chaingraph-types'
1919
import { attach, combine, sample } from 'effector'
20+
import { globalReset } from '../common'
2021
import { executionDomain } from '../domains'
2122
import { $trpcClient } from '../trpc/store'
2223
import { ExecutionStatus, ExecutionSubscriptionStatus, isTerminalStatus } from './types'
@@ -67,7 +68,7 @@ const initialState: ExecutionState = {
6768
},
6869
}
6970

70-
export const $executionState = executionDomain.createStore<ExecutionState>(initialState)
71+
export const $executionState = executionDomain.createStore<ExecutionState>(initialState).reset(globalReset)
7172

7273
// Control effects
7374
export const createExecutionFx = executionDomain.createEffect(async (payload: CreateExecutionOptions) => {
@@ -185,6 +186,7 @@ export const $executionEvents = executionDomain.createStore<ExecutionEventImpl[]
185186
.reset(clearExecutionState)
186187
.reset(stopExecutionFx.done)
187188
.reset(createExecutionFx.doneData)
189+
.reset(globalReset)
188190

189191
export const $executionNodes = executionDomain.createStore<Record<string, NodeExecutionState>>({}, {
190192
updateFilter: (prev, next) => {
@@ -307,6 +309,7 @@ export const $executionNodes = executionDomain.createStore<Record<string, NodeEx
307309
.reset(clearExecutionState)
308310
.reset(stopExecutionFx.done)
309311
.reset(createExecutionFx.doneData)
312+
.reset(globalReset)
310313

311314
export const $executionEdges = executionDomain.createStore<Record<string, EdgeExecutionState>>({})
312315
.on(newExecutionEvent, (state, event) => {
@@ -365,6 +368,7 @@ export const $executionEdges = executionDomain.createStore<Record<string, EdgeEx
365368
.reset(clearExecutionState)
366369
.reset(stopExecutionFx.done)
367370
.reset(createExecutionFx.doneData)
371+
.reset(globalReset)
368372

369373
// Handle execution status changes
370374
$executionState
@@ -521,12 +525,14 @@ export const $highlightedNodeId = executionDomain.createStore<string[] | null>(n
521525
typeof highlightedNodeId === 'string'
522526
? [highlightedNodeId]
523527
: highlightedNodeId)
528+
.reset(globalReset)
524529

525530
export const $highlightedEdgeId = executionDomain.createStore<string[] | null>(null)
526531
.on(setHighlightedEdgeId, (state, highlightedEdgeId) =>
527532
typeof highlightedEdgeId === 'string'
528533
? [highlightedEdgeId]
529534
: highlightedEdgeId)
535+
.reset(globalReset)
530536

531537
// Computed stores
532538
export const $isExecuting = $executionState.map(
@@ -578,7 +584,7 @@ export const $autoStartConditions = combine({
578584
})
579585

580586
// Store to prevent multiple start attempts
581-
export const $startAttempted = executionDomain.createStore(false)
587+
export const $startAttempted = executionDomain.createStore(false).reset(globalReset)
582588

583589
// export const $highlightedNodeId = $executionState.map(state => state.ui.highlightedNodeId)
584590
// export const $highlightedEdgeId = $executionState.map(state => state.ui.highlightedEdgeId)

apps/chaingraph-frontend/src/store/flow/stores.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { FlowMetadata } from '@badaitech/chaingraph-types'
1010
import type { CreateFlowEvent, FlowSubscriptionError, UpdateFlowEvent } from './types'
1111
import { flowDomain } from '@/store/domains'
1212
import { combine, sample } from 'effector'
13+
import { globalReset } from '../common'
1314
import { $trpcClient } from '../trpc/store'
1415
import { FlowSubscriptionStatus } from './types'
1516

@@ -118,45 +119,55 @@ export const $flows = flowDomain.createStore<FlowMetadata[]>([])
118119
})
119120
.on(deleteFlow, (flows, id) =>
120121
flows.filter(f => f.id !== id))
122+
.reset(globalReset)
121123

122124
// Currently active flow ID
123125
export const $activeFlowId = flowDomain.createStore<string | null>(null)
124126
.on(setActiveFlowId, (_, id) => id)
125127
.reset(clearActiveFlow)
128+
.reset(globalReset)
126129

127130
// Main loading state
128131
export const $isFlowsLoading = flowDomain.createStore<boolean>(false)
129132
.on(setFlowsLoading, (_, isLoading) => isLoading)
130133
.on(loadFlowsListFx.pending, (_, isPending) => isPending)
134+
.reset(globalReset)
131135

132136
// Main error state
133137
export const $flowsError = flowDomain.createStore<Error | null>(null)
134138
.on(setFlowsError, (_, error) => error)
135139
.on(loadFlowsListFx.failData, (_, error) => error)
136140
.reset(loadFlowsListFx.done)
141+
.reset(globalReset)
137142

138143
// Specific operation error stores
139144
export const $createFlowError = flowDomain.createStore<Error | null>(null)
140145
.on(createFlowFx.failData, (_, error) => error)
141146
.reset(createFlowFx.done)
147+
.reset(globalReset)
142148

143149
export const $updateFlowError = flowDomain.createStore<Error | null>(null)
144150
.on(editFlowFx.failData, (_, error) => error)
145151
.reset(editFlowFx.done)
152+
.reset(globalReset)
146153

147154
export const $deleteFlowError = flowDomain.createStore<Error | null>(null)
148155
.on(deleteFlowFx.failData, (_, error) => error)
149156
.reset(deleteFlowFx.done)
157+
.reset(globalReset)
150158

151159
// Specific operation loading states
152160
export const $isCreatingFlow = flowDomain.createStore<boolean>(false)
153161
.on(createFlowFx.pending, (_, isPending) => isPending)
162+
.reset(globalReset)
154163

155164
export const $isUpdatingFlow = flowDomain.createStore<boolean>(false)
156165
.on(editFlowFx.pending, (_, isPending) => isPending)
166+
.reset(globalReset)
157167

158168
export const $isDeletingFlow = flowDomain.createStore<boolean>(false)
159169
.on(deleteFlowFx.pending, (_, isPending) => isPending)
170+
.reset(globalReset)
160171

161172
// Combined error store
162173
export const $allFlowsErrors = combine(
@@ -180,9 +191,13 @@ export const $activeFlowMetadata = combine(
180191
// Subscription related stores
181192
export const $flowSubscriptionStatus = flowDomain.createStore<FlowSubscriptionStatus>(
182193
FlowSubscriptionStatus.IDLE,
183-
).on(setFlowSubscriptionStatus, (_, status) => status).reset(resetFlowSubscription).reset(clearActiveFlow)
194+
).on(setFlowSubscriptionStatus, (_, status) => status).reset(resetFlowSubscription).reset(clearActiveFlow).reset(globalReset)
184195

185-
export const $flowSubscriptionError = flowDomain.createStore<FlowSubscriptionError | null>(null).on(setFlowSubscriptionError, (_, error) => error).reset(resetFlowSubscription).reset(clearActiveFlow)
196+
export const $flowSubscriptionError = flowDomain.createStore<FlowSubscriptionError | null>(null)
197+
.on(setFlowSubscriptionError, (_, error) => error)
198+
.reset(resetFlowSubscription)
199+
.reset(clearActiveFlow)
200+
.reset(globalReset)
186201

187202
// Derived store to check if subscription is active
188203
export const $isFlowSubscribed = $flowSubscriptionStatus.map(

0 commit comments

Comments
 (0)