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

View File

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

View File

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

View File

@ -39,6 +39,18 @@ export default class ViewV2Fetch extends DataFetch {
this.options this.options
const { cursor, query, definition } = get(this.store) 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 // If sort/filter params are not defined, update options to store the
// params built in to this view. This ensures that we can accurately // params built in to this view. This ensures that we can accurately
// compare old and new params and skip a redundant API call. // 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, sort: view.sort,
schema, schema,
primaryDisplay: view.primaryDisplay, primaryDisplay: view.primaryDisplay,
calculation: view.calculation, uiMetadata: view.uiMetadata,
} }
const result = await sdk.views.create(tableId, parsedView) const result = await sdk.views.create(tableId, parsedView)
ctx.status = 201 ctx.status = 201
@ -142,7 +142,7 @@ export async function update(ctx: Ctx<UpdateViewRequest, ViewResponse>) {
sort: view.sort, sort: view.sort,
schema, schema,
primaryDisplay: view.primaryDisplay, primaryDisplay: view.primaryDisplay,
calculation: view.calculation, uiMetadata: view.uiMetadata,
} }
const result = await sdk.views.update(tableId, parsedView) const result = await sdk.views.update(tableId, parsedView)

View File

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