Handle missing required columns in views by showing errors
This commit is contained in:
parent
df676bbe9e
commit
4192618bdf
|
@ -71,13 +71,6 @@ export const deriveStores = context => {
|
||||||
export const createActions = context => {
|
export const createActions = context => {
|
||||||
const { columns, stickyColumn, datasource, definition } = context
|
const { columns, stickyColumn, datasource, definition } = context
|
||||||
|
|
||||||
// Checks if we have a certain column by name
|
|
||||||
const hasColumn = column => {
|
|
||||||
const $columns = get(columns)
|
|
||||||
const $sticky = get(stickyColumn)
|
|
||||||
return $columns.some(col => col.name === column) || $sticky?.name === column
|
|
||||||
}
|
|
||||||
|
|
||||||
// Updates the datasources primary display column
|
// Updates the datasources primary display column
|
||||||
const changePrimaryDisplay = async column => {
|
const changePrimaryDisplay = async column => {
|
||||||
return await datasource.actions.saveDefinition({
|
return await datasource.actions.saveDefinition({
|
||||||
|
@ -140,7 +133,6 @@ export const createActions = context => {
|
||||||
columns: {
|
columns: {
|
||||||
...columns,
|
...columns,
|
||||||
actions: {
|
actions: {
|
||||||
hasColumn,
|
|
||||||
saveChanges,
|
saveChanges,
|
||||||
changePrimaryDisplay,
|
changePrimaryDisplay,
|
||||||
changeAllColumnWidths,
|
changeAllColumnWidths,
|
||||||
|
|
|
@ -108,6 +108,11 @@ export const createActions = context => {
|
||||||
return getAPI()?.actions.isDatasourceValid(datasource)
|
return getAPI()?.actions.isDatasourceValid(datasource)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if this datasource can use a specific column by name
|
||||||
|
const canUseColumn = name => {
|
||||||
|
return getAPI()?.actions.canUseColumn(name)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
datasource: {
|
datasource: {
|
||||||
...datasource,
|
...datasource,
|
||||||
|
@ -119,6 +124,7 @@ export const createActions = context => {
|
||||||
deleteRows,
|
deleteRows,
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
|
canUseColumn,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ export const createActions = context => {
|
||||||
let erroredColumns = []
|
let erroredColumns = []
|
||||||
let missingColumns = []
|
let missingColumns = []
|
||||||
for (let column of keys) {
|
for (let column of keys) {
|
||||||
if (columns.actions.hasColumn(column)) {
|
if (datasource.actions.canUseColumn(column)) {
|
||||||
erroredColumns.push(column)
|
erroredColumns.push(column)
|
||||||
} else {
|
} else {
|
||||||
missingColumns.push(column)
|
missingColumns.push(column)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { get } from "svelte/store"
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
export const createActions = context => {
|
export const createActions = context => {
|
||||||
const { definition, API, datasource } = context
|
const { definition, API, datasource, columns, stickyColumn } = context
|
||||||
|
|
||||||
const refreshDefinition = async () => {
|
const refreshDefinition = async () => {
|
||||||
definition.set(await API.fetchTableDefinition(get(datasource).tableId))
|
definition.set(await API.fetchTableDefinition(get(datasource).tableId))
|
||||||
|
@ -43,6 +43,12 @@ export const createActions = context => {
|
||||||
return res?.rows?.[0]
|
return res?.rows?.[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const canUseColumn = name => {
|
||||||
|
const $columns = get(columns)
|
||||||
|
const $sticky = get(stickyColumn)
|
||||||
|
return $columns.some(col => col.name === name) || $sticky?.name === name
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
table: {
|
table: {
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -53,6 +59,7 @@ export const createActions = context => {
|
||||||
deleteRows,
|
deleteRows,
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
|
canUseColumn,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { get } from "svelte/store"
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
export const createActions = context => {
|
export const createActions = context => {
|
||||||
const { definition, API, datasource } = context
|
const { definition, API, datasource, columns, stickyColumn } = context
|
||||||
|
|
||||||
const refreshDefinition = async () => {
|
const refreshDefinition = async () => {
|
||||||
const $datasource = get(datasource)
|
const $datasource = get(datasource)
|
||||||
|
@ -53,6 +53,15 @@ export const createActions = context => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const canUseColumn = name => {
|
||||||
|
const $columns = get(columns)
|
||||||
|
const $sticky = get(stickyColumn)
|
||||||
|
return (
|
||||||
|
$columns.some(col => col.name === name && col.visible) ||
|
||||||
|
$sticky?.name === name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
viewV2: {
|
viewV2: {
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -63,6 +72,7 @@ export const createActions = context => {
|
||||||
deleteRows,
|
deleteRows,
|
||||||
getRow,
|
getRow,
|
||||||
isDatasourceValid,
|
isDatasourceValid,
|
||||||
|
canUseColumn,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue