Update view calculation button to be a detail popover
This commit is contained in:
parent
3ad913ae28
commit
27c1788db2
|
@ -1,15 +1,15 @@
|
||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
ActionButton,
|
ActionButton,
|
||||||
Modal,
|
|
||||||
ModalContent,
|
|
||||||
Select,
|
Select,
|
||||||
Icon,
|
Icon,
|
||||||
Multiselect,
|
Multiselect,
|
||||||
|
Button,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { CalculationType, canGroupBy, FieldType } from "@budibase/types"
|
import { CalculationType, canGroupBy, FieldType } from "@budibase/types"
|
||||||
import InfoDisplay from "pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte"
|
import InfoDisplay from "pages/builder/app/[application]/design/[screenId]/[componentId]/_components/Component/InfoDisplay.svelte"
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
|
import DetailPopover from "components/common/DetailPopover.svelte"
|
||||||
|
|
||||||
const { definition, datasource, rows } = getContext("grid")
|
const { definition, datasource, rows } = getContext("grid")
|
||||||
const calculationTypeOptions = [
|
const calculationTypeOptions = [
|
||||||
|
@ -35,19 +35,20 @@
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
let modal
|
let popover
|
||||||
let calculations = []
|
let calculations = []
|
||||||
let groupBy = []
|
let groupBy = []
|
||||||
let schema = {}
|
let schema = {}
|
||||||
|
let loading = false
|
||||||
|
|
||||||
$: schema = $definition?.schema || {}
|
$: schema = $definition?.schema || {}
|
||||||
$: count = extractCalculations($definition?.schema || {}).length
|
$: count = extractCalculations($definition?.schema || {}).length
|
||||||
$: groupByOptions = getGroupByOptions(schema)
|
$: groupByOptions = getGroupByOptions(schema)
|
||||||
|
|
||||||
const open = () => {
|
const openPopover = () => {
|
||||||
calculations = extractCalculations(schema)
|
calculations = extractCalculations(schema)
|
||||||
groupBy = calculations.length ? extractGroupBy(schema) : []
|
groupBy = calculations.length ? extractGroupBy(schema) : []
|
||||||
modal?.show()
|
popover?.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
const extractCalculations = schema => {
|
const extractCalculations = schema => {
|
||||||
|
@ -135,6 +136,7 @@
|
||||||
|
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
let newSchema = {}
|
let newSchema = {}
|
||||||
|
loading = true
|
||||||
|
|
||||||
// Add calculations
|
// Add calculations
|
||||||
for (let calc of calculations) {
|
for (let calc of calculations) {
|
||||||
|
@ -168,26 +170,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save changes
|
// Save changes
|
||||||
|
try {
|
||||||
await datasource.actions.saveDefinition({
|
await datasource.actions.saveDefinition({
|
||||||
...$definition,
|
...$definition,
|
||||||
primaryDisplay,
|
primaryDisplay,
|
||||||
schema: newSchema,
|
schema: newSchema,
|
||||||
})
|
})
|
||||||
await rows.actions.refreshData()
|
await rows.actions.refreshData()
|
||||||
|
} finally {
|
||||||
|
loading = false
|
||||||
|
popover.hide()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ActionButton icon="WebPage" quiet on:click={open}>
|
<DetailPopover bind:this={popover} title="Calculations" width={480}>
|
||||||
|
<svelte:fragment slot="anchor" let:open>
|
||||||
|
<ActionButton icon="WebPage" quiet on:click={openPopover} selected={open}>
|
||||||
Configure calculations{count ? `: ${count}` : ""}
|
Configure calculations{count ? `: ${count}` : ""}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
</svelte:fragment>
|
||||||
|
|
||||||
<Modal bind:this={modal}>
|
|
||||||
<ModalContent
|
|
||||||
title="Calculations"
|
|
||||||
confirmText="Save"
|
|
||||||
size="M"
|
|
||||||
onConfirm={save}
|
|
||||||
>
|
|
||||||
{#if calculations.length}
|
{#if calculations.length}
|
||||||
<div class="calculations">
|
<div class="calculations">
|
||||||
{#each calculations as calc, idx}
|
{#each calculations as calc, idx}
|
||||||
|
@ -236,8 +239,11 @@
|
||||||
quiet
|
quiet
|
||||||
body="Calculations only work with numeric columns and a maximum of 5 calculations can be added at once."
|
body="Calculations only work with numeric columns and a maximum of 5 calculations can be added at once."
|
||||||
/>
|
/>
|
||||||
</ModalContent>
|
|
||||||
</Modal>
|
<div>
|
||||||
|
<Button cta on:click={save} disabled={loading}>Save</Button>
|
||||||
|
</div>
|
||||||
|
</DetailPopover>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.calculations {
|
.calculations {
|
||||||
|
|
Loading…
Reference in New Issue