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.canDeleteRows = false
|
||||
config.canExpandRows = false
|
||||
config.canSaveSchema = false
|
||||
config.canEditColumns = false
|
||||
}
|
||||
|
||||
return config
|
||||
|
|
|
@ -75,21 +75,23 @@ export const createActions = context => {
|
|||
dispatch,
|
||||
table,
|
||||
viewV2,
|
||||
query,
|
||||
nonPlus,
|
||||
} = context
|
||||
|
||||
// Gets the appropriate API for the configured datasource type
|
||||
const getAPI = () => {
|
||||
const $datasource = get(datasource)
|
||||
switch ($datasource?.type) {
|
||||
const type = $datasource?.type
|
||||
if (!type) {
|
||||
return null
|
||||
}
|
||||
switch (type) {
|
||||
case "table":
|
||||
return table
|
||||
case "viewV2":
|
||||
return viewV2
|
||||
case "query":
|
||||
return query
|
||||
default:
|
||||
return null
|
||||
return nonPlus
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,32 @@
|
|||
import { get } from "svelte/store"
|
||||
|
||||
export const createActions = context => {
|
||||
const { API, columns, stickyColumn } = context
|
||||
const { columns, stickyColumn, table, viewV2 } = context
|
||||
|
||||
const saveDefinition = async newDefinition => {
|
||||
await API.saveQuery(newDefinition)
|
||||
const saveDefinition = async () => {
|
||||
throw "This datasource does not support updating the definition"
|
||||
}
|
||||
|
||||
const saveRow = async () => {
|
||||
throw "Rows cannot be updated through queries"
|
||||
throw "This datasource does not support saving rows"
|
||||
}
|
||||
|
||||
const deleteRows = async () => {
|
||||
throw "Rows cannot be deleted through queries"
|
||||
throw "This datasource does not support deleting rows"
|
||||
}
|
||||
|
||||
const getRow = () => {
|
||||
throw "Queries don't support fetching individual rows"
|
||||
throw "This datasource does not support fetching individual rows"
|
||||
}
|
||||
|
||||
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 => {
|
||||
|
@ -30,7 +36,7 @@ export const createActions = context => {
|
|||
}
|
||||
|
||||
return {
|
||||
query: {
|
||||
nonPlus: {
|
||||
actions: {
|
||||
saveDefinition,
|
||||
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 => {
|
||||
const {
|
||||
datasource,
|
||||
sort,
|
||||
filter,
|
||||
query,
|
||||
nonPlus,
|
||||
initialFilter,
|
||||
initialSortColumn,
|
||||
initialSortOrder,
|
||||
fetch,
|
||||
} = context
|
||||
|
||||
// Keep a list of subscriptions so that we can clear them when the datasource
|
||||
// config changes
|
||||
let unsubscribers = []
|
||||
|
@ -65,7 +75,7 @@ export const initialise = context => {
|
|||
// Clear previous subscriptions
|
||||
unsubscribers?.forEach(unsubscribe => unsubscribe())
|
||||
unsubscribers = []
|
||||
if (!query.actions.isDatasourceValid($datasource)) {
|
||||
if (!nonPlus.actions.isDatasourceValid($datasource)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -81,7 +91,8 @@ export const initialise = context => {
|
|||
filter.subscribe($filter => {
|
||||
// Ensure we're updating the correct fetch
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?._id !== $datasource._id) {
|
||||
if (!isSameDatasource($fetch?.options?.datasource, $datasource)) {
|
||||
console.log("skip, different ds")
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
||||
|
@ -95,7 +106,8 @@ export const initialise = context => {
|
|||
sort.subscribe($sort => {
|
||||
// Ensure we're updating the correct fetch
|
||||
const $fetch = get(fetch)
|
||||
if ($fetch?.options?.datasource?._id !== $datasource._id) {
|
||||
if (!isSameDatasource($fetch?.options?.datasource, $datasource)) {
|
||||
console.log("skip, different ds")
|
||||
return
|
||||
}
|
||||
$fetch.update({
|
|
@ -15,10 +15,10 @@ import * as Config from "./config"
|
|||
import * as Sort from "./sort"
|
||||
import * as Filter from "./filter"
|
||||
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 Table from "./datasources/table"
|
||||
import * as ViewV2 from "./datasources/viewV2"
|
||||
import * as NonPlus from "./datasources/nonPlus"
|
||||
|
||||
const DependencyOrderedStores = [
|
||||
Sort,
|
||||
|
@ -27,7 +27,7 @@ const DependencyOrderedStores = [
|
|||
Scroll,
|
||||
Table,
|
||||
ViewV2,
|
||||
Query,
|
||||
NonPlus,
|
||||
Datasource,
|
||||
Columns,
|
||||
Rows,
|
||||
|
|
Loading…
Reference in New Issue