-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12190 from Budibase/grid-tweaks
Fix grids not reflecting changes in related table primary display columns
- Loading branch information
Showing
9 changed files
with
100 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/frontend-core/src/components/grid/stores/cache.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export const createActions = context => { | ||
const { API } = context | ||
|
||
// Cache for the primary display columns of different tables. | ||
// If we ever need to cache table definitions for other purposes then we can | ||
// expand this to be a more generic cache. | ||
let primaryDisplayCache = {} | ||
|
||
const resetPrimaryDisplayCache = () => { | ||
primaryDisplayCache = {} | ||
} | ||
|
||
const getPrimaryDisplayForTableId = async tableId => { | ||
// If we've never encountered this tableId before then store a promise that | ||
// resolves to the primary display so that subsequent invocations before the | ||
// promise completes can reuse this promise | ||
if (!primaryDisplayCache[tableId]) { | ||
primaryDisplayCache[tableId] = new Promise(resolve => { | ||
API.fetchTableDefinition(tableId).then(def => { | ||
const display = def?.primaryDisplay || def?.schema?.[0]?.name | ||
primaryDisplayCache[tableId] = display | ||
resolve(display) | ||
}) | ||
}) | ||
} | ||
|
||
// We await the result so that we account for both promises and primitives | ||
return await primaryDisplayCache[tableId] | ||
} | ||
|
||
return { | ||
cache: { | ||
actions: { | ||
getPrimaryDisplayForTableId, | ||
resetPrimaryDisplayCache, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
export const initialise = context => { | ||
const { datasource, cache } = context | ||
|
||
// Wipe the caches whenever the datasource changes to ensure we aren't | ||
// storing any stale information | ||
datasource.subscribe(cache.actions.resetPrimaryDisplayCache) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters