diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index d5017aa8d1..61caa79734 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -98,10 +98,16 @@ export const createActions = context => { return await getAPI()?.actions.deleteRows(rows) } + // Gets a single row from a datasource const getRow = async id => { return await getAPI()?.actions.getRow(id) } + // Checks if a certain datasource config is valid + const isDatasourceValid = datasource => { + return getAPI()?.actions.isDatasourceValid(datasource) + } + return { datasource: { ...datasource, @@ -112,6 +118,7 @@ export const createActions = context => { updateRow, deleteRows, getRow, + isDatasourceValid, }, }, } diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.js index d876b5f8df..df881eefdd 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.js @@ -98,7 +98,7 @@ export const createActions = context => { loading.set(true) // Abandon if we don't have a valid datasource - if (!$datasource) { + if (!datasource.actions.isDatasourceValid($datasource)) { return } diff --git a/packages/frontend-core/src/components/grid/stores/table.js b/packages/frontend-core/src/components/grid/stores/table.js index 5c3d2c9ef2..bf4eebcda4 100644 --- a/packages/frontend-core/src/components/grid/stores/table.js +++ b/packages/frontend-core/src/components/grid/stores/table.js @@ -25,6 +25,10 @@ export const createActions = context => { }) } + const isDatasourceValid = datasource => { + return datasource?.type === "table" && datasource?.tableId + } + const getRow = async id => { const res = await API.searchTable({ tableId: get(datasource).tableId, @@ -48,6 +52,7 @@ export const createActions = context => { updateRow: saveRow, deleteRows, getRow, + isDatasourceValid, }, }, } diff --git a/packages/frontend-core/src/components/grid/stores/viewV2.js b/packages/frontend-core/src/components/grid/stores/viewV2.js index b2d80acd1a..31ccba8c76 100644 --- a/packages/frontend-core/src/components/grid/stores/viewV2.js +++ b/packages/frontend-core/src/components/grid/stores/viewV2.js @@ -60,6 +60,12 @@ export const createActions = context => { return res?.rows?.[0] } + const isDatasourceValid = datasource => { + return ( + datasource?.type === "viewV2" && datasource?.id && datasource?.tableId + ) + } + return { viewV2: { actions: { @@ -69,6 +75,7 @@ export const createActions = context => { updateRow, deleteRows, getRow, + isDatasourceValid, }, }, }