Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 3a7eb89

Browse files
author
aegorov
committed
keep bc cursors after view change
1 parent 8090ced commit 3a7eb89

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

src/actions/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ export class ActionPayloadTypes {
585585
bcChangeCursors: {
586586
cursorsMap: Record<string, string>
587587
keepDelta?: boolean
588+
resetChildren?: boolean
588589
} = z
589590

590591
/**

src/epics/data.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ export const bcSelectRecord: Epic = (action$, store) =>
9292
keepDelta: action.payload.keepDelta
9393
})
9494
})
95+
9596
return Observable.concat(
96-
Observable.of($do.bcChangeCursors({ cursorsMap: { [bcName]: cursor }, keepDelta: action.payload.keepDelta })),
97+
Observable.of(
98+
$do.bcChangeCursors({ cursorsMap: { [bcName]: cursor }, keepDelta: action.payload.keepDelta, resetChildren: true })
99+
),
97100
Observable.of($do.bcFetchRowMeta({ widgetName: '', bcName })),
98101
fetchChildrenBcData
99102
)

src/epics/data/bcFetchData.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ function getCursorChange(data: DataItem[], action: ActionType, prevCursor: strin
213213
const { bcName } = action.payload
214214
const { keepDelta } = (action as ActionsMap[typeof types.bcFetchDataRequest]).payload
215215
const newCursor = data[0]?.id
216+
const prevCursorData = data.some(i => i.id === prevCursor)
216217
const changeCurrentCursor = Observable.of<AnyAction>(
217218
$do.bcChangeCursors({
218219
cursorsMap: {
219-
[bcName]: data.some(i => i.id === prevCursor) ? prevCursor : newCursor
220+
[bcName]: prevCursorData ? prevCursor : newCursor
220221
},
221-
keepDelta: isHierarchy || keepDelta
222+
keepDelta: isHierarchy || keepDelta,
223+
resetChildren: !prevCursorData
222224
})
223225
)
224226
return changeCurrentCursor

src/reducers/screen.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function screen(state = initialState, action: AnyAction, store: Store): S
9595
)
9696
.filter(bcName => state.bo.bc[bcName])
9797
.forEach(bcName => {
98-
newBcs[bcName] = { ...state.bo.bc[bcName], page: 1 }
98+
newBcs[bcName] = { ...state.bo.bc[bcName] }
9999
})
100100
return {
101101
...state,
@@ -210,19 +210,21 @@ export function screen(state = initialState, action: AnyAction, store: Store): S
210210
case types.bcChangeCursors: {
211211
const newCursors: Record<string, BcMetaState> = {}
212212
const newCache: Record<string, string> = {}
213+
const { resetChildren } = action.payload
213214
Object.entries(action.payload.cursorsMap).forEach(entry => {
214215
const [bcName, cursor] = entry
215216
newCursors[bcName] = { ...state.bo.bc[bcName], cursor }
216217
newCache[bcName] = cursor
217218
})
218219
// Also reset cursors of all children of requested BCs
219220
const changedParents = Object.values(newCursors).map(bc => `${bc.url}/:id`)
220-
Object.values(state.bo.bc).forEach(bc => {
221-
if (changedParents.some(item => bc.url.includes(item))) {
222-
newCursors[bc.name] = { ...state.bo.bc[bc.name], cursor: null }
223-
newCache[bc.name] = null
224-
}
225-
})
221+
resetChildren &&
222+
Object.values(state.bo.bc).forEach(bc => {
223+
if (changedParents.some(item => bc.url.includes(item))) {
224+
newCursors[bc.name] = { ...state.bo.bc[bc.name], cursor: null, page: 1 }
225+
newCache[bc.name] = null
226+
}
227+
})
226228
return {
227229
...state,
228230
bo: {

0 commit comments

Comments
 (0)