Fix wrong store usage
This commit is contained in:
parent
c1c95a6073
commit
899c1e8d5f
|
@ -59,23 +59,16 @@ export const createActions = (context: StoreContext): NonPlusActions => {
|
|||
}
|
||||
}
|
||||
|
||||
// Small util to compare datasource definitions
|
||||
const isSameDatasource = (a: any, b: any) => {
|
||||
return JSON.stringify(a) === JSON.stringify(b)
|
||||
}
|
||||
|
||||
export const initialise = (context: StoreContext) => {
|
||||
const {
|
||||
datasource,
|
||||
sort,
|
||||
filter,
|
||||
inlineFilters,
|
||||
allFilters,
|
||||
nonPlus,
|
||||
initialFilter,
|
||||
initialSortColumn,
|
||||
initialSortOrder,
|
||||
fetch,
|
||||
} = context
|
||||
// Keep a list of subscriptions so that we can clear them when the datasource
|
||||
// config changes
|
||||
|
@ -97,34 +90,5 @@ export const initialise = (context: StoreContext) => {
|
|||
column: get(initialSortColumn),
|
||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
||||
})
|
||||
|
||||
// Update fetch when filter changes
|
||||
unsubscribers.push(
|
||||
allFilters.subscribe($allFilters => {
|
||||
// Ensure we're updating the correct fetch
|
||||
const $fetch = get(fetch)
|
||||
if (!isSameDatasource($fetch?.options?.datasource, $datasource)) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
filter: $allFilters,
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// Update fetch when sorting changes
|
||||
unsubscribers.push(
|
||||
sort.subscribe($sort => {
|
||||
// Ensure we're updating the correct fetch
|
||||
const $fetch = get(fetch)
|
||||
if (!isSameDatasource($fetch?.options?.datasource, $datasource)) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
sortOrder: $sort.order || SortOrder.ASCENDING,
|
||||
sortColumn: $sort.column,
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -83,10 +83,8 @@ export const createActions = (context: StoreContext): TableActions => {
|
|||
export const initialise = (context: StoreContext) => {
|
||||
const {
|
||||
datasource,
|
||||
fetch,
|
||||
filter,
|
||||
inlineFilters,
|
||||
allFilters,
|
||||
sort,
|
||||
table,
|
||||
initialFilter,
|
||||
|
@ -114,34 +112,5 @@ export const initialise = (context: StoreContext) => {
|
|||
column: get(initialSortColumn),
|
||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
||||
})
|
||||
|
||||
// Update fetch when filter changes
|
||||
unsubscribers.push(
|
||||
allFilters.subscribe($allFilters => {
|
||||
// Ensure we're updating the correct fetch
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?.tableId !== $datasource.tableId) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
filter: $allFilters,
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// Update fetch when sorting changes
|
||||
unsubscribers.push(
|
||||
sort.subscribe($sort => {
|
||||
// Ensure we're updating the correct fetch
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?.tableId !== $datasource.tableId) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
sortOrder: $sort.order || SortOrder.ASCENDING,
|
||||
sortColumn: $sort.column,
|
||||
})
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -97,14 +97,12 @@ export const initialise = (context: StoreContext) => {
|
|||
rows,
|
||||
filter,
|
||||
inlineFilters,
|
||||
allFilters,
|
||||
subscribe,
|
||||
viewV2,
|
||||
initialFilter,
|
||||
initialSortColumn,
|
||||
initialSortOrder,
|
||||
config,
|
||||
fetch,
|
||||
} = context
|
||||
|
||||
// Keep a list of subscriptions so that we can clear them when the datasource
|
||||
|
@ -178,17 +176,6 @@ export const initialise = (context: StoreContext) => {
|
|||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Also update the fetch to ensure the new sort is respected.
|
||||
// Ensure we're updating the correct fetch.
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?.id !== $datasource.id) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
sortOrder: $sort.order,
|
||||
sortColumn: $sort.column,
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -214,38 +201,6 @@ export const initialise = (context: StoreContext) => {
|
|||
})
|
||||
)
|
||||
|
||||
// Keep fetch up to date with inline filters when in the data section
|
||||
unsubscribers.push(
|
||||
inlineFilters.subscribe($inlineFilters => {
|
||||
if (!get(config).canSaveSchema) {
|
||||
return
|
||||
}
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?.id !== $datasource.id) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
filter: $inlineFilters,
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// Keep fetch up to date with all filters when not in the data section
|
||||
unsubscribers.push(
|
||||
allFilters.subscribe($allFilters => {
|
||||
if (get(config).canSaveSchema) {
|
||||
return
|
||||
}
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?.id !== $datasource.id) {
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
filter: $allFilters,
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
// When hidden we show columns, we need to refresh data in order to fetch
|
||||
// values for those columns
|
||||
unsubscribers.push(
|
||||
|
|
Loading…
Reference in New Issue