Refactoring to make it so that visible: false columns are removed from views, and when returning view schema, all columns are enriched.
This commit is contained in:
parent
bee6d21d82
commit
822a086666
6 changed files with 32 additions and 58 deletions
|
@ -9,7 +9,7 @@
|
|||
$: datasource = {
|
||||
type: "viewV2",
|
||||
id,
|
||||
tableId: $viewsV2.selected?.tableId
|
||||
tableId: $viewsV2.selected?.tableId,
|
||||
}
|
||||
|
||||
const handleGridViewUpdate = async e => {
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
import * as internal from "./internal"
|
||||
import * as external from "./external"
|
||||
import {
|
||||
validate as validateSchema,
|
||||
isSchema,
|
||||
isRows,
|
||||
} from "../../../utilities/schema"
|
||||
import { isExternalTable, isSQL } from "../../../integrations/utils"
|
||||
import { events } from "@budibase/backend-core"
|
||||
import {
|
||||
FetchTablesResponse,
|
||||
SaveTableResponse,
|
||||
SaveTableRequest,
|
||||
Table,
|
||||
TableResponse,
|
||||
UserCtx,
|
||||
} from "@budibase/types"
|
||||
import {isRows, isSchema, validate as validateSchema,} from "../../../utilities/schema"
|
||||
import {isExternalTable, isSQL} from "../../../integrations/utils"
|
||||
import {events} from "@budibase/backend-core"
|
||||
import {FetchTablesResponse, SaveTableRequest, SaveTableResponse, Table, TableResponse, UserCtx,} from "@budibase/types"
|
||||
import sdk from "../../../sdk"
|
||||
import { jsonFromCsvString } from "../../../utilities/csv"
|
||||
import { builderSocket } from "../../../websockets"
|
||||
import {jsonFromCsvString} from "../../../utilities/csv"
|
||||
import {builderSocket} from "../../../websockets"
|
||||
|
||||
function pickApi({ tableId, table }: { tableId?: string; table?: Table }) {
|
||||
if (table && !tableId) {
|
||||
|
@ -51,8 +40,7 @@ export async function fetch(ctx: UserCtx<void, FetchTablesResponse>) {
|
|||
}
|
||||
})
|
||||
|
||||
const response = [...internal, ...external].map(sdk.tables.enrichViewSchemas)
|
||||
ctx.body = response
|
||||
ctx.body = [...internal, ...external].map(sdk.tables.enrichViewSchemas)
|
||||
}
|
||||
|
||||
export async function find(ctx: UserCtx<void, TableResponse>) {
|
||||
|
|
|
@ -45,7 +45,7 @@ async function parseSchemaUI(ctx: Ctx, view: CreateViewRequest) {
|
|||
}
|
||||
}
|
||||
|
||||
return view.schema &&
|
||||
const finalViewSchema = view.schema &&
|
||||
Object.entries(view.schema).reduce((p, [fieldName, schemaValue]) => {
|
||||
const fieldSchema: RequiredKeys<UIFieldMetadata> = {
|
||||
order: schemaValue.order,
|
||||
|
@ -61,6 +61,12 @@ async function parseSchemaUI(ctx: Ctx, view: CreateViewRequest) {
|
|||
p[fieldName] = fieldSchema
|
||||
return p
|
||||
}, {} as Record<string, RequiredKeys<UIFieldMetadata>>)
|
||||
for (let [key, column] of Object.entries(finalViewSchema)) {
|
||||
if (!column.visible) {
|
||||
delete finalViewSchema[key]
|
||||
}
|
||||
}
|
||||
return finalViewSchema
|
||||
}
|
||||
|
||||
export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
|
||||
|
|
|
@ -119,10 +119,6 @@ describe("/v2/views", () => {
|
|||
order: 1,
|
||||
width: 100,
|
||||
},
|
||||
Category: {
|
||||
visible: false,
|
||||
icon: "ic",
|
||||
},
|
||||
},
|
||||
id: createdView.id,
|
||||
version: 2,
|
||||
|
@ -373,10 +369,6 @@ describe("/v2/views", () => {
|
|||
order: 1,
|
||||
width: 100,
|
||||
},
|
||||
Category: {
|
||||
visible: false,
|
||||
icon: "ic",
|
||||
},
|
||||
},
|
||||
id: view.id,
|
||||
version: 2,
|
||||
|
|
|
@ -1,18 +1,9 @@
|
|||
import { context } from "@budibase/backend-core"
|
||||
import { BudibaseInternalDB, getTableParams } from "../../../db/utils"
|
||||
import {
|
||||
breakExternalTableId,
|
||||
isExternalTable,
|
||||
isSQL,
|
||||
} from "../../../integrations/utils"
|
||||
import {
|
||||
Table,
|
||||
Database,
|
||||
TableResponse,
|
||||
TableViewsResponse,
|
||||
} from "@budibase/types"
|
||||
import {context} from "@budibase/backend-core"
|
||||
import {BudibaseInternalDB, getTableParams} from "../../../db/utils"
|
||||
import {breakExternalTableId, isExternalTable, isSQL,} from "../../../integrations/utils"
|
||||
import {Database, Table, TableResponse, TableViewsResponse,} from "@budibase/types"
|
||||
import datasources from "../datasources"
|
||||
import { populateExternalTableSchemas, isEditableColumn } from "./validation"
|
||||
import {isEditableColumn, populateExternalTableSchemas} from "./validation"
|
||||
import sdk from "../../../sdk"
|
||||
|
||||
async function getAllInternalTables(db?: Database): Promise<Table[]> {
|
||||
|
@ -62,7 +53,7 @@ async function getTable(tableId: any): Promise<Table> {
|
|||
}
|
||||
|
||||
function enrichViewSchemas(table: Table): TableResponse {
|
||||
const result: TableResponse = {
|
||||
return {
|
||||
...table,
|
||||
views: Object.values(table.views ?? [])
|
||||
.map(v => sdk.views.enrichSchema(v, table.schema))
|
||||
|
@ -71,8 +62,6 @@ function enrichViewSchemas(table: Table): TableResponse {
|
|||
return p
|
||||
}, {} as TableViewsResponse),
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
@ -79,20 +79,19 @@ export function enrichSchema(view: View | ViewV2, tableSchema: TableSchema) {
|
|||
}
|
||||
|
||||
let schema = { ...tableSchema }
|
||||
if (view.schemaUI) {
|
||||
const viewOverridesEntries = Object.entries(view.schemaUI)
|
||||
const viewSetsOrder = viewOverridesEntries.some(([_, v]) => v.order != null)
|
||||
for (const [fieldName, schemaUI] of viewOverridesEntries) {
|
||||
schema[fieldName] = {
|
||||
...schema[fieldName],
|
||||
...schemaUI,
|
||||
order: viewSetsOrder
|
||||
? schemaUI.order ?? undefined
|
||||
: schema[fieldName].order,
|
||||
const anyViewOrder = Object.values(view.schemaUI || {}).some(ui => ui.order != null)
|
||||
for (const key of Object.keys(schema)) {
|
||||
// if nothing specified in view, then it is not visible
|
||||
const ui = view.schemaUI?.[key] || { visible: false }
|
||||
schema[key] = {
|
||||
...schema[key],
|
||||
...ui,
|
||||
order: anyViewOrder
|
||||
? ui?.order ?? undefined
|
||||
: schema[key].order,
|
||||
}
|
||||
}
|
||||
delete view.schemaUI
|
||||
}
|
||||
|
||||
if (view?.columns?.length) {
|
||||
const pickedSchema: Record<string, FieldSchema> = {}
|
||||
|
|
Loading…
Reference in a new issue