Merge pull request #15427 from Budibase/fix/view-v1-on-tables

Fix view v1 on tables
This commit is contained in:
Adria Navarro 2025-01-23 14:51:00 +01:00 committed by GitHub
commit 9ab325596e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 17 deletions

View File

@ -1,5 +1,3 @@
// TODO: datasource and defitions are unions of the different implementations. At this point, the datasource does not know what type is being used, and the assignations will cause TS exceptions. Casting it "as any" for now. This should be fixed improving the type usages.
import { derived, get, Readable, Writable } from "svelte/store" import { derived, get, Readable, Writable } from "svelte/store"
import { import {
DataFetchDefinition, DataFetchDefinition,
@ -10,12 +8,10 @@ import { enrichSchemaWithRelColumns, memo } from "../../../utils"
import { cloneDeep } from "lodash" import { cloneDeep } from "lodash"
import { import {
SaveRowRequest, SaveRowRequest,
SaveTableRequest,
UIDatasource, UIDatasource,
UIFieldMutation, UIFieldMutation,
UIFieldSchema, UIFieldSchema,
UIRow, UIRow,
UpdateViewRequest,
ViewV2Type, ViewV2Type,
} from "@budibase/types" } from "@budibase/types"
import { Store as StoreContext, BaseStoreProps } from "." import { Store as StoreContext, BaseStoreProps } from "."
@ -79,7 +75,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
const schema = derived(definition, $definition => { const schema = derived(definition, $definition => {
const schema: Record<string, any> | undefined = getDatasourceSchema({ const schema: Record<string, any> | undefined = getDatasourceSchema({
API, API,
datasource: get(datasource) as any, // TODO: see line 1 datasource: get(datasource),
definition: $definition ?? undefined, definition: $definition ?? undefined,
}) })
if (!schema) { if (!schema) {
@ -137,7 +133,7 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => {
let type = $datasource?.type let type = $datasource?.type
// @ts-expect-error // @ts-expect-error
if (type === "provider") { if (type === "provider") {
type = ($datasource as any).value?.datasource?.type // TODO: see line 1 type = ($datasource as any).value?.datasource?.type
} }
// Handle calculation views // Handle calculation views
if ( if (
@ -196,15 +192,13 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
const refreshDefinition = async () => { const refreshDefinition = async () => {
const def = await getDatasourceDefinition({ const def = await getDatasourceDefinition({
API, API,
datasource: get(datasource) as any, // TODO: see line 1 datasource: get(datasource),
}) })
definition.set(def as any) // TODO: see line 1 definition.set(def ?? null)
} }
// Saves the datasource definition // Saves the datasource definition
const saveDefinition = async ( const saveDefinition = async (newDefinition: DataFetchDefinition) => {
newDefinition: SaveTableRequest | UpdateViewRequest
) => {
// Update local state // Update local state
const originalDefinition = get(definition) const originalDefinition = get(definition)
definition.set(newDefinition) definition.set(newDefinition)
@ -245,7 +239,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
delete newDefinition.schema[column].default delete newDefinition.schema[column].default
} }
} }
return await saveDefinition(newDefinition as any) // TODO: see line 1 return await saveDefinition(newDefinition)
} }
// Adds a schema mutation for a single field // Adds a schema mutation for a single field
@ -321,7 +315,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
await saveDefinition({ await saveDefinition({
...$definition, ...$definition,
schema: newSchema, schema: newSchema,
} as any) // TODO: see line 1 })
resetSchemaMutations() resetSchemaMutations()
} }

View File

@ -21,7 +21,7 @@ export default class ViewFetch extends BaseDataFetch<ViewV1Datasource, Table> {
getSchema(definition: Table) { getSchema(definition: Table) {
const { datasource } = this.options const { datasource } = this.options
return definition?.views?.[datasource.name]?.schema return definition?.views?.[datasource?.name]?.schema
} }
async getData() { async getData() {

View File

@ -101,12 +101,12 @@ export const fetchData = <
// Creates an empty fetch instance with no datasource configured, so no data // Creates an empty fetch instance with no datasource configured, so no data
// will initially be loaded // will initially be loaded
const createEmptyFetchInstance = ({ const createEmptyFetchInstance = <T extends DataFetchDatasource>({
API, API,
datasource, datasource,
}: { }: {
API: APIClient API: APIClient
datasource: DataFetchDatasource datasource: T
}) => { }) => {
const handler = DataFetchMap[datasource?.type] const handler = DataFetchMap[datasource?.type]
if (!handler) { if (!handler) {
@ -114,7 +114,7 @@ const createEmptyFetchInstance = ({
} }
return new handler({ return new handler({
API, API,
datasource: null as never, datasource: datasource as any,
query: null as any, query: null as any,
}) })
} }