@malloy-publisher/sdk 0.3.0 → 0.3.1
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/README.md +8 -0
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
- package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
- package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
- package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
- package/dist/ServerProvider-CH71GsoL.cjs.js +1 -0
- package/dist/{ServerProvider-DSK9rfSY.es.js → ServerProvider-X2Ma0HRs.es.js} +486 -521
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9561 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/Dashboard.d.ts +19 -14
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +7 -0
- package/dist/components/DocumentStorage/index.d.ts +1 -1
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +1 -0
- package/dist/components/drill/index.d.ts +1 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/index.d.ts +1 -0
- package/dist/components/styles.d.ts +0 -4
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/index.cjs.js +23 -270
- package/dist/index.es.js +16977 -41293
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/package.json +24 -9
- package/src/builder-entry.ts +55 -0
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +165 -175
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +66 -123
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +70 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +33 -2
- package/src/components/Dashboard/telemetry.ts +44 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +12 -0
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Environment/About.tsx +4 -36
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +33 -72
- package/src/components/Notebook/Notebook.tsx +25 -88
- package/src/components/Notebook/NotebookCell.tsx +35 -183
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/ResultContainer.tsx +4 -12
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +1 -0
- package/src/components/drill/index.ts +1 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/index.ts +6 -0
- package/src/components/styles.ts +0 -37
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/vite.config.ts +5 -0
- package/dist/ServerProvider-CGnLjzag.cjs.js +0 -1
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Autocomplete,
|
|
6
|
+
Box,
|
|
7
|
+
Button,
|
|
8
|
+
Checkbox,
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogActions,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogTitle,
|
|
13
|
+
MenuItem,
|
|
14
|
+
Stack,
|
|
15
|
+
TextField,
|
|
16
|
+
ToggleButton,
|
|
17
|
+
ToggleButtonGroup,
|
|
18
|
+
Tooltip,
|
|
19
|
+
Typography,
|
|
20
|
+
type SxProps,
|
|
21
|
+
type Theme,
|
|
22
|
+
} from "@mui/material";
|
|
23
|
+
import { useMemo } from "react";
|
|
24
|
+
import { titleCase, useFilterForm } from "./useFilterForm";
|
|
25
|
+
import { usePublisherTheme } from "../../theme/ThemeContext";
|
|
26
|
+
import type { CatalogField } from "./catalog";
|
|
27
|
+
import {
|
|
28
|
+
CONTROL_KINDS,
|
|
29
|
+
OPERATORS,
|
|
30
|
+
type BuilderControl,
|
|
31
|
+
type ControlKind,
|
|
32
|
+
type MappingRow,
|
|
33
|
+
} from "./controls";
|
|
34
|
+
import type { DashboardDocument, DashboardTile, LocalGiven } from "./document";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A filter control: what it is, and which tiles it drives.
|
|
38
|
+
*
|
|
39
|
+
* Two questions, asked in that order and nothing else. WHAT: its label, and
|
|
40
|
+
* the field it filters on — one field, because a control almost always filters
|
|
41
|
+
* the same field on every tile, and the case where it does not is one click
|
|
42
|
+
* away ("Adjust per tile"), not five text boxes on every open. WHICH: a list
|
|
43
|
+
* of the dashboard's tiles with a checkbox each, and one checkbox over them
|
|
44
|
+
* all. A tile that cannot take a filter says why in place.
|
|
45
|
+
*
|
|
46
|
+
* The field is SEARCHED, not typed blind, when the host has handed over the
|
|
47
|
+
* source's fields: the picker offers the dimensions the tiles' source has,
|
|
48
|
+
* an unknown name is marked as such where it stands, and Apply waits until
|
|
49
|
+
* every ticked tile's field resolves. A binding to a field that does not exist
|
|
50
|
+
* fails at package load, which is the worst place for it to fail; here it
|
|
51
|
+
* cannot be written.
|
|
52
|
+
*
|
|
53
|
+
* The same window adds, edits and removes. It opens on the mapping the control
|
|
54
|
+
* has NOW, so unticking a tile unbinds it, and a control this dashboard
|
|
55
|
+
* declares can be taken off the page from here.
|
|
56
|
+
*
|
|
57
|
+
* What it writes is the convention {@link LocalGiven} describes: a new control
|
|
58
|
+
* is a `given:` declared in this file, bound on each ticked tile as a
|
|
59
|
+
* `+ { where: field ~ $GIVEN }` refinement. A control the model declares can be
|
|
60
|
+
* bound here but not changed, since the builder never edits model files.
|
|
61
|
+
*/
|
|
62
|
+
export interface FilterDialogProps {
|
|
63
|
+
open: boolean;
|
|
64
|
+
document: DashboardDocument;
|
|
65
|
+
/** The control being edited, or undefined to add one. */
|
|
66
|
+
control?: BuilderControl;
|
|
67
|
+
/** Model givens not yet bound anywhere, offered as "from the model". */
|
|
68
|
+
available: readonly BuilderControl[];
|
|
69
|
+
/**
|
|
70
|
+
* The fields a binding on THIS tile may name: the dimensions of the source
|
|
71
|
+
* it reads. Per tile, because a composite dashboard exists to span sources,
|
|
72
|
+
* and a field one source has another may not. Undefined for a tile whose
|
|
73
|
+
* source the host has no catalog for, in which case any name is accepted
|
|
74
|
+
* for it and nothing is searched.
|
|
75
|
+
*/
|
|
76
|
+
fieldsFor?: (tile: DashboardTile) => readonly CatalogField[] | undefined;
|
|
77
|
+
onClose: () => void;
|
|
78
|
+
/**
|
|
79
|
+
* Bind a control. `declare` is set when the control is new to this file, or
|
|
80
|
+
* when its declaration changed, and is the declaration to write.
|
|
81
|
+
*/
|
|
82
|
+
onApply: (given: string, rows: MappingRow[], declare?: LocalGiven) => void;
|
|
83
|
+
/** Take a control off the dashboard; offered for one this file declares. */
|
|
84
|
+
onRemove: (given: string) => void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `BRAND` -> `Brand`: the label a new control gets if the author types none. */
|
|
88
|
+
/**
|
|
89
|
+
* A field name, searched from the source's dimensions and still free to type:
|
|
90
|
+
* the catalog may lag a model edit, and a host without one has no list at all.
|
|
91
|
+
*/
|
|
92
|
+
function FieldPicker({
|
|
93
|
+
value,
|
|
94
|
+
onChange,
|
|
95
|
+
fields,
|
|
96
|
+
accepts,
|
|
97
|
+
label,
|
|
98
|
+
ariaLabel,
|
|
99
|
+
error,
|
|
100
|
+
helperText,
|
|
101
|
+
disabled,
|
|
102
|
+
autoFocus,
|
|
103
|
+
placeholder,
|
|
104
|
+
sx,
|
|
105
|
+
}: {
|
|
106
|
+
value: string;
|
|
107
|
+
onChange: (next: string) => void;
|
|
108
|
+
fields: readonly CatalogField[] | undefined;
|
|
109
|
+
/** Which of the fields to offer; the rest are still accepted if typed. */
|
|
110
|
+
accepts?: (field: CatalogField) => boolean;
|
|
111
|
+
label: string;
|
|
112
|
+
ariaLabel: string;
|
|
113
|
+
error?: boolean;
|
|
114
|
+
helperText?: string;
|
|
115
|
+
disabled?: boolean;
|
|
116
|
+
autoFocus?: boolean;
|
|
117
|
+
placeholder?: string;
|
|
118
|
+
sx?: SxProps<Theme>;
|
|
119
|
+
}) {
|
|
120
|
+
const options = useMemo(
|
|
121
|
+
() =>
|
|
122
|
+
(fields ?? [])
|
|
123
|
+
.filter((field) => accepts?.(field) ?? true)
|
|
124
|
+
.map((field) => field.name),
|
|
125
|
+
[fields, accepts],
|
|
126
|
+
);
|
|
127
|
+
const types = useMemo(
|
|
128
|
+
() => new Map((fields ?? []).map((field) => [field.name, field.type])),
|
|
129
|
+
[fields],
|
|
130
|
+
);
|
|
131
|
+
return (
|
|
132
|
+
<Autocomplete
|
|
133
|
+
freeSolo
|
|
134
|
+
size="small"
|
|
135
|
+
options={options}
|
|
136
|
+
inputValue={value}
|
|
137
|
+
onInputChange={(_, next) => onChange(next)}
|
|
138
|
+
value={value}
|
|
139
|
+
onChange={(_, next) => onChange(typeof next === "string" ? next : "")}
|
|
140
|
+
disabled={disabled}
|
|
141
|
+
disableClearable
|
|
142
|
+
renderOption={(props, option) => (
|
|
143
|
+
<li {...props} key={option}>
|
|
144
|
+
<Typography variant="body2" sx={{ flex: 1 }}>
|
|
145
|
+
{option}
|
|
146
|
+
</Typography>
|
|
147
|
+
{types.get(option) && (
|
|
148
|
+
<Typography variant="caption" sx={{ opacity: 0.6 }}>
|
|
149
|
+
{types.get(option)?.replace(/_type$/, "")}
|
|
150
|
+
</Typography>
|
|
151
|
+
)}
|
|
152
|
+
</li>
|
|
153
|
+
)}
|
|
154
|
+
renderInput={(params) => (
|
|
155
|
+
<TextField
|
|
156
|
+
{...params}
|
|
157
|
+
label={label}
|
|
158
|
+
placeholder={placeholder}
|
|
159
|
+
autoFocus={autoFocus}
|
|
160
|
+
error={error}
|
|
161
|
+
helperText={helperText}
|
|
162
|
+
inputProps={{ ...params.inputProps, "aria-label": ariaLabel }}
|
|
163
|
+
/>
|
|
164
|
+
)}
|
|
165
|
+
sx={sx}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function FilterDialog({
|
|
171
|
+
open,
|
|
172
|
+
document,
|
|
173
|
+
control,
|
|
174
|
+
available,
|
|
175
|
+
fieldsFor,
|
|
176
|
+
onClose,
|
|
177
|
+
onApply,
|
|
178
|
+
onRemove,
|
|
179
|
+
}: FilterDialogProps) {
|
|
180
|
+
const { theme } = usePublisherTheme();
|
|
181
|
+
const {
|
|
182
|
+
editing,
|
|
183
|
+
shown,
|
|
184
|
+
fromModel,
|
|
185
|
+
source,
|
|
186
|
+
setSource,
|
|
187
|
+
label,
|
|
188
|
+
setLabel,
|
|
189
|
+
kind,
|
|
190
|
+
dateDefault,
|
|
191
|
+
setDateDefault,
|
|
192
|
+
field,
|
|
193
|
+
rows,
|
|
194
|
+
setRows,
|
|
195
|
+
perTile,
|
|
196
|
+
setPerTile,
|
|
197
|
+
newName,
|
|
198
|
+
target,
|
|
199
|
+
valueTyped,
|
|
200
|
+
commonOp,
|
|
201
|
+
setRow,
|
|
202
|
+
setCommonOp,
|
|
203
|
+
pickExisting,
|
|
204
|
+
pickKind,
|
|
205
|
+
bindable,
|
|
206
|
+
bindableCount,
|
|
207
|
+
included,
|
|
208
|
+
commonFields,
|
|
209
|
+
setAll,
|
|
210
|
+
accepts,
|
|
211
|
+
pickField,
|
|
212
|
+
rowProblems,
|
|
213
|
+
commonProblem,
|
|
214
|
+
canApply,
|
|
215
|
+
apply,
|
|
216
|
+
} = useFilterForm({
|
|
217
|
+
open,
|
|
218
|
+
document,
|
|
219
|
+
control,
|
|
220
|
+
available,
|
|
221
|
+
fieldsFor,
|
|
222
|
+
onApply,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const operatorField = (
|
|
226
|
+
value: string | undefined,
|
|
227
|
+
onChange: (op: string) => void,
|
|
228
|
+
ariaLabel: string,
|
|
229
|
+
) => (
|
|
230
|
+
<TextField
|
|
231
|
+
select
|
|
232
|
+
size="small"
|
|
233
|
+
label="Compares"
|
|
234
|
+
value={value ?? ">="}
|
|
235
|
+
onChange={(event) => onChange(event.target.value)}
|
|
236
|
+
inputProps={{ "aria-label": ariaLabel }}
|
|
237
|
+
sx={{ width: 130 }}
|
|
238
|
+
>
|
|
239
|
+
{OPERATORS.filter((o) => o.op !== "~").map((o) => (
|
|
240
|
+
<MenuItem key={o.op} value={o.op}>
|
|
241
|
+
{o.label}
|
|
242
|
+
</MenuItem>
|
|
243
|
+
))}
|
|
244
|
+
</TextField>
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth>
|
|
249
|
+
<DialogTitle sx={{ pb: 0.5 }}>
|
|
250
|
+
{editing ? (shown.label ?? shown.name) : "Add a filter"}
|
|
251
|
+
{editing && (
|
|
252
|
+
<Typography
|
|
253
|
+
component="div"
|
|
254
|
+
variant="caption"
|
|
255
|
+
sx={{ color: theme.tileTitle, mt: 0.25 }}
|
|
256
|
+
>
|
|
257
|
+
<Box
|
|
258
|
+
component="span"
|
|
259
|
+
sx={{ fontFamily: "ui-monospace, monospace" }}
|
|
260
|
+
>
|
|
261
|
+
${shown.name}
|
|
262
|
+
</Box>
|
|
263
|
+
{fromModel
|
|
264
|
+
? " · declared in the model, so its label and options are set there"
|
|
265
|
+
: " · declared in this dashboard"}
|
|
266
|
+
</Typography>
|
|
267
|
+
)}
|
|
268
|
+
</DialogTitle>
|
|
269
|
+
<DialogContent>
|
|
270
|
+
{/* Top margin on the stack, not padding on the content: MUI zeroes
|
|
271
|
+
a DialogContent's top padding after a DialogTitle with a rule
|
|
272
|
+
that outranks `sx`, and the fields' floating labels need the
|
|
273
|
+
room or they clip. */}
|
|
274
|
+
<Stack sx={{ gap: 2.5, pt: 1 }}>
|
|
275
|
+
{/* WHAT the filter is. */}
|
|
276
|
+
{!editing && available.length > 0 && (
|
|
277
|
+
<ToggleButtonGroup
|
|
278
|
+
exclusive
|
|
279
|
+
size="small"
|
|
280
|
+
value={source.kind}
|
|
281
|
+
onChange={(_, value: "new" | "existing" | null) => {
|
|
282
|
+
if (value === "new") setSource({ kind: "new" });
|
|
283
|
+
else if (value === "existing" && available[0])
|
|
284
|
+
pickExisting(available[0]);
|
|
285
|
+
}}
|
|
286
|
+
aria-label="Where the filter comes from"
|
|
287
|
+
>
|
|
288
|
+
<ToggleButton value="new">
|
|
289
|
+
New in this dashboard
|
|
290
|
+
</ToggleButton>
|
|
291
|
+
<ToggleButton value="existing">
|
|
292
|
+
From the model
|
|
293
|
+
</ToggleButton>
|
|
294
|
+
</ToggleButtonGroup>
|
|
295
|
+
)}
|
|
296
|
+
|
|
297
|
+
{!editing && source.kind === "existing" ? (
|
|
298
|
+
<TextField
|
|
299
|
+
select
|
|
300
|
+
size="small"
|
|
301
|
+
label="Control"
|
|
302
|
+
value={source.name}
|
|
303
|
+
onChange={(event) => {
|
|
304
|
+
const picked = available.find(
|
|
305
|
+
(g) => g.name === event.target.value,
|
|
306
|
+
);
|
|
307
|
+
if (picked) pickExisting(picked);
|
|
308
|
+
}}
|
|
309
|
+
>
|
|
310
|
+
{available.map((given) => (
|
|
311
|
+
<MenuItem key={given.name} value={given.name}>
|
|
312
|
+
{given.label ?? given.name}
|
|
313
|
+
<Typography
|
|
314
|
+
component="span"
|
|
315
|
+
variant="caption"
|
|
316
|
+
sx={{ ml: 1, opacity: 0.6 }}
|
|
317
|
+
>
|
|
318
|
+
${given.name}
|
|
319
|
+
</Typography>
|
|
320
|
+
</MenuItem>
|
|
321
|
+
))}
|
|
322
|
+
</TextField>
|
|
323
|
+
) : null}
|
|
324
|
+
|
|
325
|
+
<Stack direction="row" sx={{ gap: 1.5, flexWrap: "wrap" }}>
|
|
326
|
+
{/* Hidden while per-tile fields are open: they speak for
|
|
327
|
+
themselves then, and a box above them that applied to
|
|
328
|
+
nothing would read as one more thing to fill. */}
|
|
329
|
+
{!perTile && (
|
|
330
|
+
<FieldPicker
|
|
331
|
+
value={field}
|
|
332
|
+
onChange={pickField}
|
|
333
|
+
fields={commonFields}
|
|
334
|
+
accepts={accepts}
|
|
335
|
+
label="Field to filter"
|
|
336
|
+
ariaLabel="Field to filter"
|
|
337
|
+
placeholder="category"
|
|
338
|
+
autoFocus={!editing}
|
|
339
|
+
error={commonProblem !== undefined}
|
|
340
|
+
helperText={
|
|
341
|
+
commonProblem ??
|
|
342
|
+
(!editing && newName
|
|
343
|
+
? `Declared as $${newName}`
|
|
344
|
+
: undefined)
|
|
345
|
+
}
|
|
346
|
+
sx={{ flex: 1, minWidth: 200 }}
|
|
347
|
+
/>
|
|
348
|
+
)}
|
|
349
|
+
{!fromModel && (
|
|
350
|
+
<TextField
|
|
351
|
+
size="small"
|
|
352
|
+
label="Label"
|
|
353
|
+
placeholder={newName ? titleCase(newName) : ""}
|
|
354
|
+
value={label}
|
|
355
|
+
onChange={(event) => setLabel(event.target.value)}
|
|
356
|
+
inputProps={{ "aria-label": "Control label" }}
|
|
357
|
+
sx={{ flex: 1, minWidth: 160 }}
|
|
358
|
+
/>
|
|
359
|
+
)}
|
|
360
|
+
{valueTyped &&
|
|
361
|
+
!perTile &&
|
|
362
|
+
operatorField(commonOp, setCommonOp, "Comparison")}
|
|
363
|
+
</Stack>
|
|
364
|
+
{!editing && source.kind === "new" && (
|
|
365
|
+
<Stack direction="row" sx={{ gap: 1.5 }}>
|
|
366
|
+
<TextField
|
|
367
|
+
select
|
|
368
|
+
size="small"
|
|
369
|
+
label="Control"
|
|
370
|
+
value={kind}
|
|
371
|
+
onChange={(event) =>
|
|
372
|
+
pickKind(event.target.value as ControlKind)
|
|
373
|
+
}
|
|
374
|
+
inputProps={{ "aria-label": "Kind of control" }}
|
|
375
|
+
slotProps={{
|
|
376
|
+
select: {
|
|
377
|
+
renderValue: (value) =>
|
|
378
|
+
CONTROL_KINDS.find((k) => k.kind === value)
|
|
379
|
+
?.label ?? String(value),
|
|
380
|
+
},
|
|
381
|
+
}}
|
|
382
|
+
sx={{ flex: 1 }}
|
|
383
|
+
>
|
|
384
|
+
{CONTROL_KINDS.map((option) => (
|
|
385
|
+
<MenuItem key={option.kind} value={option.kind}>
|
|
386
|
+
{option.label}
|
|
387
|
+
<Typography
|
|
388
|
+
component="span"
|
|
389
|
+
variant="caption"
|
|
390
|
+
sx={{ ml: 1, opacity: 0.6 }}
|
|
391
|
+
>
|
|
392
|
+
{option.hint}
|
|
393
|
+
</Typography>
|
|
394
|
+
</MenuItem>
|
|
395
|
+
))}
|
|
396
|
+
</TextField>
|
|
397
|
+
{kind === "date" && (
|
|
398
|
+
<TextField
|
|
399
|
+
size="small"
|
|
400
|
+
type="date"
|
|
401
|
+
label="Starts at"
|
|
402
|
+
value={dateDefault}
|
|
403
|
+
onChange={(event) =>
|
|
404
|
+
setDateDefault(event.target.value)
|
|
405
|
+
}
|
|
406
|
+
InputLabelProps={{ shrink: true }}
|
|
407
|
+
sx={{ flex: 1 }}
|
|
408
|
+
/>
|
|
409
|
+
)}
|
|
410
|
+
</Stack>
|
|
411
|
+
)}
|
|
412
|
+
|
|
413
|
+
{/* WHICH tiles. */}
|
|
414
|
+
<Box>
|
|
415
|
+
<Stack
|
|
416
|
+
direction="row"
|
|
417
|
+
sx={{ alignItems: "center", gap: 0.5 }}
|
|
418
|
+
>
|
|
419
|
+
<Checkbox
|
|
420
|
+
size="small"
|
|
421
|
+
checked={
|
|
422
|
+
bindableCount > 0 && included === bindableCount
|
|
423
|
+
}
|
|
424
|
+
indeterminate={included > 0 && included < bindableCount}
|
|
425
|
+
disabled={bindableCount === 0}
|
|
426
|
+
onChange={(event) => setAll(event.target.checked)}
|
|
427
|
+
inputProps={{ "aria-label": "All tiles" }}
|
|
428
|
+
/>
|
|
429
|
+
<Typography variant="subtitle2" sx={{ flex: 1 }}>
|
|
430
|
+
Applies to {included} of {document.tiles.length} tiles
|
|
431
|
+
</Typography>
|
|
432
|
+
<Button
|
|
433
|
+
size="small"
|
|
434
|
+
onClick={() => {
|
|
435
|
+
// Opening per-tile starts every row from the common
|
|
436
|
+
// field; closing it goes back to one box for all.
|
|
437
|
+
if (!perTile)
|
|
438
|
+
setRows((previous) =>
|
|
439
|
+
previous.map((row) => ({ ...row, field })),
|
|
440
|
+
);
|
|
441
|
+
setPerTile((was) => !was);
|
|
442
|
+
}}
|
|
443
|
+
>
|
|
444
|
+
{perTile ? "Same field for all" : "Adjust per tile"}
|
|
445
|
+
</Button>
|
|
446
|
+
</Stack>
|
|
447
|
+
<Stack sx={{ gap: perTile ? 1 : 0 }}>
|
|
448
|
+
{document.tiles.map((tile, index) => {
|
|
449
|
+
const row = rows[index];
|
|
450
|
+
const title = tile.label ?? tile.name;
|
|
451
|
+
const problem = perTile
|
|
452
|
+
? rowProblems[index]
|
|
453
|
+
: undefined;
|
|
454
|
+
return (
|
|
455
|
+
<Stack
|
|
456
|
+
key={`${tile.source}.${tile.name}`}
|
|
457
|
+
direction="row"
|
|
458
|
+
sx={{
|
|
459
|
+
gap: 1,
|
|
460
|
+
alignItems: perTile ? "flex-start" : "center",
|
|
461
|
+
opacity: bindable[index] ? 1 : 0.6,
|
|
462
|
+
}}
|
|
463
|
+
>
|
|
464
|
+
<Checkbox
|
|
465
|
+
size="small"
|
|
466
|
+
disabled={!bindable[index]}
|
|
467
|
+
checked={
|
|
468
|
+
(row?.include ?? false) && bindable[index]
|
|
469
|
+
}
|
|
470
|
+
inputProps={{
|
|
471
|
+
"aria-label": `Filter ${title}`,
|
|
472
|
+
}}
|
|
473
|
+
onChange={(event) =>
|
|
474
|
+
setRow(index, {
|
|
475
|
+
include: event.target.checked,
|
|
476
|
+
})
|
|
477
|
+
}
|
|
478
|
+
/>
|
|
479
|
+
<Typography
|
|
480
|
+
variant="body2"
|
|
481
|
+
sx={{
|
|
482
|
+
flex: 1,
|
|
483
|
+
minWidth: 0,
|
|
484
|
+
pt: perTile ? 1 : 0,
|
|
485
|
+
}}
|
|
486
|
+
noWrap
|
|
487
|
+
>
|
|
488
|
+
{title}
|
|
489
|
+
</Typography>
|
|
490
|
+
{!bindable[index] ? (
|
|
491
|
+
<Tooltip
|
|
492
|
+
title={
|
|
493
|
+
tile.declaration.kind === "inherited"
|
|
494
|
+
? "Declared on its source, which this dashboard does not write."
|
|
495
|
+
: "Its query is written out here rather than named, so a filter cannot be added to it."
|
|
496
|
+
}
|
|
497
|
+
>
|
|
498
|
+
<Typography
|
|
499
|
+
variant="caption"
|
|
500
|
+
sx={{ color: theme.tileTitle }}
|
|
501
|
+
>
|
|
502
|
+
{tile.declaration.kind === "inherited"
|
|
503
|
+
? "From the model"
|
|
504
|
+
: "Inline query"}
|
|
505
|
+
</Typography>
|
|
506
|
+
</Tooltip>
|
|
507
|
+
) : (
|
|
508
|
+
perTile && (
|
|
509
|
+
<>
|
|
510
|
+
{valueTyped &&
|
|
511
|
+
operatorField(
|
|
512
|
+
row?.op,
|
|
513
|
+
(op) => setRow(index, { op }),
|
|
514
|
+
`Comparison for ${title}`,
|
|
515
|
+
)}
|
|
516
|
+
<FieldPicker
|
|
517
|
+
value={row?.field ?? ""}
|
|
518
|
+
onChange={(next) =>
|
|
519
|
+
setRow(index, { field: next })
|
|
520
|
+
}
|
|
521
|
+
fields={fieldsFor?.(tile)}
|
|
522
|
+
accepts={accepts}
|
|
523
|
+
label="Field"
|
|
524
|
+
ariaLabel={`Field for ${title}`}
|
|
525
|
+
disabled={!row?.include}
|
|
526
|
+
error={problem !== undefined}
|
|
527
|
+
helperText={problem}
|
|
528
|
+
sx={{ width: 220 }}
|
|
529
|
+
/>
|
|
530
|
+
</>
|
|
531
|
+
)
|
|
532
|
+
)}
|
|
533
|
+
</Stack>
|
|
534
|
+
);
|
|
535
|
+
})}
|
|
536
|
+
</Stack>
|
|
537
|
+
{included === 0 && (
|
|
538
|
+
<Typography
|
|
539
|
+
variant="caption"
|
|
540
|
+
sx={{ color: "warning.main", display: "block", mt: 1 }}
|
|
541
|
+
>
|
|
542
|
+
No tile is ticked, so this control will not appear on
|
|
543
|
+
the dashboard.
|
|
544
|
+
</Typography>
|
|
545
|
+
)}
|
|
546
|
+
</Box>
|
|
547
|
+
</Stack>
|
|
548
|
+
</DialogContent>
|
|
549
|
+
<DialogActions sx={{ px: 3, py: 1.5 }}>
|
|
550
|
+
{editing && (
|
|
551
|
+
<Button
|
|
552
|
+
color="error"
|
|
553
|
+
onClick={() => onRemove(shown.name)}
|
|
554
|
+
aria-label={`Remove control ${shown.name}`}
|
|
555
|
+
sx={{ mr: "auto" }}
|
|
556
|
+
>
|
|
557
|
+
Remove from dashboard
|
|
558
|
+
</Button>
|
|
559
|
+
)}
|
|
560
|
+
<Button onClick={onClose}>Cancel</Button>
|
|
561
|
+
<Tooltip
|
|
562
|
+
title={
|
|
563
|
+
canApply || target === undefined
|
|
564
|
+
? ""
|
|
565
|
+
: "A ticked tile has no field, or names one its source does not have."
|
|
566
|
+
}
|
|
567
|
+
>
|
|
568
|
+
<span>
|
|
569
|
+
<Button
|
|
570
|
+
variant="contained"
|
|
571
|
+
onClick={apply}
|
|
572
|
+
disabled={!canApply}
|
|
573
|
+
>
|
|
574
|
+
{editing ? "Apply" : "Add filter"}
|
|
575
|
+
</Button>
|
|
576
|
+
</span>
|
|
577
|
+
</Tooltip>
|
|
578
|
+
</DialogActions>
|
|
579
|
+
</Dialog>
|
|
580
|
+
);
|
|
581
|
+
}
|