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