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) => {
|
export const initialise = (context: StoreContext) => {
|
||||||
const {
|
const {
|
||||||
datasource,
|
datasource,
|
||||||
sort,
|
sort,
|
||||||
filter,
|
filter,
|
||||||
inlineFilters,
|
inlineFilters,
|
||||||
allFilters,
|
|
||||||
nonPlus,
|
nonPlus,
|
||||||
initialFilter,
|
initialFilter,
|
||||||
initialSortColumn,
|
initialSortColumn,
|
||||||
initialSortOrder,
|
initialSortOrder,
|
||||||
fetch,
|
|
||||||
} = context
|
} = context
|
||||||
// Keep a list of subscriptions so that we can clear them when the datasource
|
// Keep a list of subscriptions so that we can clear them when the datasource
|
||||||
// config changes
|
// config changes
|
||||||
|
@ -97,34 +90,5 @@ export const initialise = (context: StoreContext) => {
|
||||||
column: get(initialSortColumn),
|
column: get(initialSortColumn),
|
||||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
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) => {
|
export const initialise = (context: StoreContext) => {
|
||||||
const {
|
const {
|
||||||
datasource,
|
datasource,
|
||||||
fetch,
|
|
||||||
filter,
|
filter,
|
||||||
inlineFilters,
|
inlineFilters,
|
||||||
allFilters,
|
|
||||||
sort,
|
sort,
|
||||||
table,
|
table,
|
||||||
initialFilter,
|
initialFilter,
|
||||||
|
@ -114,34 +112,5 @@ export const initialise = (context: StoreContext) => {
|
||||||
column: get(initialSortColumn),
|
column: get(initialSortColumn),
|
||||||
order: get(initialSortOrder) || SortOrder.ASCENDING,
|
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,
|
rows,
|
||||||
filter,
|
filter,
|
||||||
inlineFilters,
|
inlineFilters,
|
||||||
allFilters,
|
|
||||||
subscribe,
|
subscribe,
|
||||||
viewV2,
|
viewV2,
|
||||||
initialFilter,
|
initialFilter,
|
||||||
initialSortColumn,
|
initialSortColumn,
|
||||||
initialSortOrder,
|
initialSortOrder,
|
||||||
config,
|
config,
|
||||||
fetch,
|
|
||||||
} = context
|
} = context
|
||||||
|
|
||||||
// Keep a list of subscriptions so that we can clear them when the datasource
|
// 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
|
// When hidden we show columns, we need to refresh data in order to fetch
|
||||||
// values for those columns
|
// values for those columns
|
||||||
unsubscribers.push(
|
unsubscribers.push(
|
||||||
|
|
Loading…
Reference in New Issue