Add uiMetadata to viewv2

This commit is contained in:
Andrew Kingston 2024-10-01 10:59:48 +01:00
parent ec8856b6ae
commit 930dd812cc
No known key found for this signature in database
6 changed files with 44 additions and 12 deletions

View File

@ -1,11 +1,26 @@
<script>
import { ActionButton, Modal, ModalContent } from "@budibase/bbui"
import { CalculationType } from "@budibase/types"
import { API } from "api"
import { getContext, createEventDispatcher } from "svelte"
const { datasource } = getContext("grid")
const { definition } = getContext("grid")
const dispatch = createEventDispatcher()
let modal
const save = async () => {
await API.viewV2.update({
...$definition,
schema: {
"Average game length": {
visible: true,
calculationType: CalculationType.AVG,
field: "Game Length",
},
},
})
}
</script>
<ActionButton icon="WebPage" quiet on:click={modal?.show}>
@ -13,7 +28,12 @@
</ActionButton>
<Modal bind:this={modal}>
<ModalContent title="Calculations" confirmText="Save" size="L">
<ModalContent
title="Calculations"
confirmText="Save"
size="L"
onConfirm={save}
>
Show calculations which are based on
</ModalContent>
</Modal>

View File

@ -17,6 +17,7 @@
let generateButton
$: view = $viewsV2.selected
$: calculation = view?.uiMetadata?.calculation
$: id = view?.id
$: datasource = {
type: "viewV2",
@ -28,9 +29,6 @@
$: currentTheme = $themeStore?.theme
$: darkMode = !currentTheme.includes("light")
$: currentTheme = $themeStore?.theme
$: darkMode = !currentTheme.includes("light")
const makeRowActionButtons = actions => {
return (actions || []).map(action => ({
text: action.name,
@ -58,14 +56,14 @@
buttonsCollapsed
>
<svelte:fragment slot="controls">
{#if view?.calculation}
{#if calculation}
<GridViewCalculationButton />
{/if}
<GridFilterButton />
<GridSortButton />
<GridSizeButton />
<GridManageAccessButton />
{#if !view?.calculation}
{#if !calculation}
<GridColumnsSettingButton />
<GridRowActionsButton />
<GridScreensButton on:request-generate={() => generateButton?.show()} />

View File

@ -38,9 +38,11 @@
const newView = await viewsV2.create({
name: trimmedName,
tableId: table._id,
schema: calculation ? {} : enrichSchema(table.schema),
schema: enrichSchema(table.schema),
primaryDisplay: calculation ? undefined : table.primaryDisplay,
calculation,
uiMetadata: {
calculation,
},
})
notifications.success(`View ${name} created`)
$goto(`./${newView.id}`)

View File

@ -39,6 +39,18 @@ export default class ViewV2Fetch extends DataFetch {
this.options
const { cursor, query, definition } = get(this.store)
// If this is a calculation view and there are no schema fields then do nothing
console.log(definition)
if (
definition.calculation &&
!Object.keys(definition.schema || {}).length
) {
return {
rows: [],
hasNextPage: false,
}
}
// If sort/filter params are not defined, update options to store the
// params built in to this view. This ensures that we can accurately
// compare old and new params and skip a redundant API call.

View File

@ -106,7 +106,7 @@ export async function create(ctx: Ctx<CreateViewRequest, ViewResponse>) {
sort: view.sort,
schema,
primaryDisplay: view.primaryDisplay,
calculation: view.calculation,
uiMetadata: view.uiMetadata,
}
const result = await sdk.views.create(tableId, parsedView)
ctx.status = 201
@ -142,7 +142,7 @@ export async function update(ctx: Ctx<UpdateViewRequest, ViewResponse>) {
sort: view.sort,
schema,
primaryDisplay: view.primaryDisplay,
calculation: view.calculation,
uiMetadata: view.uiMetadata,
}
const result = await sdk.views.update(tableId, parsedView)

View File

@ -72,7 +72,7 @@ export interface ViewV2 {
type?: SortType
}
schema?: Record<string, ViewFieldMetadata>
calculation?: boolean
uiMetadata?: Record<string, any>
}
export type ViewSchema = ViewCountOrSumSchema | ViewStatisticsSchema