@bluemarble/bi 0.1.2 → 0.2.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.
@@ -1,6 +1,6 @@
1
- import { C as validateModel, D as parseColumnRef, E as modelEdges, T as measureHome, _ as AGGREGATIONS, a as FILTER_FIELDS, c as chartReferences, d as layoutModelWarnings, f as validateLayout, g as toModelCode, i as CHART_TYPE_LABEL, k as referencedTables, l as filterReferences, n as CHART_FIELDS, o as chartColumns, p as canonicalJson, r as CHART_TYPES, s as chartOfType, t as CANVAS_PRESETS, u as layoutFileContent, v as AGGREGATION_LABEL, x as isAggregate, y as VALUE_FORMATS } from "./layout-iPByu6V0.js";
1
+ import { A as referencedTables, D as modelEdges, E as measureHome, O as parseColumnRef, S as isAggregate, _ as toModelCode, a as chartOfType, b as VALUE_FORMATS, c as filterReferences, d as layoutModelWarnings, i as chartColumns, m as canonicalJson, n as CANVAS_PRESETS, o as chartReferences, p as validateLayout, r as FILTER_FIELDS, t as BUILTIN_CHART_TYPES, u as layoutFileContent, v as AGGREGATIONS, w as validateModel, y as AGGREGATION_LABEL } from "./layout-DvHS8XFz.js";
2
2
  import { n as diffRows } from "./compare-DloZhg1T.js";
3
- import { a as useDashboard, c as layoutItemKey, l as parseLayoutItemKey, n as INSPECT_ATTRIBUTE, o as errorMessage, s as LAYOUT_ITEM_ATTRIBUTE, t as ModelDictionary } from "./ModelDictionary-DU6i_QSn.js";
3
+ import { a as useDashboard, c as layoutItemKey, l as parseLayoutItemKey, n as INSPECT_ATTRIBUTE, o as errorMessage, s as LAYOUT_ITEM_ATTRIBUTE, t as ModelDictionary } from "./ModelDictionary-DN77UDVM.js";
4
4
  import { Alert, Autocomplete, Box, Button, Checkbox, Chip, CircularProgress, Collapse, Dialog, DialogActions, DialogContent, DialogTitle, Divider, FormControlLabel, IconButton, List, ListItemButton, Menu, MenuItem, MenuList, Paper, Popper, Portal, Tab, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Tabs, TextField, ThemeProvider, ToggleButton, ToggleButtonGroup, Tooltip, Typography, createTheme } from "@mui/material";
5
5
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -730,15 +730,19 @@ const NEW_CHART = {
730
730
  span: 12
731
731
  }
732
732
  };
733
- const newChart = (type, model, charts) => {
734
- const { id, ...rest } = NEW_CHART[type];
733
+ const newChart = (type, model, charts, types) => {
734
+ const { id, ...rest } = NEW_CHART[type] ?? {
735
+ id: type,
736
+ title: `Novo ${types[type]?.label ?? type}`,
737
+ span: 6
738
+ };
735
739
  return chartOfType(type, model, {
736
740
  id: uniqueId(charts, id),
737
741
  ...rest
738
- });
742
+ }, types);
739
743
  };
740
- const chartSummary = (chart) => {
741
- const { dimensions, measures } = chartReferences(chart);
744
+ const chartSummary = (chart, types) => {
745
+ const { dimensions, measures } = chartReferences(chart, types);
742
746
  return `${chart.type} · ${dimensions.join(", ") || "—"} · ${measures.join(", ")}`;
743
747
  };
744
748
  /**
@@ -748,7 +752,7 @@ const chartSummary = (chart) => {
748
752
  */
749
753
  function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
750
754
  const { layouts } = devtools;
751
- const { fetcher, model: modelName } = useDashboard();
755
+ const { fetcher, model: modelName, chartTypes } = useDashboard();
752
756
  const entries = useSyncExternalStore(layouts.subscribe, layouts.getSnapshot, layouts.getSnapshot);
753
757
  const [layoutId, setLayoutId] = useState(null);
754
758
  const entry = entries.find((item) => item.registered.id === layoutId) ?? entries[0] ?? null;
@@ -771,12 +775,14 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
771
775
  setLayoutId(parsed.layoutId);
772
776
  setSelection(parsed.item);
773
777
  }, [picked]);
774
- const errors = useMemo(() => editing ? validateLayout(editing) : [], [editing]);
778
+ const errors = useMemo(() => editing ? validateLayout(editing, chartTypes) : [], [editing, chartTypes]);
775
779
  const warnings = useMemo(() => {
776
780
  if (!editing || errors.length) return [];
777
- const list = layoutModelWarnings(editing, model);
781
+ const list = layoutModelWarnings(editing, model, chartTypes);
778
782
  const { charts: chartFormatters = [], filters: filterFormatters } = entry?.parts ?? {};
779
- for (const chart of editing.charts) for (const name of chartReferences(chart).formatters) if (!chartFormatters.includes(name)) list.push(`"${chart.title || chart.id}": formatter "${name}" não foi passado ao <DashboardCharts formatters>`);
783
+ const serverTypes = new Set(capabilities?.chartTypes ?? []);
784
+ for (const type of new Set(editing.charts.map((chart) => chart.type))) if (capabilities?.saveLayout && !BUILTIN_CHART_TYPES[type] && !serverTypes.has(type)) list.push(`Tipo "${type}" não foi passado ao \`devtools.chartTypes\` do endpoint: "Salvar no arquivo" vai recusar.`);
785
+ for (const chart of editing.charts) for (const name of chartReferences(chart, chartTypes).formatters) if (!chartFormatters.includes(name)) list.push(`"${chart.title || chart.id}": formatter "${name}" não foi passado ao <DashboardCharts formatters>`);
780
786
  if (editing.canvas && !entry?.parts.canvas) list.push("A página não usa <DashboardCanvas layout={...}>: o tamanho fixo da tela não é aplicado.");
781
787
  if (editing.filters?.length && !filterFormatters) list.push("A página não usa <DashboardFilters layout={...}>: os filtros do layout não aparecem.");
782
788
  for (const filter of editing.filters ?? []) for (const name of filterReferences(filter).formatters) if (filterFormatters && !filterFormatters.includes(name)) list.push(`filtro "${filter.dimension}": formatter "${name}" não foi passado ao <DashboardFilters formatters>`);
@@ -785,7 +791,9 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
785
791
  editing,
786
792
  errors,
787
793
  model,
788
- entry
794
+ entry,
795
+ chartTypes,
796
+ capabilities
789
797
  ]);
790
798
  if (!entry || !editing) return /* @__PURE__ */ jsxs(Empty, { children: [
791
799
  "Nenhum ",
@@ -807,7 +815,7 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
807
815
  const update = (next) => {
808
816
  setEditing(next);
809
817
  setSave(null);
810
- if (!validateLayout(next).length) {
818
+ if (!validateLayout(next, chartTypes).length) {
811
819
  devtools.store.expectRefetch();
812
820
  layouts.setDraft(entry.registered.id, next);
813
821
  }
@@ -884,7 +892,7 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
884
892
  ...base,
885
893
  id: uniqueId(charts, base.id),
886
894
  title: `${base.title} (cópia)`
887
- } : newChart(type, model, charts);
895
+ } : newChart(type, model, charts, chartTypes);
888
896
  const index = base ? charts.findIndex((item) => item.id === base.id) + 1 : charts.length;
889
897
  setCharts([
890
898
  ...charts.slice(0, index),
@@ -1037,10 +1045,10 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
1037
1045
  anchorEl: addMenu,
1038
1046
  open: !!addMenu,
1039
1047
  onClose: () => setAddMenu(null),
1040
- children: CHART_TYPES.map((type) => /* @__PURE__ */ jsx(MenuItem, {
1048
+ children: Object.entries(chartTypes).map(([type, { label }]) => /* @__PURE__ */ jsx(MenuItem, {
1041
1049
  dense: true,
1042
1050
  onClick: () => add(type),
1043
- children: CHART_TYPE_LABEL[type]
1051
+ children: label
1044
1052
  }, type))
1045
1053
  })] }),
1046
1054
  children: charts.map((chart, index) => {
@@ -1050,7 +1058,7 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
1050
1058
  };
1051
1059
  return /* @__PURE__ */ jsx(ItemRow, {
1052
1060
  title: chart.title || "(sem título)",
1053
- subtitle: `${chartSummary(chart)} · ${chart.span ?? 12}/12`,
1061
+ subtitle: `${chartSummary(chart, chartTypes)} · ${chart.span ?? 12}/12`,
1054
1062
  selected: chart.id === selected?.id,
1055
1063
  onSelect: () => focus(item),
1056
1064
  onHover: (on) => hover(on ? item : null),
@@ -1119,6 +1127,7 @@ function LayoutPanel({ devtools, model, capabilities, picked, onHover }) {
1119
1127
  }
1120
1128
  }, `filter:${selectedFilter.dimension}`) : selected ? /* @__PURE__ */ jsx(ChartForm, {
1121
1129
  chart: selected,
1130
+ types: chartTypes,
1122
1131
  model,
1123
1132
  formatters: entry.parts.charts ?? [],
1124
1133
  columns: formColumns,
@@ -1392,28 +1401,32 @@ function SmallButton({ title, disabled, onClick, children }) {
1392
1401
  }) })
1393
1402
  });
1394
1403
  }
1395
- function ChartForm({ chart, model, formatters, columns, onChange }) {
1404
+ function ChartForm({ chart, types, model, formatters, columns, onChange }) {
1396
1405
  const set = (key, value) => onChange((current) => withField(current, key, value));
1397
1406
  return /* @__PURE__ */ jsx(FieldsForm, {
1398
- fields: CHART_FIELDS[chart.type],
1407
+ fields: types[chart.type]?.fields ?? {},
1399
1408
  values: chart,
1400
1409
  onSet: set,
1401
1410
  model,
1402
1411
  formatters,
1403
- columns: chartColumns(chart),
1412
+ columns: chartColumns(chart, types),
1404
1413
  formColumns: columns,
1405
- chosenDimensions: chartReferences(chart).dimensions,
1406
- header: /* @__PURE__ */ jsxs(Fragment, { children: [field("Tipo", /* @__PURE__ */ jsx(TextField, {
1414
+ chosenDimensions: chartReferences(chart, types).dimensions,
1415
+ header: /* @__PURE__ */ jsxs(Fragment, { children: [field("Tipo", /* @__PURE__ */ jsxs(TextField, {
1407
1416
  select: true,
1408
1417
  size: "small",
1409
1418
  fullWidth: true,
1410
1419
  value: chart.type,
1411
- onChange: (e) => onChange((current) => chartOfType(e.target.value, model, current)),
1420
+ onChange: (e) => onChange((current) => chartOfType(e.target.value, model, current, types)),
1412
1421
  sx: inputSx$1,
1413
- children: CHART_TYPES.map((type) => /* @__PURE__ */ jsx(MenuItem, {
1422
+ children: [Object.entries(types).map(([type, { label }]) => /* @__PURE__ */ jsx(MenuItem, {
1414
1423
  value: type,
1415
- children: CHART_TYPE_LABEL[type]
1416
- }, type))
1424
+ children: label
1425
+ }, type)), !types[chart.type] && /* @__PURE__ */ jsxs(MenuItem, {
1426
+ value: chart.type,
1427
+ disabled: true,
1428
+ children: [chart.type, " (não registrado)"]
1429
+ })]
1417
1430
  })), field("id", /* @__PURE__ */ jsx(TextField, {
1418
1431
  size: "small",
1419
1432
  fullWidth: true,
@@ -6381,4 +6394,4 @@ function ToggleButton$1({ draft, loading, problems, inspecting, onOpen }) {
6381
6394
  //#endregion
6382
6395
  export { DashboardDevtools as default };
6383
6396
 
6384
- //# sourceMappingURL=DashboardDevtools-DLhEr3fN.js.map
6397
+ //# sourceMappingURL=DashboardDevtools-5wh3brAT.js.map