This commit is contained in:
Adria Navarro 2024-10-03 10:28:29 +02:00
parent 7c778061e5
commit 1b53bab92e
4 changed files with 28 additions and 24 deletions

View File

@ -34,7 +34,7 @@ import {
Table, Table,
TableSchema, TableSchema,
User, User,
ViewFieldMetadata, ViewV2Schema,
} from "@budibase/types" } from "@budibase/types"
import _ from "lodash" import _ from "lodash"
import tk from "timekeeper" import tk from "timekeeper"
@ -139,6 +139,15 @@ describe.each([
return table._id! return table._id!
} }
async function createView(tableId: string, schema: ViewV2Schema) {
const view = await config.api.viewV2.create({
tableId: tableId,
name: generator.guid(),
schema,
})
return view
}
async function createRows(arr: Record<string, any>[]) { async function createRows(arr: Record<string, any>[]) {
// Shuffling to avoid false positives given a fixed order // Shuffling to avoid false positives given a fixed order
for (const row of _.shuffle(arr)) { for (const row of _.shuffle(arr)) {
@ -153,21 +162,17 @@ describe.each([
"view", "view",
async (schema: TableSchema) => { async (schema: TableSchema) => {
const tableId = await createTable(schema) const tableId = await createTable(schema)
const view = await config.api.viewV2.create({ const view = await createView(
tableId: tableId, tableId,
name: generator.guid(), Object.keys(schema).reduce<ViewV2Schema>((viewSchema, fieldName) => {
schema: Object.keys(schema).reduce<Record<string, ViewFieldMetadata>>( const field = schema[fieldName]
(viewSchema, fieldName) => { viewSchema[fieldName] = {
const field = schema[fieldName] visible: field.visible ?? true,
viewSchema[fieldName] = { readonly: false,
visible: field.visible ?? true, }
readonly: false, return viewSchema
} }, {})
return viewSchema )
},
{}
),
})
return view.id return view.id
}, },
], ],

View File

@ -22,9 +22,9 @@ import {
RelationshipType, RelationshipType,
TableSchema, TableSchema,
RenameColumn, RenameColumn,
ViewFieldMetadata,
FeatureFlag, FeatureFlag,
BBReferenceFieldSubType, BBReferenceFieldSubType,
ViewV2Schema,
} from "@budibase/types" } from "@budibase/types"
import { generator, mocks } from "@budibase/backend-core/tests" import { generator, mocks } from "@budibase/backend-core/tests"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils" import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
@ -1152,10 +1152,7 @@ describe.each([
return table return table
} }
const createView = async ( const createView = async (tableId: string, schema: ViewV2Schema) =>
tableId: string,
schema: Record<string, ViewFieldMetadata>
) =>
await config.api.viewV2.create({ await config.api.viewV2.create({
name: generator.guid(), name: generator.guid(),
tableId, tableId,

View File

@ -23,8 +23,8 @@ import {
Row, Row,
Table, Table,
TableSchema, TableSchema,
ViewFieldMetadata,
ViewV2, ViewV2,
ViewV2Schema,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../sdk" import sdk from "../../sdk"
import { helpers } from "@budibase/shared-core" import { helpers } from "@budibase/shared-core"
@ -262,7 +262,7 @@ export async function squashLinks<T = Row[] | Row>(
FeatureFlag.ENRICHED_RELATIONSHIPS FeatureFlag.ENRICHED_RELATIONSHIPS
) )
let viewSchema: Record<string, ViewFieldMetadata> = {} let viewSchema: ViewV2Schema = {}
if (sdk.views.isView(source)) { if (sdk.views.isView(source)) {
if (helpers.views.isCalculationView(source)) { if (helpers.views.isCalculationView(source)) {
return enriched return enriched

View File

@ -71,9 +71,11 @@ export interface ViewV2 {
order?: SortOrder order?: SortOrder
type?: SortType type?: SortType
} }
schema?: Record<string, ViewFieldMetadata> schema?: ViewV2Schema
} }
export type ViewV2Schema = Record<string, ViewFieldMetadata>
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema
export interface ViewCountOrSumSchema { export interface ViewCountOrSumSchema {