Extract
This commit is contained in:
parent
7c778061e5
commit
1b53bab92e
|
@ -34,7 +34,7 @@ import {
|
|||
Table,
|
||||
TableSchema,
|
||||
User,
|
||||
ViewFieldMetadata,
|
||||
ViewV2Schema,
|
||||
} from "@budibase/types"
|
||||
import _ from "lodash"
|
||||
import tk from "timekeeper"
|
||||
|
@ -139,6 +139,15 @@ describe.each([
|
|||
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>[]) {
|
||||
// Shuffling to avoid false positives given a fixed order
|
||||
for (const row of _.shuffle(arr)) {
|
||||
|
@ -153,21 +162,17 @@ describe.each([
|
|||
"view",
|
||||
async (schema: TableSchema) => {
|
||||
const tableId = await createTable(schema)
|
||||
const view = await config.api.viewV2.create({
|
||||
tableId: tableId,
|
||||
name: generator.guid(),
|
||||
schema: Object.keys(schema).reduce<Record<string, ViewFieldMetadata>>(
|
||||
(viewSchema, fieldName) => {
|
||||
const view = await createView(
|
||||
tableId,
|
||||
Object.keys(schema).reduce<ViewV2Schema>((viewSchema, fieldName) => {
|
||||
const field = schema[fieldName]
|
||||
viewSchema[fieldName] = {
|
||||
visible: field.visible ?? true,
|
||||
readonly: false,
|
||||
}
|
||||
return viewSchema
|
||||
},
|
||||
{}
|
||||
),
|
||||
})
|
||||
}, {})
|
||||
)
|
||||
return view.id
|
||||
},
|
||||
],
|
||||
|
|
|
@ -22,9 +22,9 @@ import {
|
|||
RelationshipType,
|
||||
TableSchema,
|
||||
RenameColumn,
|
||||
ViewFieldMetadata,
|
||||
FeatureFlag,
|
||||
BBReferenceFieldSubType,
|
||||
ViewV2Schema,
|
||||
} from "@budibase/types"
|
||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||
|
@ -1152,10 +1152,7 @@ describe.each([
|
|||
return table
|
||||
}
|
||||
|
||||
const createView = async (
|
||||
tableId: string,
|
||||
schema: Record<string, ViewFieldMetadata>
|
||||
) =>
|
||||
const createView = async (tableId: string, schema: ViewV2Schema) =>
|
||||
await config.api.viewV2.create({
|
||||
name: generator.guid(),
|
||||
tableId,
|
||||
|
|
|
@ -23,8 +23,8 @@ import {
|
|||
Row,
|
||||
Table,
|
||||
TableSchema,
|
||||
ViewFieldMetadata,
|
||||
ViewV2,
|
||||
ViewV2Schema,
|
||||
} from "@budibase/types"
|
||||
import sdk from "../../sdk"
|
||||
import { helpers } from "@budibase/shared-core"
|
||||
|
@ -262,7 +262,7 @@ export async function squashLinks<T = Row[] | Row>(
|
|||
FeatureFlag.ENRICHED_RELATIONSHIPS
|
||||
)
|
||||
|
||||
let viewSchema: Record<string, ViewFieldMetadata> = {}
|
||||
let viewSchema: ViewV2Schema = {}
|
||||
if (sdk.views.isView(source)) {
|
||||
if (helpers.views.isCalculationView(source)) {
|
||||
return enriched
|
||||
|
|
|
@ -71,9 +71,11 @@ export interface ViewV2 {
|
|||
order?: SortOrder
|
||||
type?: SortType
|
||||
}
|
||||
schema?: Record<string, ViewFieldMetadata>
|
||||
schema?: ViewV2Schema
|
||||
}
|
||||
|
||||
export type ViewV2Schema = Record<string, ViewFieldMetadata>
|
||||
|
||||
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema
|
||||
|
||||
export interface ViewCountOrSumSchema {
|
||||
|
|
Loading…
Reference in New Issue