diff --git a/api/package.json b/api/package.json index 08266d57c..2ce1a4b1c 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/api", - "version": "9.2.1", + "version": "9.3.0", "description": "", "main": "index.js", "scripts": { diff --git a/dashboard/package.json b/dashboard/package.json index c3e43b7d4..6e87c4936 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@devtable/dashboard", - "version": "9.2.1", + "version": "9.3.0", "license": "Apache-2.0", "publishConfig": { "access": "public", diff --git a/dashboard/src/plugins/viz-components/stats/index.ts b/dashboard/src/plugins/viz-components/stats/index.ts index 60e9678c2..3676e83fe 100644 --- a/dashboard/src/plugins/viz-components/stats/index.ts +++ b/dashboard/src/plugins/viz-components/stats/index.ts @@ -7,7 +7,7 @@ import { VizStatsEditor } from './viz-stats-editor'; export const StatsVizComponent: VizComponent = { createConfig() { return { - version: 2, + version: 3, config: DEFAULT_CONFIG, }; }, diff --git a/dashboard/src/plugins/viz-components/stats/type.ts b/dashboard/src/plugins/viz-components/stats/type.ts index a56ff1e8f..eac527d48 100644 --- a/dashboard/src/plugins/viz-components/stats/type.ts +++ b/dashboard/src/plugins/viz-components/stats/type.ts @@ -1,9 +1,10 @@ -export const DEFAULT_CONFIG: IVizStatsConf = { - align: 'center', - template: 'The variable ${value} is defined in Variables section', -}; - export interface IVizStatsConf { - align: 'center'; template: string; + vertical_align: 'top' | 'center' | 'bottom'; + horizontal_align: 'left' | 'center' | 'right'; } +export const DEFAULT_CONFIG: IVizStatsConf = { + template: 'The variable ${value} is defined in Variables section', + vertical_align: 'center', + horizontal_align: 'left', +}; diff --git a/dashboard/src/plugins/viz-components/stats/update/index.ts b/dashboard/src/plugins/viz-components/stats/update/index.ts index c8a9b1f09..1afe56071 100644 --- a/dashboard/src/plugins/viz-components/stats/update/index.ts +++ b/dashboard/src/plugins/viz-components/stats/update/index.ts @@ -60,6 +60,17 @@ function updateSchema2(legacyConf: IVizStatsConf & { variables: ITemplateVariabl return omit(legacyConf, ['variables']); } +// align -> horizontal_align +// add vertical_align +function v3(legacyConf: $TSFixMe): IVizStatsConf { + const { align, ...rest } = legacyConf; + return { + horizontal_align: align, + vertical_align: 'center', + ...rest, + }; +} + /** * used when moving variables from stats to `panel.variables` */ @@ -96,5 +107,9 @@ export class VizStatsMigrator extends VersionBasedMigrator { }); return { ...data, version: 2, config: updateSchema2(config) }; }); + this.version(3, (data) => { + const { config } = data; + return { ...data, version: 3, config: v3(config) }; + }); } } diff --git a/dashboard/src/plugins/viz-components/stats/viz-stats-editor.tsx b/dashboard/src/plugins/viz-components/stats/viz-stats-editor.tsx index 7a3d79ee3..ea432ba3f 100644 --- a/dashboard/src/plugins/viz-components/stats/viz-stats-editor.tsx +++ b/dashboard/src/plugins/viz-components/stats/viz-stats-editor.tsx @@ -1,4 +1,4 @@ -import { ActionIcon, Group, Select, Stack, Text } from '@mantine/core'; +import { ActionIcon, Group, Select, SimpleGrid, Stack, Text } from '@mantine/core'; import React from 'react'; import { DeviceFloppy } from 'tabler-icons-react'; import { VizConfigProps } from '~/types/plugin'; @@ -14,15 +14,17 @@ const horizontalAlignmentOptions = [ { label: 'Right', value: 'right' }, ]; +const verticalAlignmentOptions = [ + { label: 'Top', value: 'top' }, + { label: 'Center', value: 'center' }, + { label: 'Bottom', value: 'bottom' }, +]; + export function VizStatsEditor({ context }: VizConfigProps) { const { value: conf, set: setConf } = useStorageData(context.instanceData, 'config'); const defaultValues = React.useMemo(() => { - const { align, template = '' } = defaultsDeep({}, conf, DEFAULT_CONFIG); - return { - template, - align, - }; + return defaultsDeep({}, conf, DEFAULT_CONFIG); }, [conf]); const { control, handleSubmit, watch, getValues, reset } = useForm({ defaultValues }); @@ -31,7 +33,7 @@ export function VizStatsEditor({ context }: VizConfigProps) { reset(defaultValues); }, [defaultValues]); - watch(['template', 'align']); + watch(['template', 'horizontal_align', 'vertical_align']); const values = getValues(); const changed = React.useMemo(() => { return !_.isEqual(values, conf); @@ -51,11 +53,18 @@ export function VizStatsEditor({ context }: VizConfigProps) { control={control} render={({ field }) => } /> - } + /> +