@wildo-ai/saas-frontend-lib 1.1.12 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/components/data-display/approval-seal.d.ts +97 -0
- package/dist/esm/components/data-display/approval-seal.d.ts.map +1 -0
- package/dist/esm/components/data-display/approval-seal.js +208 -0
- package/dist/esm/components/data-display/approval-seal.js.map +1 -0
- package/dist/esm/components/data-display/formatters/display-field-file.d.ts.map +1 -1
- package/dist/esm/components/data-display/formatters/display-field-file.js +16 -2
- package/dist/esm/components/data-display/formatters/display-field-file.js.map +1 -1
- package/dist/esm/components/flows-actors/approval.d.ts.map +1 -1
- package/dist/esm/components/flows-actors/approval.js +48 -18
- package/dist/esm/components/flows-actors/approval.js.map +1 -1
- package/dist/esm/components/resources/collection/calendar/ResourceCollectionBody_Calendar.d.ts.map +1 -1
- package/dist/esm/components/resources/collection/calendar/ResourceCollectionBody_Calendar.js +5 -1
- package/dist/esm/components/resources/collection/calendar/ResourceCollectionBody_Calendar.js.map +1 -1
- package/dist/esm/components/views/chart-dashboard/ChartDashboard.d.ts +27 -24
- package/dist/esm/components/views/chart-dashboard/ChartDashboard.d.ts.map +1 -1
- package/dist/esm/components/views/chart-dashboard/ChartDashboard.js +27 -33
- package/dist/esm/components/views/chart-dashboard/ChartDashboard.js.map +1 -1
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.d.ts +37 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.d.ts.map +1 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.js +100 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.js.map +1 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.labels.d.ts +3 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.labels.d.ts.map +1 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.labels.js +34 -0
- package/dist/esm/components/views/chart-dashboard/ChartDashboardLayoutEditor.labels.js.map +1 -0
- package/dist/esm/components/views/chart-dashboard/chart-dashboard-layout.utils.d.ts +47 -0
- package/dist/esm/components/views/chart-dashboard/chart-dashboard-layout.utils.d.ts.map +1 -0
- package/dist/esm/components/views/chart-dashboard/chart-dashboard-layout.utils.js +94 -0
- package/dist/esm/components/views/chart-dashboard/chart-dashboard-layout.utils.js.map +1 -0
- package/dist/esm/components/views/chart-dashboard/useChartDashboardLayout.d.ts +39 -0
- package/dist/esm/components/views/chart-dashboard/useChartDashboardLayout.d.ts.map +1 -0
- package/dist/esm/components/views/chart-dashboard/useChartDashboardLayout.js +155 -0
- package/dist/esm/components/views/chart-dashboard/useChartDashboardLayout.js.map +1 -0
- package/dist/esm/core/components-registry/assert-registry-completeness.frontend.helper.d.ts.map +1 -1
- package/dist/esm/core/components-registry/assert-registry-completeness.frontend.helper.js +2 -0
- package/dist/esm/core/components-registry/assert-registry-completeness.frontend.helper.js.map +1 -1
- package/dist/esm/core/requests/wildo-http-client-manual-calls.frontend.service.d.ts +34 -1
- package/dist/esm/core/requests/wildo-http-client-manual-calls.frontend.service.d.ts.map +1 -1
- package/dist/esm/core/requests/wildo-http-client-manual-calls.frontend.service.js +41 -0
- package/dist/esm/core/requests/wildo-http-client-manual-calls.frontend.service.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -14,9 +14,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
* A tile may be a FIGURE as well as a drawing: a chart view whose chart is a `ChartType.KPI` (a count, a sum, a rate over
|
|
15
15
|
* the whole scope, its query grouping by nothing) renders as one number (`ChartKpiFigure`). It is declared, fetched,
|
|
16
16
|
* authorized and hidden exactly as a chart tile, because it IS a chart: one resource's declared aggregation (#2299).
|
|
17
|
+
*
|
|
18
|
+
* A dashboard given a `layoutRef` may be ARRANGED per organization (#2299): the organization's administrators reorder,
|
|
19
|
+
* resize and hide its tiles, stored as the organization's `organizationDashboardLayouts` row for that ref, and every
|
|
20
|
+
* member sees the arrangement. The arrangement only rearranges the declared tiles ({@link arrangeChartDashboardTiles}),
|
|
21
|
+
* and the read gate runs after it, so no arrangement shows a chart its viewer may not read.
|
|
17
22
|
*/
|
|
18
23
|
import { useMemo } from 'react';
|
|
19
|
-
import { ChartType } from '@wildo-ai/saas-models';
|
|
24
|
+
import { ChartDashboardTileRows, ChartDashboardTileSpan, ChartType } from '@wildo-ai/saas-models';
|
|
20
25
|
import { NavigationViewLabelFamily, TypographyVariant } from '@wildo-ai/presets-components-models';
|
|
21
26
|
import { cn } from '../../../core/ui/cn.js';
|
|
22
27
|
import { useI18n } from '../../../core/i18n/useI18n.js';
|
|
@@ -27,28 +32,10 @@ import { Text } from '../../../components/typography/text.js';
|
|
|
27
32
|
import { EmbedChart } from '../../../components/resources/embeds/ResourceEmbeds.js';
|
|
28
33
|
import { CompositeLayout } from '../../../components/views/composite-view/CompositeLayout.js';
|
|
29
34
|
import { viewerMayReadChart } from './chart-dashboard.utils.js';
|
|
35
|
+
import { arrangeChartDashboardTiles, defaultChartDashboardTileHeight } from './chart-dashboard-layout.utils.js';
|
|
36
|
+
import { ChartDashboardLayoutReadState, useChartDashboardLayout } from './useChartDashboardLayout.js';
|
|
37
|
+
import { ChartDashboardLayoutControl } from './ChartDashboardLayoutEditor.js';
|
|
30
38
|
/** @wildo_source:part:start saas.frontend.chart-dashboard facet:layer:frontend facet:family:view facet:audience:app-developer */
|
|
31
|
-
/** How many grid columns a dashboard tile spans, where the dashboard is wide enough to have them. */
|
|
32
|
-
export var ChartDashboardTileSpan;
|
|
33
|
-
(function (ChartDashboardTileSpan) {
|
|
34
|
-
/** One column (the default): a donut, a bar of a few categories. */
|
|
35
|
-
ChartDashboardTileSpan["ONE"] = "one";
|
|
36
|
-
/** Two columns: a trend over time, a bar of many categories. One column where the dashboard has one. */
|
|
37
|
-
ChartDashboardTileSpan["TWO"] = "two";
|
|
38
|
-
/** The whole row: a long timeline, a wide table-like chart. */
|
|
39
|
-
ChartDashboardTileSpan["FULL"] = "full";
|
|
40
|
-
})(ChartDashboardTileSpan || (ChartDashboardTileSpan = {}));
|
|
41
|
-
/** How many grid rows a dashboard tile spans, where the dashboard has more than one column. */
|
|
42
|
-
export var ChartDashboardTileRows;
|
|
43
|
-
(function (ChartDashboardTileRows) {
|
|
44
|
-
/** One row (the default). */
|
|
45
|
-
ChartDashboardTileRows["ONE"] = "one";
|
|
46
|
-
/**
|
|
47
|
-
* Two rows: a large chart beside two smaller ones stacked in the next column. Place it right after the first
|
|
48
|
-
* small tile, so the second small tile flows into the row beneath the first: `[small, large (TWO rows), small]`.
|
|
49
|
-
*/
|
|
50
|
-
ChartDashboardTileRows["TWO"] = "two";
|
|
51
|
-
})(ChartDashboardTileRows || (ChartDashboardTileRows = {}));
|
|
52
39
|
/**
|
|
53
40
|
* The most columns a dashboard's grid reaches, as its container widens. Every dashboard is one column in a narrow pane.
|
|
54
41
|
*/
|
|
@@ -78,6 +65,11 @@ export var ChartDashboardColumns;
|
|
|
78
65
|
*
|
|
79
66
|
* A KPI tile (a chart view whose chart is `ChartType.KPI`) shows one figure under that title, hidden by the same rule.
|
|
80
67
|
*
|
|
68
|
+
* With a `layoutRef`, the current organization's stored arrangement applies first (order, sizes, hidden tiles); the read
|
|
69
|
+
* gate then applies to what is left. An administrator who may arrange it gets a "customize" button above the grid,
|
|
70
|
+
* opening the layout editor, and keeps it even when every tile is hidden. The grid waits for the arrangement to be read,
|
|
71
|
+
* and a read that fails shows the declared layout.
|
|
72
|
+
*
|
|
81
73
|
* Place it inside a composite view (`CompositeLayout`), or declare a whole view as one with
|
|
82
74
|
* {@link defineChartDashboardView}.
|
|
83
75
|
*
|
|
@@ -92,21 +84,26 @@ export var ChartDashboardColumns;
|
|
|
92
84
|
* />
|
|
93
85
|
* ```
|
|
94
86
|
*/
|
|
95
|
-
export function ChartDashboard({ tiles, columns = ChartDashboardColumns.FOUR, className }) {
|
|
87
|
+
export function ChartDashboard({ tiles, columns = ChartDashboardColumns.FOUR, layoutRef, className }) {
|
|
96
88
|
const { registry } = useResourceRegistry();
|
|
97
89
|
const viewer = useViewerEffectiveRoles();
|
|
98
|
-
const
|
|
90
|
+
const layout = useChartDashboardLayout(layoutRef, viewer);
|
|
91
|
+
const arrangedTiles = useMemo(() => arrangeChartDashboardTiles(tiles, layout.stored?.tiles).filter((entry) => !entry.hidden).map((entry) => entry.tile), [tiles, layout.stored]);
|
|
92
|
+
const visibleTiles = useMemo(() => arrangedTiles.flatMap((tile) => {
|
|
99
93
|
const chartView = registry.resourceConfigurations[tile.resourceType]?.frontendConfiguration?.chartViews
|
|
100
94
|
?.find((candidate) => candidate.ref === tile.chartViewRef);
|
|
101
95
|
// An unknown chart is an authoring error, and `EmbedChart` throws it with the resource and ref named.
|
|
102
96
|
if (chartView !== undefined && !viewerMayReadChart(chartView.chartDefinition, registry, viewer))
|
|
103
97
|
return [];
|
|
104
98
|
return [{ tile, isFigure: chartView?.chartDefinition.chartType === ChartType.KPI }];
|
|
105
|
-
}), [
|
|
106
|
-
if (
|
|
99
|
+
}), [arrangedTiles, registry, viewer]);
|
|
100
|
+
if (layout.readState === ChartDashboardLayoutReadState.LOADING)
|
|
101
|
+
return null;
|
|
102
|
+
// An administrator keeps the editor even when nothing is left to show: they may have hidden every tile.
|
|
103
|
+
if (visibleTiles.length === 0 && !layout.canEdit)
|
|
107
104
|
return null;
|
|
108
105
|
const grid = GRID_CLASSES[columns];
|
|
109
|
-
return (
|
|
106
|
+
return (_jsxs("div", { className: cn('@container flex w-full flex-col gap-element', className), "data-chart-dashboard": true, children: [layout.canEdit && _jsx(ChartDashboardLayoutControl, { tiles: tiles, layout: layout }), visibleTiles.length > 0 && (_jsx("div", { className: cn('grid grid-cols-1 gap-group', grid.columns), children: visibleTiles.map(({ tile, isFigure }) => (_jsx(ChartDashboardTileCell, { tile: tile, isFigure: isFigure, grid: grid }, `${tile.resourceType}:${tile.chartViewRef}`))) }))] }));
|
|
110
107
|
}
|
|
111
108
|
const GRID_CLASSES = {
|
|
112
109
|
[ChartDashboardColumns.TWO]: { columns: '@2xl:grid-cols-2', spanTwo: '@2xl:col-span-2', rowsTwo: '@2xl:row-span-2' },
|
|
@@ -117,13 +114,10 @@ function tileSpanClasses(tile, grid) {
|
|
|
117
114
|
const span = tile.span ?? ChartDashboardTileSpan.ONE;
|
|
118
115
|
return cn(span === ChartDashboardTileSpan.TWO && grid.spanTwo, span === ChartDashboardTileSpan.FULL && 'col-span-full', tile.rows === ChartDashboardTileRows.TWO && grid.rowsTwo);
|
|
119
116
|
}
|
|
120
|
-
const DEFAULT_TILE_HEIGHT = 280;
|
|
121
|
-
/** A KPI tile's loading placeholder: about one line of the figure, so the tile does not jump when it arrives. */
|
|
122
|
-
const DEFAULT_FIGURE_TILE_HEIGHT = 64;
|
|
123
117
|
function ChartDashboardTileCell({ tile, isFigure, grid }) {
|
|
124
118
|
const { tView } = useI18n();
|
|
125
119
|
const heading = tView(NavigationViewLabelFamily.CHART, `resources.${tile.resourceType}.${tile.chartViewRef}`, 'title');
|
|
126
|
-
return (_jsxs("section", { className: cn('flex min-w-0 flex-col gap-element', tileSpanClasses(tile, grid)), "data-chart-dashboard-tile": `${tile.resourceType}:${tile.chartViewRef}`, "data-chart-dashboard-figure": isFigure ? '' : undefined, children: [heading && (_jsx(Text, { as: "div", typography: TypographyVariant.EYEBROW, children: heading })), _jsx(EmbedChart, { resourceType: tile.resourceType, viewRef: tile.chartViewRef, height: tile.height ?? (isFigure
|
|
120
|
+
return (_jsxs("section", { className: cn('flex min-w-0 flex-col gap-element', tileSpanClasses(tile, grid)), "data-chart-dashboard-tile": `${tile.resourceType}:${tile.chartViewRef}`, "data-chart-dashboard-figure": isFigure ? '' : undefined, children: [heading && (_jsx(Text, { as: "div", typography: TypographyVariant.EYEBROW, children: heading })), _jsx(EmbedChart, { resourceType: tile.resourceType, viewRef: tile.chartViewRef, height: tile.height ?? defaultChartDashboardTileHeight(isFigure, tile.rows) })] }));
|
|
127
121
|
}
|
|
128
122
|
/** @wildo_source:part:start saas.frontend.chart-dashboard-view facet:layer:frontend facet:family:view facet:audience:app-developer */
|
|
129
123
|
/**
|
|
@@ -145,9 +139,9 @@ function ChartDashboardTileCell({ tile, isFigure, grid }) {
|
|
|
145
139
|
* ```
|
|
146
140
|
*/
|
|
147
141
|
export function defineChartDashboardView(config) {
|
|
148
|
-
const { tiles, ...compositeConfig } = config;
|
|
142
|
+
const { tiles, columns, layoutRef, ...compositeConfig } = config;
|
|
149
143
|
function ChartDashboardView() {
|
|
150
|
-
return (_jsx(CompositeLayout, { children: _jsx(ChartDashboard, { tiles: tiles }) }));
|
|
144
|
+
return (_jsx(CompositeLayout, { children: _jsx(ChartDashboard, { tiles: tiles, columns: columns, layoutRef: layoutRef }) }));
|
|
151
145
|
}
|
|
152
146
|
return defineCompositeView(ChartDashboardView, compositeConfig);
|
|
153
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartDashboard.js","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/ChartDashboard.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAc,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACnG,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wDAAwD,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,mEAA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,EAAE,CAAC,CAAC,CAAC,SAAS,aAErD,OAAO,IAAI,CACV,KAAC,IAAI,IAAC,EAAE,EAAC,KAAK,EAAC,UAAU,EAAE,iBAAiB,CAAC,OAAO,YACjD,OAAO,GACH,CACR,EACD,KAAC,UAAU,IACT,YAAY,EAAE,IAAI,CAAC,YAAY,EAC/B,OAAO,EAAE,IAAI,CAAC,YAAY,EAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,mBAAmB,CAAC,GACpF,IACM,CACX,CAAC;AACJ,CAAC;AAED,sIAAsI;AACtI;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAAsG;IAEtG,MAAM,EAAE,KAAK,EAAE,GAAG,eAAe,EAAE,GAAG,MAAM,CAAC;IAC7C,SAAS,kBAAkB;QACzB,OAAO,CACL,KAAC,eAAe,cACd,KAAC,cAAc,IAAC,KAAK,EAAE,KAAK,GAAI,GAChB,CACnB,CAAC;IACJ,CAAC;IACD,OAAO,mBAAmB,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;AAClE,CAAC","sourcesContent":["/**\n * A declarative chart dashboard: charts that SEVERAL resources own, on one responsive grid (#2299).\n *\n * Charts are resource-scoped: each resource declares its `chartViews`, and the backend executes them with tenant scope\n * and authorization injected. Before this, a page combining them was hand-written per application (a grid of\n * `EmbedChart`s with a heading each). The dashboard is that page as data: a list of tiles, each naming the resource that\n * owns the chart and the chart view's ref.\n *\n * Each tile renders through `EmbedChart`, so it keeps everything a resource-owned chart does: the chart's feature\n * gate, the viewer's organization scope (from the host composite's context), and a failure that stays inside its card.\n * A tile the viewer may not read is not drawn at all ({@link viewerMayReadChart}).\n *\n * A tile may be a FIGURE as well as a drawing: a chart view whose chart is a `ChartType.KPI` (a count, a sum, a rate over\n * the whole scope, its query grouping by nothing) renders as one number (`ChartKpiFigure`). It is declared, fetched,\n * authorized and hidden exactly as a chart tile, because it IS a chart: one resource's declared aggregation (#2299).\n */\n\nimport React, { useMemo } from 'react';\nimport { ChartType } from '@wildo-ai/saas-models';\nimport { NavigationViewLabelFamily, TypographyVariant } from '@wildo-ai/presets-components-models';\nimport { cn } from '~wildo-frontend-lib/core/ui/cn';\nimport { useI18n } from '~wildo-frontend-lib/core/i18n/useI18n';\nimport { useResourceRegistry } from '~wildo-frontend-lib/core/resources/useResourceRegistry';\nimport { useViewerEffectiveRoles } from '~wildo-frontend-lib/core/navigation/launcher-runtime-availability';\nimport {\n defineCompositeView,\n type CompositeViewAuthoringConfig,\n} from '~wildo-frontend-lib/core/config/composite-view.schemas';\nimport { Text } from '~wildo-frontend-lib/components/typography/text';\nimport { EmbedChart } from '~wildo-frontend-lib/components/resources/embeds/ResourceEmbeds';\nimport { CompositeLayout } from '~wildo-frontend-lib/components/views/composite-view/CompositeLayout';\nimport { viewerMayReadChart } from './chart-dashboard.utils';\n\n/** @wildo_source:part:start saas.frontend.chart-dashboard facet:layer:frontend facet:family:view facet:audience:app-developer */\n/** How many grid columns a dashboard tile spans, where the dashboard is wide enough to have them. */\nexport enum ChartDashboardTileSpan {\n /** One column (the default): a donut, a bar of a few categories. */\n ONE = 'one',\n /** Two columns: a trend over time, a bar of many categories. One column where the dashboard has one. */\n TWO = 'two',\n /** The whole row: a long timeline, a wide table-like chart. */\n FULL = 'full',\n}\n\n/** How many grid rows a dashboard tile spans, where the dashboard has more than one column. */\nexport enum ChartDashboardTileRows {\n /** One row (the default). */\n ONE = 'one',\n /**\n * Two rows: a large chart beside two smaller ones stacked in the next column. Place it right after the first\n * small tile, so the second small tile flows into the row beneath the first: `[small, large (TWO rows), small]`.\n */\n TWO = 'two',\n}\n\n/**\n * The most columns a dashboard's grid reaches, as its container widens. Every dashboard is one column in a narrow pane.\n */\nexport enum ChartDashboardColumns {\n /** Two columns from a medium container (42rem). */\n TWO = 'two',\n /**\n * Three narrow columns from a small container (28rem): small charts beside a large one, in a dashboard that shares\n * its row with something else (a block of counters, a list).\n */\n THREE = 'three',\n /** Two columns from a medium container (42rem), four from a wide one (64rem). The default. */\n FOUR = 'four',\n}\n\n/**\n * One tile of a {@link ChartDashboard}: a chart a resource declares in its `chartViews`. A chart whose `chartType` is\n * `ChartType.KPI` is a KPI tile: one figure under its title instead of a drawing.\n */\nexport interface ChartDashboardTile {\n /** The resource whose `chartViews` declares the chart. */\n resourceType: string;\n /** The chart view's `ref` on that resource (`InsertedChartDeclaration.ref`, usually `<chartDefinition>.ref`). */\n chartViewRef: string;\n /** Grid columns the tile spans. Default: {@link ChartDashboardTileSpan.ONE}. */\n span?: ChartDashboardTileSpan;\n /** Grid rows the tile spans. Default: {@link ChartDashboardTileRows.ONE}. */\n rows?: ChartDashboardTileRows;\n /**\n * Chart canvas height in px (the canvas is sized by this, not by the tile). Default: 280 for a chart; a KPI tile takes\n * the height of its figure, and this only sizes its loading placeholder (default 64).\n */\n height?: number;\n}\n\nexport interface ChartDashboardProps {\n /** The tiles, in reading order. Tiles may name charts of any number of resources. */\n tiles: readonly ChartDashboardTile[];\n /** The most columns the grid reaches. Default: {@link ChartDashboardColumns.FOUR}. */\n columns?: ChartDashboardColumns;\n className?: string;\n}\n\n/**\n * Lays charts from several resources on one responsive grid: one column in a narrow pane, then up to `columns`\n * ({@link ChartDashboardColumns}, four by default) as the container widens (container queries, so a dashboard in a\n * split pane is laid out for the pane). A tile may span two columns or the whole row, and two rows.\n *\n * Each tile is headed by the chart view's own title (`views.chart.resources.<resourceType>.<ref>.title`, the words\n * its route and launcher use) and drawn through `EmbedChart`: the chart's feature gate, the host composite's scope and\n * a failure kept inside the tile. A tile whose chart the viewer may not read — the backend's aggregation gate would\n * refuse it: no LIST role on its resource or on a resource it joins, or outside the chart's own `accessControl.roles`,\n * or only a role confined there to its holder's own or assigned rows (a chart reads every row in scope) — is not drawn,\n * and the grid closes up. A dashboard with nothing the viewer may read renders nothing.\n *\n * A KPI tile (a chart view whose chart is `ChartType.KPI`) shows one figure under that title, hidden by the same rule.\n *\n * Place it inside a composite view (`CompositeLayout`), or declare a whole view as one with\n * {@link defineChartDashboardView}.\n *\n * @example\n * ```tsx\n * <ChartDashboard\n * tiles={[\n * { resourceType: R.TODOS, chartViewRef: todosByStatusChartDefinition.ref },\n * { resourceType: R.TASKS, chartViewRef: todoTaskPriorityChartDefinition.ref },\n * { resourceType: R.TODOS, chartViewRef: todosCreatedTimelineChartDefinition.ref, span: ChartDashboardTileSpan.TWO },\n * ]}\n * />\n * ```\n */\nexport function ChartDashboard({ tiles, columns = ChartDashboardColumns.FOUR, className }: ChartDashboardProps): React.JSX.Element | null {\n const { registry } = useResourceRegistry();\n const viewer = useViewerEffectiveRoles();\n const visibleTiles = useMemo(\n () => tiles.flatMap((tile) => {\n const chartView = registry.resourceConfigurations[tile.resourceType]?.frontendConfiguration?.chartViews\n ?.find((candidate) => candidate.ref === tile.chartViewRef);\n // An unknown chart is an authoring error, and `EmbedChart` throws it with the resource and ref named.\n if (chartView !== undefined && !viewerMayReadChart(chartView.chartDefinition, registry, viewer)) return [];\n return [{ tile, isFigure: chartView?.chartDefinition.chartType === ChartType.KPI }];\n }),\n [tiles, registry, viewer],\n );\n\n if (visibleTiles.length === 0) return null;\n const grid = GRID_CLASSES[columns];\n return (\n <div className={cn('@container w-full', className)} data-chart-dashboard>\n <div className={cn('grid grid-cols-1 gap-group', grid.columns)}>\n {visibleTiles.map(({ tile, isFigure }) => (\n <ChartDashboardTileCell key={`${tile.resourceType}:${tile.chartViewRef}`} tile={tile} isFigure={isFigure} grid={grid} />\n ))}\n </div>\n </div>\n );\n}\n/** @wildo_source:part:end saas.frontend.chart-dashboard */\n\n/**\n * The grid's column classes, and the span classes that go with them. A span applies only from the container width\n * where the grid has more than one column, so it is read from the same entry: a two-row tile in a one-column grid would\n * otherwise stretch over two rows of its own. Literal strings, so the stylesheet compiler sees every class.\n */\ninterface ChartDashboardGridClasses {\n columns: string;\n spanTwo: string;\n rowsTwo: string;\n}\n\nconst GRID_CLASSES: Record<ChartDashboardColumns, ChartDashboardGridClasses> = {\n [ChartDashboardColumns.TWO]: { columns: '@2xl:grid-cols-2', spanTwo: '@2xl:col-span-2', rowsTwo: '@2xl:row-span-2' },\n [ChartDashboardColumns.THREE]: { columns: '@md:grid-cols-3', spanTwo: '@md:col-span-2', rowsTwo: '@md:row-span-2' },\n [ChartDashboardColumns.FOUR]: { columns: '@2xl:grid-cols-2 @5xl:grid-cols-4', spanTwo: '@2xl:col-span-2', rowsTwo: '@2xl:row-span-2' },\n};\n\nfunction tileSpanClasses(tile: ChartDashboardTile, grid: ChartDashboardGridClasses): string {\n const span = tile.span ?? ChartDashboardTileSpan.ONE;\n return cn(\n span === ChartDashboardTileSpan.TWO && grid.spanTwo,\n span === ChartDashboardTileSpan.FULL && 'col-span-full',\n tile.rows === ChartDashboardTileRows.TWO && grid.rowsTwo,\n );\n}\n\nconst DEFAULT_TILE_HEIGHT = 280;\n/** A KPI tile's loading placeholder: about one line of the figure, so the tile does not jump when it arrives. */\nconst DEFAULT_FIGURE_TILE_HEIGHT = 64;\n\nfunction ChartDashboardTileCell({ tile, isFigure, grid }: { tile: ChartDashboardTile; isFigure: boolean; grid: ChartDashboardGridClasses }): React.JSX.Element {\n const { tView } = useI18n();\n const heading = tView(NavigationViewLabelFamily.CHART, `resources.${tile.resourceType}.${tile.chartViewRef}`, 'title');\n return (\n <section\n className={cn('flex min-w-0 flex-col gap-element', tileSpanClasses(tile, grid))}\n data-chart-dashboard-tile={`${tile.resourceType}:${tile.chartViewRef}`}\n data-chart-dashboard-figure={isFigure ? '' : undefined}\n >\n {heading && (\n <Text as=\"div\" typography={TypographyVariant.EYEBROW}>\n {heading}\n </Text>\n )}\n <EmbedChart\n resourceType={tile.resourceType}\n viewRef={tile.chartViewRef}\n height={tile.height ?? (isFigure ? DEFAULT_FIGURE_TILE_HEIGHT : DEFAULT_TILE_HEIGHT)}\n />\n </section>\n );\n}\n\n/** @wildo_source:part:start saas.frontend.chart-dashboard-view facet:layer:frontend facet:family:view facet:audience:app-developer */\n/**\n * A whole composite view that is a chart dashboard, declared as data — register it under the frontend domain module's\n * `compositeViews` like any app-level composite. The rest of the config is the composite view's\n * own (`sectionRefs`, `icon`, `requiredFeatures`, …).\n *\n * @example\n * ```ts\n * compositeViews: {\n * 'operations-dashboard': defineChartDashboardView({\n * tiles: [\n * { resourceType: R.CASES, chartViewRef: casesByStatusChart.ref },\n * { resourceType: R.INVOICES, chartViewRef: revenueByMonthChart.ref, span: ChartDashboardTileSpan.TWO },\n * { resourceType: R.SLA_BREACHES, chartViewRef: breachesByTeamChart.ref },\n * ],\n * }),\n * }\n * ```\n */\nexport function defineChartDashboardView(\n config: { tiles: readonly ChartDashboardTile[] } & Omit<CompositeViewAuthoringConfig, 'viewComponent'>,\n): CompositeViewAuthoringConfig {\n const { tiles, ...compositeConfig } = config;\n function ChartDashboardView(): React.JSX.Element {\n return (\n <CompositeLayout>\n <ChartDashboard tiles={tiles} />\n </CompositeLayout>\n );\n }\n return defineCompositeView(ChartDashboardView, compositeConfig);\n}\n/** @wildo_source:part:end saas.frontend.chart-dashboard-view */\n"]}
|
|
1
|
+
{"version":3,"file":"ChartDashboard.js","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/ChartDashboard.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAc,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACnG,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wDAAwD,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,mEA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ive grid (#2299).\n *\n * Charts are resource-scoped: each resource declares its `chartViews`, and the backend executes them with tenant scope\n * and authorization injected. Before this, a page combining them was hand-written per application (a grid of\n * `EmbedChart`s with a heading each). The dashboard is that page as data: a list of tiles, each naming the resource that\n * owns the chart and the chart view's ref.\n *\n * Each tile renders through `EmbedChart`, so it keeps everything a resource-owned chart does: the chart's feature\n * gate, the viewer's organization scope (from the host composite's context), and a failure that stays inside its card.\n * A tile the viewer may not read is not drawn at all ({@link viewerMayReadChart}).\n *\n * A tile may be a FIGURE as well as a drawing: a chart view whose chart is a `ChartType.KPI` (a count, a sum, a rate over\n * the whole scope, its query grouping by nothing) renders as one number (`ChartKpiFigure`). It is declared, fetched,\n * authorized and hidden exactly as a chart tile, because it IS a chart: one resource's declared aggregation (#2299).\n *\n * A dashboard given a `layoutRef` may be ARRANGED per organization (#2299): the organization's administrators reorder,\n * resize and hide its tiles, stored as the organization's `organizationDashboardLayouts` row for that ref, and every\n * member sees the arrangement. The arrangement only rearranges the declared tiles ({@link arrangeChartDashboardTiles}),\n * and the read gate runs after it, so no arrangement shows a chart its viewer may not read.\n */\n\nimport React, { useMemo } from 'react';\nimport { ChartDashboardTileRows, ChartDashboardTileSpan, ChartType } from '@wildo-ai/saas-models';\nimport { NavigationViewLabelFamily, TypographyVariant } from '@wildo-ai/presets-components-models';\nimport { cn } from '~wildo-frontend-lib/core/ui/cn';\nimport { useI18n } from '~wildo-frontend-lib/core/i18n/useI18n';\nimport { useResourceRegistry } from '~wildo-frontend-lib/core/resources/useResourceRegistry';\nimport { useViewerEffectiveRoles } from '~wildo-frontend-lib/core/navigation/launcher-runtime-availability';\nimport {\n defineCompositeView,\n type CompositeViewAuthoringConfig,\n} from '~wildo-frontend-lib/core/config/composite-view.schemas';\nimport { Text } from '~wildo-frontend-lib/components/typography/text';\nimport { EmbedChart } from '~wildo-frontend-lib/components/resources/embeds/ResourceEmbeds';\nimport { CompositeLayout } from '~wildo-frontend-lib/components/views/composite-view/CompositeLayout';\nimport { viewerMayReadChart } from './chart-dashboard.utils';\nimport { arrangeChartDashboardTiles, defaultChartDashboardTileHeight } from './chart-dashboard-layout.utils';\nimport { ChartDashboardLayoutReadState, useChartDashboardLayout } from './useChartDashboardLayout';\nimport { ChartDashboardLayoutControl } from './ChartDashboardLayoutEditor';\n\n/** @wildo_source:part:start saas.frontend.chart-dashboard facet:layer:frontend facet:family:view facet:audience:app-developer */\n/**\n * The most columns a dashboard's grid reaches, as its container widens. Every dashboard is one column in a narrow pane.\n */\nexport enum ChartDashboardColumns {\n /** Two columns from a medium container (42rem). */\n TWO = 'two',\n /**\n * Three narrow columns from a small container (28rem): small charts beside a large one, in a dashboard that shares\n * its row with something else (a block of counters, a list).\n */\n THREE = 'three',\n /** Two columns from a medium container (42rem), four from a wide one (64rem). The default. */\n FOUR = 'four',\n}\n\n/**\n * One tile of a {@link ChartDashboard}: a chart a resource declares in its `chartViews`. A chart whose `chartType` is\n * `ChartType.KPI` is a KPI tile: one figure under its title instead of a drawing.\n */\nexport interface ChartDashboardTile {\n /** The resource whose `chartViews` declares the chart. */\n resourceType: string;\n /** The chart view's `ref` on that resource (`InsertedChartDeclaration.ref`, usually `<chartDefinition>.ref`). */\n chartViewRef: string;\n /** Grid columns the tile spans (`ChartDashboardTileSpan`, `@wildo-ai/saas-models`). Default: `ONE`. */\n span?: ChartDashboardTileSpan;\n /** Grid rows the tile spans (`ChartDashboardTileRows`, `@wildo-ai/saas-models`). Default: `ONE`. */\n rows?: ChartDashboardTileRows;\n /**\n * Chart canvas height in px for the tile's declared `rows` (the canvas is sized by this, not by the tile). Default:\n * 280 for a one-row chart, 592 for a two-row one (two rows and the gap between them); a KPI tile takes the height of its\n * figure, and this only sizes its loading placeholder (default 64). When an organization's layout changes the tile's\n * rows, this height is doubled (plus the gap) or halved with them.\n */\n height?: number;\n}\n\nexport interface ChartDashboardProps {\n /** The tiles, in reading order. Tiles may name charts of any number of resources. */\n tiles: readonly ChartDashboardTile[];\n /** The most columns the grid reaches. Default: {@link ChartDashboardColumns.FOUR}. */\n columns?: ChartDashboardColumns;\n /**\n * The dashboard's name for an organization's stored arrangement of it (`organizationDashboardLayouts.dashboardRef`),\n * unique within the application, e.g. `'home-analytics'`. Given one, the organization's administrators may reorder,\n * resize and hide its tiles for every member, and go back to the declared layout; without one the dashboard is always\n * laid out as declared.\n */\n layoutRef?: string;\n className?: string;\n}\n\n/**\n * Lays charts from several resources on one responsive grid: one column in a narrow pane, then up to `columns`\n * ({@link ChartDashboardColumns}, four by default) as the container widens (container queries, so a dashboard in a\n * split pane is laid out for the pane). A tile may span two columns or the whole row, and two rows.\n *\n * Each tile is headed by the chart view's own title (`views.chart.resources.<resourceType>.<ref>.title`, the words\n * its route and launcher use) and drawn through `EmbedChart`: the chart's feature gate, the host composite's scope and\n * a failure kept inside the tile. A tile whose chart the viewer may not read — the backend's aggregation gate would\n * refuse it: no LIST role on its resource or on a resource it joins, or outside the chart's own `accessControl.roles`,\n * or only a role confined there to its holder's own or assigned rows (a chart reads every row in scope) — is not drawn,\n * and the grid closes up. A dashboard with nothing the viewer may read renders nothing.\n *\n * A KPI tile (a chart view whose chart is `ChartType.KPI`) shows one figure under that title, hidden by the same rule.\n *\n * With a `layoutRef`, the current organization's stored arrangement applies first (order, sizes, hidden tiles); the read\n * gate then applies to what is left. An administrator who may arrange it gets a \"customize\" button above the grid,\n * opening the layout editor, and keeps it even when every tile is hidden. The grid waits for the arrangement to be read,\n * and a read that fails shows the declared layout.\n *\n * Place it inside a composite view (`CompositeLayout`), or declare a whole view as one with\n * {@link defineChartDashboardView}.\n *\n * @example\n * ```tsx\n * <ChartDashboard\n * tiles={[\n * { resourceType: R.TODOS, chartViewRef: todosByStatusChartDefinition.ref },\n * { resourceType: R.TASKS, chartViewRef: todoTaskPriorityChartDefinition.ref },\n * { resourceType: R.TODOS, chartViewRef: todosCreatedTimelineChartDefinition.ref, span: ChartDashboardTileSpan.TWO },\n * ]}\n * />\n * ```\n */\nexport function ChartDashboard({ tiles, columns = ChartDashboardColumns.FOUR, layoutRef, className }: ChartDashboardProps): React.JSX.Element | null {\n const { registry } = useResourceRegistry();\n const viewer = useViewerEffectiveRoles();\n const layout = useChartDashboardLayout(layoutRef, viewer);\n const arrangedTiles = useMemo(\n () => arrangeChartDashboardTiles(tiles, layout.stored?.tiles).filter((entry) => !entry.hidden).map((entry) => entry.tile),\n [tiles, layout.stored],\n );\n const visibleTiles = useMemo(\n () => arrangedTiles.flatMap((tile) => {\n const chartView = registry.resourceConfigurations[tile.resourceType]?.frontendConfiguration?.chartViews\n ?.find((candidate) => candidate.ref === tile.chartViewRef);\n // An unknown chart is an authoring error, and `EmbedChart` throws it with the resource and ref named.\n if (chartView !== undefined && !viewerMayReadChart(chartView.chartDefinition, registry, viewer)) return [];\n return [{ tile, isFigure: chartView?.chartDefinition.chartType === ChartType.KPI }];\n }),\n [arrangedTiles, registry, viewer],\n );\n\n if (layout.readState === ChartDashboardLayoutReadState.LOADING) return null;\n // An administrator keeps the editor even when nothing is left to show: they may have hidden every tile.\n if (visibleTiles.length === 0 && !layout.canEdit) return null;\n const grid = GRID_CLASSES[columns];\n return (\n <div className={cn('@container flex w-full flex-col gap-element', className)} data-chart-dashboard>\n {layout.canEdit && <ChartDashboardLayoutControl tiles={tiles} layout={layout} />}\n {visibleTiles.length > 0 && (\n <div className={cn('grid grid-cols-1 gap-group', grid.columns)}>\n {visibleTiles.map(({ tile, isFigure }) => (\n <ChartDashboardTileCell key={`${tile.resourceType}:${tile.chartViewRef}`} tile={tile} isFigure={isFigure} grid={grid} />\n ))}\n </div>\n )}\n </div>\n );\n}\n/** @wildo_source:part:end saas.frontend.chart-dashboard */\n\n/**\n * The grid's column classes, and the span classes that go with them. A span applies only from the container width\n * where the grid has more than one column, so it is read from the same entry: a two-row tile in a one-column grid would\n * otherwise stretch over two rows of its own. Literal strings, so the stylesheet compiler sees every class.\n */\ninterface ChartDashboardGridClasses {\n columns: string;\n spanTwo: string;\n rowsTwo: string;\n}\n\nconst GRID_CLASSES: Record<ChartDashboardColumns, ChartDashboardGridClasses> = {\n [ChartDashboardColumns.TWO]: { columns: '@2xl:grid-cols-2', spanTwo: '@2xl:col-span-2', rowsTwo: '@2xl:row-span-2' },\n [ChartDashboardColumns.THREE]: { columns: '@md:grid-cols-3', spanTwo: '@md:col-span-2', rowsTwo: '@md:row-span-2' },\n [ChartDashboardColumns.FOUR]: { columns: '@2xl:grid-cols-2 @5xl:grid-cols-4', spanTwo: '@2xl:col-span-2', rowsTwo: '@2xl:row-span-2' },\n};\n\nfunction tileSpanClasses(tile: ChartDashboardTile, grid: ChartDashboardGridClasses): string {\n const span = tile.span ?? ChartDashboardTileSpan.ONE;\n return cn(\n span === ChartDashboardTileSpan.TWO && grid.spanTwo,\n span === ChartDashboardTileSpan.FULL && 'col-span-full',\n tile.rows === ChartDashboardTileRows.TWO && grid.rowsTwo,\n );\n}\n\nfunction ChartDashboardTileCell({ tile, isFigure, grid }: { tile: ChartDashboardTile; isFigure: boolean; grid: ChartDashboardGridClasses }): React.JSX.Element {\n const { tView } = useI18n();\n const heading = tView(NavigationViewLabelFamily.CHART, `resources.${tile.resourceType}.${tile.chartViewRef}`, 'title');\n return (\n <section\n className={cn('flex min-w-0 flex-col gap-element', tileSpanClasses(tile, grid))}\n data-chart-dashboard-tile={`${tile.resourceType}:${tile.chartViewRef}`}\n data-chart-dashboard-figure={isFigure ? '' : undefined}\n >\n {heading && (\n <Text as=\"div\" typography={TypographyVariant.EYEBROW}>\n {heading}\n </Text>\n )}\n <EmbedChart\n resourceType={tile.resourceType}\n viewRef={tile.chartViewRef}\n height={tile.height ?? defaultChartDashboardTileHeight(isFigure, tile.rows)}\n />\n </section>\n );\n}\n\n/** @wildo_source:part:start saas.frontend.chart-dashboard-view facet:layer:frontend facet:family:view facet:audience:app-developer */\n/**\n * A whole composite view that is a chart dashboard, declared as data — register it under the frontend domain module's\n * `compositeViews` like any app-level composite. The rest of the config is the composite view's\n * own (`sectionRefs`, `icon`, `requiredFeatures`, …).\n *\n * @example\n * ```ts\n * compositeViews: {\n * 'operations-dashboard': defineChartDashboardView({\n * tiles: [\n * { resourceType: R.CASES, chartViewRef: casesByStatusChart.ref },\n * { resourceType: R.INVOICES, chartViewRef: revenueByMonthChart.ref, span: ChartDashboardTileSpan.TWO },\n * { resourceType: R.SLA_BREACHES, chartViewRef: breachesByTeamChart.ref },\n * ],\n * }),\n * }\n * ```\n */\nexport function defineChartDashboardView(\n config: { tiles: readonly ChartDashboardTile[]; columns?: ChartDashboardColumns; layoutRef?: string } & Omit<CompositeViewAuthoringConfig, 'viewComponent'>,\n): CompositeViewAuthoringConfig {\n const { tiles, columns, layoutRef, ...compositeConfig } = config;\n function ChartDashboardView(): React.JSX.Element {\n return (\n <CompositeLayout>\n <ChartDashboard tiles={tiles} columns={columns} layoutRef={layoutRef} />\n </CompositeLayout>\n );\n }\n return defineCompositeView(ChartDashboardView, compositeConfig);\n}\n/** @wildo_source:part:end saas.frontend.chart-dashboard-view */\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart dashboard's layout editor (#2299): an organization administrator reorders a dashboard's tiles, sizes each,
|
|
3
|
+
* hides some, and saves the arrangement for the whole organization; or resets it to the layout the application declares.
|
|
4
|
+
*
|
|
5
|
+
* Opened from the dashboard itself ({@link ChartDashboardLayoutControl}, rendered by `ChartDashboard` above its grid for a
|
|
6
|
+
* viewer who may write the organization's `organizationDashboardLayouts`). The list is every DECLARED tile, in the
|
|
7
|
+
* dashboard's current order ({@link arrangeChartDashboardTiles}, the function the dashboard renders with), hidden ones
|
|
8
|
+
* included so they can be shown again; it is never a list of charts the application did not place on the dashboard.
|
|
9
|
+
*
|
|
10
|
+
* What it changes is presentation for every member, never access: a tile a member may not read stays hidden from them
|
|
11
|
+
* whatever is saved here. The backend decides each write and records it, with the tiles before and after.
|
|
12
|
+
*
|
|
13
|
+
* Built from the engine's own controls (Dialog, Button, Switch, Select, Text, Alert); every word is a key of
|
|
14
|
+
* `ChartDashboardLayoutEditor.labels.ts`, and the tile names are the chart views' own titles.
|
|
15
|
+
*/
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import type { ChartDashboardTile } from './ChartDashboard';
|
|
18
|
+
import type { ChartDashboardLayoutHandle } from './useChartDashboardLayout';
|
|
19
|
+
export interface ChartDashboardLayoutEditorProps {
|
|
20
|
+
/** The dashboard's DECLARED tiles. */
|
|
21
|
+
tiles: readonly ChartDashboardTile[];
|
|
22
|
+
/** The organization's layout of the dashboard, and the doors to change it. */
|
|
23
|
+
layout: ChartDashboardLayoutHandle;
|
|
24
|
+
/** Called once the arrangement is saved or reset, or the editor is cancelled. */
|
|
25
|
+
onDone: () => void;
|
|
26
|
+
}
|
|
27
|
+
/** The editor's body: one row per declared tile, and save / reset / cancel. See the module comment. */
|
|
28
|
+
export declare function ChartDashboardLayoutEditor({ tiles, layout, onDone }: ChartDashboardLayoutEditorProps): React.JSX.Element | null;
|
|
29
|
+
/**
|
|
30
|
+
* The dashboard's "customize" button and the dialog it opens. Rendered by `ChartDashboard` only for a viewer who may
|
|
31
|
+
* arrange the dashboard for the organization (`ChartDashboardLayoutHandle.canEdit`).
|
|
32
|
+
*/
|
|
33
|
+
export declare function ChartDashboardLayoutControl({ tiles, layout }: {
|
|
34
|
+
tiles: readonly ChartDashboardTile[];
|
|
35
|
+
layout: ChartDashboardLayoutHandle;
|
|
36
|
+
}): React.JSX.Element | null;
|
|
37
|
+
//# sourceMappingURL=ChartDashboardLayoutEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartDashboardLayoutEditor.d.ts","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/ChartDashboardLayoutEditor.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAyC,MAAM,OAAO,CAAC;AAoB9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAO3D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAuB5E,MAAM,WAAW,+BAA+B;IAC9C,sCAAsC;IACtC,KAAK,EAAE,SAAS,kBAAkB,EAAE,CAAC;IACrC,8EAA8E;IAC9E,MAAM,EAAE,0BAA0B,CAAC;IACnC,iFAAiF;IACjF,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,uGAAuG;AACvG,wBAAgB,0BAA0B,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,+BAA+B,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CA+H/H;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;IAAE,KAAK,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAAC,MAAM,EAAE,0BAA0B,CAAA;CAAE,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAsBrK"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The chart dashboard's layout editor (#2299): an organization administrator reorders a dashboard's tiles, sizes each,
|
|
4
|
+
* hides some, and saves the arrangement for the whole organization; or resets it to the layout the application declares.
|
|
5
|
+
*
|
|
6
|
+
* Opened from the dashboard itself ({@link ChartDashboardLayoutControl}, rendered by `ChartDashboard` above its grid for a
|
|
7
|
+
* viewer who may write the organization's `organizationDashboardLayouts`). The list is every DECLARED tile, in the
|
|
8
|
+
* dashboard's current order ({@link arrangeChartDashboardTiles}, the function the dashboard renders with), hidden ones
|
|
9
|
+
* included so they can be shown again; it is never a list of charts the application did not place on the dashboard.
|
|
10
|
+
*
|
|
11
|
+
* What it changes is presentation for every member, never access: a tile a member may not read stays hidden from them
|
|
12
|
+
* whatever is saved here. The backend decides each write and records it, with the tiles before and after.
|
|
13
|
+
*
|
|
14
|
+
* Built from the engine's own controls (Dialog, Button, Switch, Select, Text, Alert); every word is a key of
|
|
15
|
+
* `ChartDashboardLayoutEditor.labels.ts`, and the tile names are the chart views' own titles.
|
|
16
|
+
*/
|
|
17
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { ChartDashboardTileRows, ChartDashboardTileSpan } from '@wildo-ai/saas-models';
|
|
20
|
+
import { ButtonSize, FrontendComponentType, NavigationViewLabelFamily, TypographyVariant } from '@wildo-ai/presets-components-models';
|
|
21
|
+
import { useI18n } from '../../../core/i18n/useI18n.js';
|
|
22
|
+
import { useIconRegistry } from '../../../core/icons/useIconRegistry.js';
|
|
23
|
+
import { IconSize, StandardIconReference } from '../../../core/icons/icon-registry.frontend.schemas.js';
|
|
24
|
+
import { Button, ButtonVariants_Variant } from '../../../components/actions/button.js';
|
|
25
|
+
import { Switch } from '../../../components/form/controls/boolean/switch.js';
|
|
26
|
+
import { Select } from '../../../components/form/controls/enum/select.js';
|
|
27
|
+
import { Text } from '../../../components/typography/text.js';
|
|
28
|
+
import { Alert, AlertDescription } from '../../../components/overlays/containers/alert.js';
|
|
29
|
+
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '../../../components/overlays/containers/dialog.js';
|
|
30
|
+
import { arrangeChartDashboardTiles, resizeChartDashboardTile, storedLayoutTilesOf, } from './chart-dashboard-layout.utils.js';
|
|
31
|
+
const COMPONENT = FrontendComponentType.HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR;
|
|
32
|
+
const SPAN_SCHEMA = z.enum(ChartDashboardTileSpan);
|
|
33
|
+
const ROWS_SCHEMA = z.enum(ChartDashboardTileRows);
|
|
34
|
+
const SPANS = Object.values(ChartDashboardTileSpan);
|
|
35
|
+
const ROWS = Object.values(ChartDashboardTileRows);
|
|
36
|
+
/** The key a tile row is known by in the editor: the one the dashboard and the stored layout know it by. */
|
|
37
|
+
function tileKey(tile) {
|
|
38
|
+
return `${tile.resourceType}:${tile.chartViewRef}`;
|
|
39
|
+
}
|
|
40
|
+
/** Move `items[index]` by `offset` places, when the target place exists. */
|
|
41
|
+
function moved(items, index, offset) {
|
|
42
|
+
const target = index + offset;
|
|
43
|
+
if (target < 0 || target >= items.length)
|
|
44
|
+
return [...items];
|
|
45
|
+
const next = [...items];
|
|
46
|
+
const [item] = next.splice(index, 1);
|
|
47
|
+
next.splice(target, 0, item);
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
/** The editor's body: one row per declared tile, and save / reset / cancel. See the module comment. */
|
|
51
|
+
export function ChartDashboardLayoutEditor({ tiles, layout, onDone }) {
|
|
52
|
+
const { tComponent, tView, isReady } = useI18n({ component: COMPONENT });
|
|
53
|
+
const { renderIcon } = useIconRegistry();
|
|
54
|
+
const t = useCallback((key, params) => tComponent(COMPONENT, key, params), [tComponent]);
|
|
55
|
+
const [arrangement, setArrangement] = useState(() => arrangeChartDashboardTiles(tiles, layout.stored?.tiles));
|
|
56
|
+
const [busy, setBusy] = useState(false);
|
|
57
|
+
const [failed, setFailed] = useState(false);
|
|
58
|
+
const update = useCallback((index, change) => {
|
|
59
|
+
setArrangement((current) => current.map((entry, position) => (position === index ? change(entry) : entry)));
|
|
60
|
+
}, []);
|
|
61
|
+
const run = useCallback(async (write) => {
|
|
62
|
+
setBusy(true);
|
|
63
|
+
setFailed(false);
|
|
64
|
+
try {
|
|
65
|
+
await write();
|
|
66
|
+
onDone();
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// Nothing changed: the dialog stays open with the arrangement as edited, and says so.
|
|
70
|
+
setFailed(true);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
setBusy(false);
|
|
74
|
+
}
|
|
75
|
+
}, [onDone]);
|
|
76
|
+
const spanOptions = useMemo(() => SPANS.map((value) => ({ value, label: t(`span_${value}`) })), [t]);
|
|
77
|
+
const rowsOptions = useMemo(() => ROWS.map((value) => ({ value, label: t(`rows_${value}`) })), [t]);
|
|
78
|
+
if (!isReady)
|
|
79
|
+
return null;
|
|
80
|
+
return (_jsxs("div", { className: "flex flex-col gap-group", "data-chart-dashboard-layout-editor": true, children: [_jsx("ol", { className: "flex flex-col gap-element", children: arrangement.map((entry, index) => {
|
|
81
|
+
const key = tileKey(entry.tile);
|
|
82
|
+
const name = tView(NavigationViewLabelFamily.CHART, `resources.${entry.tile.resourceType}.${entry.tile.chartViewRef}`, 'title') || key;
|
|
83
|
+
const span = entry.tile.span ?? ChartDashboardTileSpan.ONE;
|
|
84
|
+
const rows = entry.tile.rows ?? ChartDashboardTileRows.ONE;
|
|
85
|
+
return (_jsxs("li", { className: "flex flex-wrap items-center gap-item", "data-chart-dashboard-layout-tile": key, "data-hidden": entry.hidden ? '' : undefined, children: [_jsxs("div", { className: "flex shrink-0 flex-col", children: [_jsx(Button, { type: "button", variant: ButtonVariants_Variant.GHOST, size: ButtonSize.ICON_SM, "aria-label": t('moveUp'), disabled: busy || index === 0, onClick: () => setArrangement((current) => moved(current, index, -1)), children: renderIcon(StandardIconReference.CHEVRON_UP, { size: IconSize.XS }) }), _jsx(Button, { type: "button", variant: ButtonVariants_Variant.GHOST, size: ButtonSize.ICON_SM, "aria-label": t('moveDown'), disabled: busy || index === arrangement.length - 1, onClick: () => setArrangement((current) => moved(current, index, 1)), children: renderIcon(StandardIconReference.CHEVRON_DOWN, { size: IconSize.XS }) })] }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx(Text, { as: "div", typography: TypographyVariant.BODY, children: name }), _jsx(Text, { as: "div", typography: TypographyVariant.DESCRIPTION, children: t('tilePosition', { position: index + 1, count: arrangement.length }) })] }), _jsx(Switch, { name: `${key}:shown`, schema: z.boolean(), "aria-label": t('shownLabel'), checked: !entry.hidden, disabled: busy, onCheckedChange: (shown) => update(index, (current) => ({ ...current, hidden: !shown })) }), _jsxs("div", { className: "flex flex-col gap-item-xs", children: [_jsx(Text, { as: "div", typography: TypographyVariant.DESCRIPTION, children: t('widthLabel') }), _jsx(Select, { name: `${key}:span`, schema: SPAN_SCHEMA, options: spanOptions, value: span, disabled: busy, onChange: (value) => update(index, (current) => ({ ...current, tile: resizeChartDashboardTile(current.declared, SPAN_SCHEMA.parse(value), rows) })) })] }), _jsxs("div", { className: "flex flex-col gap-item-xs", children: [_jsx(Text, { as: "div", typography: TypographyVariant.DESCRIPTION, children: t('heightLabel') }), _jsx(Select, { name: `${key}:rows`, schema: ROWS_SCHEMA, options: rowsOptions, value: rows, disabled: busy, onChange: (value) => update(index, (current) => ({ ...current, tile: resizeChartDashboardTile(current.declared, span, ROWS_SCHEMA.parse(value)) })) })] })] }, key));
|
|
86
|
+
}) }), failed && (_jsx(Alert, { variant: "destructive", children: _jsx(AlertDescription, { children: t('saveFailed') }) })), _jsxs(DialogFooter, { children: [layout.stored && (_jsx(Button, { type: "button", variant: ButtonVariants_Variant.OUTLINE, disabled: busy, onClick: () => void run(layout.reset), "data-chart-dashboard-layout-reset": true, children: t('resetButton') })), _jsx(Button, { type: "button", variant: ButtonVariants_Variant.GHOST, disabled: busy, onClick: onDone, children: t('cancelButton') }), _jsx(Button, { type: "button", variant: ButtonVariants_Variant.DEFAULT, loading: busy, disabled: busy, onClick: () => void run(() => layout.save(storedLayoutTilesOf(arrangement))), "data-chart-dashboard-layout-save": true, children: t('saveButton') })] })] }));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The dashboard's "customize" button and the dialog it opens. Rendered by `ChartDashboard` only for a viewer who may
|
|
90
|
+
* arrange the dashboard for the organization (`ChartDashboardLayoutHandle.canEdit`).
|
|
91
|
+
*/
|
|
92
|
+
export function ChartDashboardLayoutControl({ tiles, layout }) {
|
|
93
|
+
const { tComponent, isReady } = useI18n({ component: COMPONENT });
|
|
94
|
+
const [open, setOpen] = useState(false);
|
|
95
|
+
const close = useCallback(() => setOpen(false), []);
|
|
96
|
+
if (!isReady)
|
|
97
|
+
return null;
|
|
98
|
+
return (_jsxs("div", { className: "flex justify-end", "data-chart-dashboard-layout-control": true, children: [_jsx(Button, { type: "button", variant: ButtonVariants_Variant.GHOST, size: ButtonSize.SM, onClick: () => setOpen(true), "data-chart-dashboard-layout-open": true, children: tComponent(COMPONENT, 'customizeButton') }), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: tComponent(COMPONENT, 'title') }), _jsx(DialogDescription, { children: tComponent(COMPONENT, 'description') })] }), open && _jsx(ChartDashboardLayoutEditor, { tiles: tiles, layout: layout, onDone: close })] }) })] }));
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=ChartDashboardLayoutEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartDashboardLayoutEditor.js","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/ChartDashboardLayoutEditor.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAc,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACtI,OAAO,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,+DAA+D,CAAC;AAChH,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,6DAA6D,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,0DAA0D,CAAC;AAClF,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I,IAAI,KAAC,0BAA0B,IAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAI,IACtE,GACT,IACL,CACP,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The chart dashboard's layout editor (#2299): an organization administrator reorders a dashboard's tiles, sizes each,\n * hides some, and saves the arrangement for the whole organization; or resets it to the layout the application declares.\n *\n * Opened from the dashboard itself ({@link ChartDashboardLayoutControl}, rendered by `ChartDashboard` above its grid for a\n * viewer who may write the organization's `organizationDashboardLayouts`). The list is every DECLARED tile, in the\n * dashboard's current order ({@link arrangeChartDashboardTiles}, the function the dashboard renders with), hidden ones\n * included so they can be shown again; it is never a list of charts the application did not place on the dashboard.\n *\n * What it changes is presentation for every member, never access: a tile a member may not read stays hidden from them\n * whatever is saved here. The backend decides each write and records it, with the tiles before and after.\n *\n * Built from the engine's own controls (Dialog, Button, Switch, Select, Text, Alert); every word is a key of\n * `ChartDashboardLayoutEditor.labels.ts`, and the tile names are the chart views' own titles.\n */\n\nimport React, { useCallback, useMemo, useState } from 'react';\nimport { z } from 'zod';\nimport { ChartDashboardTileRows, ChartDashboardTileSpan } from '@wildo-ai/saas-models';\nimport { ButtonSize, FrontendComponentType, NavigationViewLabelFamily, TypographyVariant } from '@wildo-ai/presets-components-models';\nimport { useI18n } from '~wildo-frontend-lib/core/i18n/useI18n';\nimport { useIconRegistry } from '~wildo-frontend-lib/core/icons/useIconRegistry';\nimport { IconSize, StandardIconReference } from '~wildo-frontend-lib/core/icons/icon-registry.frontend.schemas';\nimport { Button, ButtonVariants_Variant } from '~wildo-frontend-lib/components/actions/button';\nimport { Switch } from '~wildo-frontend-lib/components/form/controls/boolean/switch';\nimport { Select } from '~wildo-frontend-lib/components/form/controls/enum/select';\nimport { Text } from '~wildo-frontend-lib/components/typography/text';\nimport { Alert, AlertDescription } from '~wildo-frontend-lib/components/overlays/containers/alert';\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '~wildo-frontend-lib/components/overlays/containers/dialog';\nimport type { ChartDashboardTile } from './ChartDashboard';\nimport {\n arrangeChartDashboardTiles,\n resizeChartDashboardTile,\n storedLayoutTilesOf,\n type ArrangedChartDashboardTile,\n} from './chart-dashboard-layout.utils';\nimport type { ChartDashboardLayoutHandle } from './useChartDashboardLayout';\n\nconst COMPONENT = FrontendComponentType.HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR;\nconst SPAN_SCHEMA = z.enum(ChartDashboardTileSpan);\nconst ROWS_SCHEMA = z.enum(ChartDashboardTileRows);\nconst SPANS: readonly ChartDashboardTileSpan[] = Object.values(ChartDashboardTileSpan);\nconst ROWS: readonly ChartDashboardTileRows[] = Object.values(ChartDashboardTileRows);\n\n/** The key a tile row is known by in the editor: the one the dashboard and the stored layout know it by. */\nfunction tileKey(tile: ChartDashboardTile): string {\n return `${tile.resourceType}:${tile.chartViewRef}`;\n}\n\n/** Move `items[index]` by `offset` places, when the target place exists. */\nfunction moved<T>(items: readonly T[], index: number, offset: number): T[] {\n const target = index + offset;\n if (target < 0 || target >= items.length) return [...items];\n const next = [...items];\n const [item] = next.splice(index, 1);\n next.splice(target, 0, item!);\n return next;\n}\n\nexport interface ChartDashboardLayoutEditorProps {\n /** The dashboard's DECLARED tiles. */\n tiles: readonly ChartDashboardTile[];\n /** The organization's layout of the dashboard, and the doors to change it. */\n layout: ChartDashboardLayoutHandle;\n /** Called once the arrangement is saved or reset, or the editor is cancelled. */\n onDone: () => void;\n}\n\n/** The editor's body: one row per declared tile, and save / reset / cancel. See the module comment. */\nexport function ChartDashboardLayoutEditor({ tiles, layout, onDone }: ChartDashboardLayoutEditorProps): React.JSX.Element | null {\n const { tComponent, tView, isReady } = useI18n({ component: COMPONENT });\n const { renderIcon } = useIconRegistry();\n const t = useCallback((key: string, params?: Record<string, string | number>) => tComponent(COMPONENT, key, params), [tComponent]);\n const [arrangement, setArrangement] = useState<ArrangedChartDashboardTile[]>(() => arrangeChartDashboardTiles(tiles, layout.stored?.tiles));\n const [busy, setBusy] = useState(false);\n const [failed, setFailed] = useState(false);\n\n const update = useCallback((index: number, change: (entry: ArrangedChartDashboardTile) => ArrangedChartDashboardTile) => {\n setArrangement((current) => current.map((entry, position) => (position === index ? change(entry) : entry)));\n }, []);\n\n const run = useCallback(async (write: () => Promise<void>) => {\n setBusy(true);\n setFailed(false);\n try {\n await write();\n onDone();\n } catch {\n // Nothing changed: the dialog stays open with the arrangement as edited, and says so.\n setFailed(true);\n } finally {\n setBusy(false);\n }\n }, [onDone]);\n\n const spanOptions = useMemo(() => SPANS.map((value) => ({ value, label: t(`span_${value}`) })), [t]);\n const rowsOptions = useMemo(() => ROWS.map((value) => ({ value, label: t(`rows_${value}`) })), [t]);\n\n if (!isReady) return null;\n return (\n <div className=\"flex flex-col gap-group\" data-chart-dashboard-layout-editor>\n <ol className=\"flex flex-col gap-element\">\n {arrangement.map((entry, index) => {\n const key = tileKey(entry.tile);\n const name = tView(NavigationViewLabelFamily.CHART, `resources.${entry.tile.resourceType}.${entry.tile.chartViewRef}`, 'title') || key;\n const span = entry.tile.span ?? ChartDashboardTileSpan.ONE;\n const rows = entry.tile.rows ?? ChartDashboardTileRows.ONE;\n return (\n <li key={key} className=\"flex flex-wrap items-center gap-item\" data-chart-dashboard-layout-tile={key} data-hidden={entry.hidden ? '' : undefined}>\n <div className=\"flex shrink-0 flex-col\">\n <Button\n type=\"button\"\n variant={ButtonVariants_Variant.GHOST}\n size={ButtonSize.ICON_SM}\n aria-label={t('moveUp')}\n disabled={busy || index === 0}\n onClick={() => setArrangement((current) => moved(current, index, -1))}\n >\n {renderIcon(StandardIconReference.CHEVRON_UP, { size: IconSize.XS })}\n </Button>\n <Button\n type=\"button\"\n variant={ButtonVariants_Variant.GHOST}\n size={ButtonSize.ICON_SM}\n aria-label={t('moveDown')}\n disabled={busy || index === arrangement.length - 1}\n onClick={() => setArrangement((current) => moved(current, index, 1))}\n >\n {renderIcon(StandardIconReference.CHEVRON_DOWN, { size: IconSize.XS })}\n </Button>\n </div>\n <div className=\"flex min-w-0 flex-1 flex-col\">\n <Text as=\"div\" typography={TypographyVariant.BODY}>{name}</Text>\n <Text as=\"div\" typography={TypographyVariant.DESCRIPTION}>{t('tilePosition', { position: index + 1, count: arrangement.length })}</Text>\n </div>\n <Switch\n name={`${key}:shown`}\n schema={z.boolean()}\n aria-label={t('shownLabel')}\n checked={!entry.hidden}\n disabled={busy}\n onCheckedChange={(shown) => update(index, (current) => ({ ...current, hidden: !shown }))}\n />\n <div className=\"flex flex-col gap-item-xs\">\n <Text as=\"div\" typography={TypographyVariant.DESCRIPTION}>{t('widthLabel')}</Text>\n <Select\n name={`${key}:span`}\n schema={SPAN_SCHEMA}\n options={spanOptions}\n value={span}\n disabled={busy}\n onChange={(value) => update(index, (current) => ({ ...current, tile: resizeChartDashboardTile(current.declared, SPAN_SCHEMA.parse(value), rows) }))}\n />\n </div>\n <div className=\"flex flex-col gap-item-xs\">\n <Text as=\"div\" typography={TypographyVariant.DESCRIPTION}>{t('heightLabel')}</Text>\n <Select\n name={`${key}:rows`}\n schema={ROWS_SCHEMA}\n options={rowsOptions}\n value={rows}\n disabled={busy}\n onChange={(value) => update(index, (current) => ({ ...current, tile: resizeChartDashboardTile(current.declared, span, ROWS_SCHEMA.parse(value)) }))}\n />\n </div>\n </li>\n );\n })}\n </ol>\n {failed && (\n <Alert variant=\"destructive\">\n <AlertDescription>{t('saveFailed')}</AlertDescription>\n </Alert>\n )}\n <DialogFooter>\n {layout.stored && (\n <Button type=\"button\" variant={ButtonVariants_Variant.OUTLINE} disabled={busy} onClick={() => void run(layout.reset)} data-chart-dashboard-layout-reset>\n {t('resetButton')}\n </Button>\n )}\n <Button type=\"button\" variant={ButtonVariants_Variant.GHOST} disabled={busy} onClick={onDone}>\n {t('cancelButton')}\n </Button>\n <Button\n type=\"button\"\n variant={ButtonVariants_Variant.DEFAULT}\n loading={busy}\n disabled={busy}\n onClick={() => void run(() => layout.save(storedLayoutTilesOf(arrangement)))}\n data-chart-dashboard-layout-save\n >\n {t('saveButton')}\n </Button>\n </DialogFooter>\n </div>\n );\n}\n\n/**\n * The dashboard's \"customize\" button and the dialog it opens. Rendered by `ChartDashboard` only for a viewer who may\n * arrange the dashboard for the organization (`ChartDashboardLayoutHandle.canEdit`).\n */\nexport function ChartDashboardLayoutControl({ tiles, layout }: { tiles: readonly ChartDashboardTile[]; layout: ChartDashboardLayoutHandle }): React.JSX.Element | null {\n const { tComponent, isReady } = useI18n({ component: COMPONENT });\n const [open, setOpen] = useState(false);\n const close = useCallback(() => setOpen(false), []);\n if (!isReady) return null;\n return (\n <div className=\"flex justify-end\" data-chart-dashboard-layout-control>\n <Button type=\"button\" variant={ButtonVariants_Variant.GHOST} size={ButtonSize.SM} onClick={() => setOpen(true)} data-chart-dashboard-layout-open>\n {tComponent(COMPONENT, 'customizeButton')}\n </Button>\n <Dialog open={open} onOpenChange={setOpen}>\n <DialogContent>\n <DialogHeader>\n <DialogTitle>{tComponent(COMPONENT, 'title')}</DialogTitle>\n <DialogDescription>{tComponent(COMPONENT, 'description')}</DialogDescription>\n </DialogHeader>\n {/* Mounted only while open, so each opening starts from the layout as it stands now. */}\n {open && <ChartDashboardLayoutEditor tiles={tiles} layout={layout} onDone={close} />}\n </DialogContent>\n </Dialog>\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartDashboardLayoutEditor.labels.d.ts","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/ChartDashboardLayoutEditor.labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,qCAAqC,CAAC;AAQ7C,eAAO,MAAM,8CAA8C,EAAE,mBAAmB,EAwB/E,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FrontendComponentType, LabelKind, registerComponentLabels, } from '@wildo-ai/presets-components-models';
|
|
2
|
+
// Statically scanned by the dev companion to generate the `components.HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR.*`
|
|
3
|
+
// bundle; NOT imported at runtime, so it never ships in the browser bundle. Keep in lock-step with the keys the editor
|
|
4
|
+
// and the dashboard read via `tComponent(HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR, ...)`.
|
|
5
|
+
//
|
|
6
|
+
// The size words are literal refs, one per member of `ChartDashboardTileSpan` (`span_<value>`) and of
|
|
7
|
+
// `ChartDashboardTileRows` (`rows_<value>`): the scan reads literals.
|
|
8
|
+
export const HighLevelViewsChartDashboardLayoutEditorLabels = [
|
|
9
|
+
{ ref: 'customizeButton', kind: LabelKind.BUTTON, purpose: 'Button above a dashboard of charts, shown to an organization administrator, that opens the editor arranging the dashboard for the whole organization' },
|
|
10
|
+
{ ref: 'title', kind: LabelKind.HEADING, purpose: 'Heading of the dialog that arranges a dashboard of charts for the organization' },
|
|
11
|
+
{ ref: 'description', kind: LabelKind.DESCRIPTION, purpose: 'One sentence under the heading: the order, size and visibility chosen here apply to every member of the organization, and a member still sees only the charts they may read' },
|
|
12
|
+
{
|
|
13
|
+
ref: 'tilePosition',
|
|
14
|
+
kind: LabelKind.MESSAGE,
|
|
15
|
+
params: [{ key: 'position', meaning: 'the tile\'s place on the dashboard, from 1' }, { key: 'count', meaning: 'how many tiles the dashboard has' }],
|
|
16
|
+
purpose: 'Small text beside a tile\'s name saying where it sits: tile {position} of {count}',
|
|
17
|
+
},
|
|
18
|
+
{ ref: 'moveUp', kind: LabelKind.BUTTON, purpose: 'Accessible name of the button that moves a chart one place earlier on the dashboard' },
|
|
19
|
+
{ ref: 'moveDown', kind: LabelKind.BUTTON, purpose: 'Accessible name of the button that moves a chart one place later on the dashboard' },
|
|
20
|
+
{ ref: 'shownLabel', kind: LabelKind.LABEL, purpose: 'Label of the switch that shows or hides a chart on the organization\'s dashboard' },
|
|
21
|
+
{ ref: 'widthLabel', kind: LabelKind.LABEL, purpose: 'Label of the chooser of how wide a chart is on the dashboard' },
|
|
22
|
+
{ ref: 'heightLabel', kind: LabelKind.LABEL, purpose: 'Label of the chooser of how tall a chart is on the dashboard' },
|
|
23
|
+
{ ref: 'span_one', kind: LabelKind.LABEL, purpose: 'Width choice: the chart takes one column' },
|
|
24
|
+
{ ref: 'span_two', kind: LabelKind.LABEL, purpose: 'Width choice: the chart takes two columns' },
|
|
25
|
+
{ ref: 'span_full', kind: LabelKind.LABEL, purpose: 'Width choice: the chart takes the whole row' },
|
|
26
|
+
{ ref: 'rows_one', kind: LabelKind.LABEL, purpose: 'Height choice: the chart takes one row' },
|
|
27
|
+
{ ref: 'rows_two', kind: LabelKind.LABEL, purpose: 'Height choice: the chart takes two rows' },
|
|
28
|
+
{ ref: 'saveButton', kind: LabelKind.BUTTON, purpose: 'Button that saves the arrangement as the organization\'s layout of the dashboard' },
|
|
29
|
+
{ ref: 'resetButton', kind: LabelKind.BUTTON, purpose: 'Button that drops the organization\'s arrangement, so the dashboard shows the charts as the application lays them out' },
|
|
30
|
+
{ ref: 'cancelButton', kind: LabelKind.BUTTON, purpose: 'Button that closes the editor without saving' },
|
|
31
|
+
{ ref: 'saveFailed', kind: LabelKind.MESSAGE, purpose: 'Shown when the arrangement could not be saved or reset; nothing changed' },
|
|
32
|
+
];
|
|
33
|
+
registerComponentLabels(FrontendComponentType.HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR, HighLevelViewsChartDashboardLayoutEditorLabels);
|
|
34
|
+
//# sourceMappingURL=ChartDashboardLayoutEditor.labels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartDashboardLayoutEditor.labels.js","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/ChartDashboardLayoutEditor.labels.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,SAAS,EAET,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAE7C,wHAAwH;A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E,0CAA0C,EAAE;IAC/F,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,2CAA2C,EAAE;IAChG,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,6CAA6C,EAAE;IACnG,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,wCAAwC,EAAE;IAC7F,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,yCAAyC,EAAE;IAC9F,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,kFAAkF,EAAE;IAC1I,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,uHAAuH,EAAE;IAChL,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,8CAA8C,EAAE;IACxG,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,yEAAyE,EAAE;CACnI,CAAC;AAEF,uBAAuB,CAAC,qBAAqB,CAAC,8CAA8C,EAAE,8CAA8C,CAAC,CAAC","sourcesContent":["import {\n FrontendComponentType,\n LabelKind,\n type LabellingUnitaryDef,\n registerComponentLabels,\n} from '@wildo-ai/presets-components-models';\n\n// Statically scanned by the dev companion to generate the `components.HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR.*`\n// bundle; NOT imported at runtime, so it never ships in the browser bundle. Keep in lock-step with the keys the editor\n// and the dashboard read via `tComponent(HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR, ...)`.\n//\n// The size words are literal refs, one per member of `ChartDashboardTileSpan` (`span_<value>`) and of\n// `ChartDashboardTileRows` (`rows_<value>`): the scan reads literals.\nexport const HighLevelViewsChartDashboardLayoutEditorLabels: LabellingUnitaryDef[] = [\n { ref: 'customizeButton', kind: LabelKind.BUTTON, purpose: 'Button above a dashboard of charts, shown to an organization administrator, that opens the editor arranging the dashboard for the whole organization' },\n { ref: 'title', kind: LabelKind.HEADING, purpose: 'Heading of the dialog that arranges a dashboard of charts for the organization' },\n { ref: 'description', kind: LabelKind.DESCRIPTION, purpose: 'One sentence under the heading: the order, size and visibility chosen here apply to every member of the organization, and a member still sees only the charts they may read' },\n {\n ref: 'tilePosition',\n kind: LabelKind.MESSAGE,\n params: [{ key: 'position', meaning: 'the tile\\'s place on the dashboard, from 1' }, { key: 'count', meaning: 'how many tiles the dashboard has' }],\n purpose: 'Small text beside a tile\\'s name saying where it sits: tile {position} of {count}',\n },\n { ref: 'moveUp', kind: LabelKind.BUTTON, purpose: 'Accessible name of the button that moves a chart one place earlier on the dashboard' },\n { ref: 'moveDown', kind: LabelKind.BUTTON, purpose: 'Accessible name of the button that moves a chart one place later on the dashboard' },\n { ref: 'shownLabel', kind: LabelKind.LABEL, purpose: 'Label of the switch that shows or hides a chart on the organization\\'s dashboard' },\n { ref: 'widthLabel', kind: LabelKind.LABEL, purpose: 'Label of the chooser of how wide a chart is on the dashboard' },\n { ref: 'heightLabel', kind: LabelKind.LABEL, purpose: 'Label of the chooser of how tall a chart is on the dashboard' },\n { ref: 'span_one', kind: LabelKind.LABEL, purpose: 'Width choice: the chart takes one column' },\n { ref: 'span_two', kind: LabelKind.LABEL, purpose: 'Width choice: the chart takes two columns' },\n { ref: 'span_full', kind: LabelKind.LABEL, purpose: 'Width choice: the chart takes the whole row' },\n { ref: 'rows_one', kind: LabelKind.LABEL, purpose: 'Height choice: the chart takes one row' },\n { ref: 'rows_two', kind: LabelKind.LABEL, purpose: 'Height choice: the chart takes two rows' },\n { ref: 'saveButton', kind: LabelKind.BUTTON, purpose: 'Button that saves the arrangement as the organization\\'s layout of the dashboard' },\n { ref: 'resetButton', kind: LabelKind.BUTTON, purpose: 'Button that drops the organization\\'s arrangement, so the dashboard shows the charts as the application lays them out' },\n { ref: 'cancelButton', kind: LabelKind.BUTTON, purpose: 'Button that closes the editor without saving' },\n { ref: 'saveFailed', kind: LabelKind.MESSAGE, purpose: 'Shown when the arrangement could not be saved or reset; nothing changed' },\n];\n\nregisterComponentLabels(FrontendComponentType.HIGH_LEVEL_VIEWS_CHART_DASHBOARD_LAYOUT_EDITOR, HighLevelViewsChartDashboardLayoutEditorLabels);\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an organization's stored layout arranges a chart dashboard's DECLARED tiles (#2299).
|
|
3
|
+
*
|
|
4
|
+
* The application declares the tiles (`ChartDashboard`'s `tiles`); an organization's administrators may store a layout
|
|
5
|
+
* for the dashboard (`organizationDashboardLayouts`, one row per organization and `layoutRef`). The layout only ARRANGES
|
|
6
|
+
* what was declared:
|
|
7
|
+
*
|
|
8
|
+
* - the stored order wins, for every tile it names;
|
|
9
|
+
* - a stored entry naming a tile the dashboard does not declare is ignored: a layout cannot add a chart, so a chart an
|
|
10
|
+
* application removed does not come back, and a row written by hand cannot place one the application never placed;
|
|
11
|
+
* - a declared tile the layout does not name (declared after the layout was saved) is shown, after the stored ones, at
|
|
12
|
+
* its declared size: hiding a new chart is the administrator's decision, never an accident of when they saved;
|
|
13
|
+
* - a hidden tile is left out. And a tile still shows only to a viewer who may read its chart: the gate runs on what this
|
|
14
|
+
* function returns ({@link viewerMayReadChart}), so no layout shows a chart its viewer would be refused.
|
|
15
|
+
*
|
|
16
|
+
* Pure: the dashboard and the layout editor both read it, so the editor's list is the dashboard's order by construction.
|
|
17
|
+
*/
|
|
18
|
+
import { ChartDashboardTileRows, ChartDashboardTileSpan, type OrganizationDashboardLayoutTile } from '@wildo-ai/saas-models';
|
|
19
|
+
import type { ChartDashboardTile } from './ChartDashboard';
|
|
20
|
+
/**
|
|
21
|
+
* The vertical gap between two grid rows, in px, at the default theme density (`gap-group`). A tile made two rows tall
|
|
22
|
+
* by a layout gets a canvas of two of its one-row canvases plus this gap, and the reverse; a denser theme leaves the
|
|
23
|
+
* canvas a few pixels off its cell, which the chart tolerates.
|
|
24
|
+
*/
|
|
25
|
+
export declare const CHART_DASHBOARD_ROW_GAP_PX = 32;
|
|
26
|
+
/** One declared tile as the layout arranges it, hidden ones included (the editor lists them). */
|
|
27
|
+
export interface ArrangedChartDashboardTile {
|
|
28
|
+
/** The tile as the dashboard will render it: the declared tile with the layout's size. */
|
|
29
|
+
tile: ChartDashboardTile;
|
|
30
|
+
/** The tile as the application declared it, before the layout. */
|
|
31
|
+
declared: ChartDashboardTile;
|
|
32
|
+
hidden: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The declared tile resized to `span` and `rows`, its canvas height following its rows. */
|
|
35
|
+
export declare function resizeChartDashboardTile(declared: ChartDashboardTile, span: ChartDashboardTileSpan, rows: ChartDashboardTileRows): ChartDashboardTile;
|
|
36
|
+
/**
|
|
37
|
+
* Every declared tile, in the order the layout gives it and at the size it gives it, hidden ones flagged. With no
|
|
38
|
+
* layout, the declared tiles as declared.
|
|
39
|
+
*/
|
|
40
|
+
export declare function arrangeChartDashboardTiles(declaredTiles: readonly ChartDashboardTile[], storedTiles: readonly OrganizationDashboardLayoutTile[] | undefined): ArrangedChartDashboardTile[];
|
|
41
|
+
/** The tiles a layout leaves on the dashboard, in its order: {@link arrangeChartDashboardTiles} without the hidden ones. */
|
|
42
|
+
export declare function visibleChartDashboardTiles(declaredTiles: readonly ChartDashboardTile[], storedTiles: readonly OrganizationDashboardLayoutTile[] | undefined): ChartDashboardTile[];
|
|
43
|
+
/** The layout to store for an arrangement: every tile, in order, with an explicit size and whether it is hidden. */
|
|
44
|
+
export declare function storedLayoutTilesOf(arranged: readonly ArrangedChartDashboardTile[]): OrganizationDashboardLayoutTile[];
|
|
45
|
+
/** A chart tile's default canvas height, per rows; a KPI tile's loading placeholder (its figure sets its own height). */
|
|
46
|
+
export declare function defaultChartDashboardTileHeight(isFigure: boolean, rows: ChartDashboardTileRows | undefined): number;
|
|
47
|
+
//# sourceMappingURL=chart-dashboard-layout.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-dashboard-layout.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/views/chart-dashboard/chart-dashboard-layout.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EAEtB,KAAK,+BAA+B,EACrC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C,iGAAiG;AACjG,MAAM,WAAW,0BAA0B;IACzC,0FAA0F;IAC1F,IAAI,EAAE,kBAAkB,CAAC;IACzB,kEAAkE;IAClE,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB;AAmBD,4FAA4F;AAC5F,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,sBAAsB,EAAE,IAAI,EAAE,sBAAsB,GAAG,kBAAkB,CAIrJ;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,SAAS,kBAAkB,EAAE,EAC5C,WAAW,EAAE,SAAS,+BAA+B,EAAE,GAAG,SAAS,GAClE,0BAA0B,EAAE,CAgB9B;AAED,4HAA4H;AAC5H,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,SAAS,kBAAkB,EAAE,EAC5C,WAAW,EAAE,SAAS,+BAA+B,EAAE,GAAG,SAAS,GAClE,kBAAkB,EAAE,CAEtB;AAED,oHAAoH;AACpH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,SAAS,0BAA0B,EAAE,GAAG,+BAA+B,EAAE,CAQtH;AAED,yHAAyH;AACzH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,sBAAsB,GAAG,SAAS,GAAG,MAAM,CAGnH"}
|