Update grids to work with all datasources
This commit is contained in:
parent
77f87af87f
commit
88c4d0cd20
|
@ -55,6 +55,8 @@ export const deriveStores = context => {
|
||||||
config.canEditRows = false
|
config.canEditRows = false
|
||||||
config.canDeleteRows = false
|
config.canDeleteRows = false
|
||||||
config.canExpandRows = false
|
config.canExpandRows = false
|
||||||
|
config.canSaveSchema = false
|
||||||
|
config.canEditColumns = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -75,21 +75,23 @@ export const createActions = context => {
|
||||||
dispatch,
|
dispatch,
|
||||||
table,
|
table,
|
||||||
viewV2,
|
viewV2,
|
||||||
query,
|
nonPlus,
|
||||||
} = context
|
} = context
|
||||||
|
|
||||||
// Gets the appropriate API for the configured datasource type
|
// Gets the appropriate API for the configured datasource type
|
||||||
const getAPI = () => {
|
const getAPI = () => {
|
||||||
const $datasource = get(datasource)
|
const $datasource = get(datasource)
|
||||||
switch ($datasource?.type) {
|
const type = $datasource?.type
|
||||||
|
if (!type) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
switch (type) {
|
||||||
case "table":
|
case "table":
|
||||||
return table
|
return table
|
||||||
case "viewV2":
|
case "viewV2":
|
||||||
return viewV2
|
return viewV2
|
||||||
case "query":
|
|
||||||
return query
|
|
||||||
default:
|
default:
|
||||||
return null
|
return nonPlus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,32 @@
|
||||||
import { get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
|
|
||||||
export const createActions = context => {
|
export const createActions = context => {
|
||||||
const { API, columns, stickyColumn } = context
|
const { columns, stickyColumn, table, viewV2 } = context
|
||||||
|
|
||||||
const saveDefinition = async newDefinition => {
|
const saveDefinition = async () => {
|
||||||
await API.saveQuery(newDefinition)
|
throw "This datasource does not support updating the definition"
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveRow = async () => {
|
const saveRow = async () => {
|
||||||
throw "Rows cannot be updated through queries"
|
throw "This datasource does not support saving rows"
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteRows = async () => {
|
const deleteRows = async () => {
|
||||||
throw "Rows cannot be deleted through queries"
|
throw "This datasource does not support deleting rows"
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRow = () => {
|
const getRow = () => {
|
||||||
throw "Queries don't support fetching individual rows"
|
throw "This datasource does not support fetching individual rows"
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDatasourceValid = datasource => {
|
const isDatasourceValid = datasource => {
|
||||||
return datasource?.type === "query" && datasource?._id
|
// There are many different types and shapes of datasource, so we only
|
||||||
|
// check that we aren't null
|
||||||
|
return (
|
||||||
|
!table.actions.isDatasourceValid(datasource) &&
|
||||||
|
!viewV2.actions.isDatasourceValid(datasource) &&
|
||||||
|
datasource?.type != null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const canUseColumn = name => {
|
const canUseColumn = name => {
|
||||||
|
@ -30,7 +36,7 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
query: {
|
nonPlus: {
|
||||||
actions: {
|
actions: {
|
||||||
saveDefinition,
|
saveDefinition,
|
||||||
addRow: saveRow,
|
addRow: saveRow,
|
||||||
|
@ -44,18 +50,22 @@ export const createActions = context => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Small util to compare datasource definitions
|
||||||
|
const isSameDatasource = (a, b) => {
|
||||||
|
return JSON.stringify(a) === JSON.stringify(b)
|
||||||
|
}
|
||||||
|
|
||||||
export const initialise = context => {
|
export const initialise = context => {
|
||||||
const {
|
const {
|
||||||
datasource,
|
datasource,
|
||||||
sort,
|
sort,
|
||||||
filter,
|
filter,
|
||||||
query,
|
nonPlus,
|
||||||
initialFilter,
|
initialFilter,
|
||||||
initialSortColumn,
|
initialSortColumn,
|
||||||
initialSortOrder,
|
initialSortOrder,
|
||||||
fetch,
|
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
|
||||||
let unsubscribers = []
|
let unsubscribers = []
|
||||||
|
@ -65,7 +75,7 @@ export const initialise = context => {
|
||||||
// Clear previous subscriptions
|
// Clear previous subscriptions
|
||||||
unsubscribers?.forEach(unsubscribe => unsubscribe())
|
unsubscribers?.forEach(unsubscribe => unsubscribe())
|
||||||
unsubscribers = []
|
unsubscribers = []
|
||||||
if (!query.actions.isDatasourceValid($datasource)) {
|
if (!nonPlus.actions.isDatasourceValid($datasource)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +91,8 @@ export const initialise = context => {
|
||||||
filter.subscribe($filter => {
|
filter.subscribe($filter => {
|
||||||
// Ensure we're updating the correct fetch
|
// Ensure we're updating the correct fetch
|
||||||
const $fetch = get(fetch)
|
const $fetch = get(fetch)
|
||||||
if ($fetch?.options?.datasource?._id !== $datasource._id) {
|
if (!isSameDatasource($fetch?.options?.datasource, $datasource)) {
|
||||||
|
console.log("skip, different ds")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$fetch.update({
|
$fetch.update({
|
||||||
|
@ -95,7 +106,8 @@ export const initialise = context => {
|
||||||
sort.subscribe($sort => {
|
sort.subscribe($sort => {
|
||||||
// Ensure we're updating the correct fetch
|
// Ensure we're updating the correct fetch
|
||||||
const $fetch = get(fetch)
|
const $fetch = get(fetch)
|
||||||
if ($fetch?.options?.datasource?._id !== $datasource._id) {
|
if (!isSameDatasource($fetch?.options?.datasource, $datasource)) {
|
||||||
|
console.log("skip, different ds")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
$fetch.update({
|
$fetch.update({
|
|
@ -15,10 +15,10 @@ import * as Config from "./config"
|
||||||
import * as Sort from "./sort"
|
import * as Sort from "./sort"
|
||||||
import * as Filter from "./filter"
|
import * as Filter from "./filter"
|
||||||
import * as Notifications from "./notifications"
|
import * as Notifications from "./notifications"
|
||||||
import * as Table from "./table"
|
|
||||||
import * as ViewV2 from "./viewV2"
|
|
||||||
import * as Query from "./query"
|
|
||||||
import * as Datasource from "./datasource"
|
import * as Datasource from "./datasource"
|
||||||
|
import * as Table from "./datasources/table"
|
||||||
|
import * as ViewV2 from "./datasources/viewV2"
|
||||||
|
import * as NonPlus from "./datasources/nonPlus"
|
||||||
|
|
||||||
const DependencyOrderedStores = [
|
const DependencyOrderedStores = [
|
||||||
Sort,
|
Sort,
|
||||||
|
@ -27,7 +27,7 @@ const DependencyOrderedStores = [
|
||||||
Scroll,
|
Scroll,
|
||||||
Table,
|
Table,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
Query,
|
NonPlus,
|
||||||
Datasource,
|
Datasource,
|
||||||
Columns,
|
Columns,
|
||||||
Rows,
|
Rows,
|
||||||
|
|
Loading…
Reference in New Issue