@geo2france/api-dashboard 1.12.0 → 1.13.0

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.
@@ -2,6 +2,7 @@ import { RowProps } from "antd";
2
2
  import DashboardElement from "../DashboardElement/DashboardElement";
3
3
  import React from "react";
4
4
  import { SimpleRecord } from "../../types";
5
+ import { Section } from "./Section";
5
6
  type Section = {
6
7
  key: string;
7
8
  libel?: string;
@@ -1,13 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { Button, Col, Dropdown, Flex, Grid, Layout, Radio, Row } from "antd";
2
+ import { Button, Col, Dropdown, Flex, Grid, Layout, Radio, Row, Tabs, theme } from "antd";
3
3
  import React, { isValidElement, useState, createContext, } from "react";
4
4
  import { Helmet } from "react-helmet-async";
5
5
  import { useSearchParamsState } from "../../utils/useSearchParamsState";
6
6
  import Control, { DSL_Control } from "../Control/Control";
7
7
  import { Dataset, Debug, Provider } from "../../dsl";
8
- import { DSL_ChartBlock } from "./Block";
9
8
  import { DEFAULT_PALETTE, Palette, PaletteContext } from "../Palette/Palette";
9
+ import { Section } from "./Section";
10
+ import { Icon } from "@iconify/react";
10
11
  const { Header } = Layout;
12
+ const { useToken } = theme;
11
13
  const getSection = (child) => React.isValidElement(child) ? child.props.section : undefined;
12
14
  const DashboardPage = ({ children: children_input, control, row_gutter = [8, 8], sections }) => {
13
15
  let sections_std = [];
@@ -41,6 +43,7 @@ export const DatasetContext = createContext({});
41
43
  export const DatasetRegistryContext = createContext(() => { }); // A modifier, utiliser un seul context
42
44
  export const ControlContext = createContext(undefined);
43
45
  export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, children, debug = false }) => {
46
+ const { token } = useToken();
44
47
  const [datasets, setdatasets] = useState({});
45
48
  const [palette, setPalette] = useState(DEFAULT_PALETTE);
46
49
  //const allDatasetLoaded = Object.values(datasets).every(d => !d.isFetching);
@@ -61,6 +64,9 @@ export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, child
61
64
  else if (typeof (c.type) != 'string' && c.type.name == DSL_Control.name) {
62
65
  return "control";
63
66
  }
67
+ else if (typeof (c.type) != 'string' && c.type.name == Section.name) {
68
+ return "section";
69
+ }
64
70
  else {
65
71
  return "other";
66
72
  }
@@ -68,9 +74,23 @@ export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, child
68
74
  const visible_components = childrenArray.filter((c) => c && getComponentKind(c) == 'other');
69
75
  const logic_components = childrenArray.filter((c) => getComponentKind(c) == 'logical');
70
76
  const control_components = childrenArray.filter((c) => getComponentKind(c) == 'control');
77
+ const section_components = childrenArray.filter((c) => getComponentKind(c) == 'section');
71
78
  if (debug && !logic_components.some((c) => typeof c.type !== "string" && c.type.name === Debug.name)) {
72
79
  logic_components.push(_jsx(Debug, {}, "debug_property"));
73
80
  }
81
+ const items = section_components.map((s) => ({
82
+ key: s.props.title,
83
+ label: s.props.title,
84
+ children: s,
85
+ icon: typeof (s.props.icon) === 'string' ? (_jsx(Icon, { icon: s.props.icon, fontSize: 18, style: { marginInlineEnd: -6 } })) : s.props.icon,
86
+ }));
87
+ if (visible_components.length > 0) {
88
+ items.push({
89
+ key: "99 - Autres",
90
+ label: '-',
91
+ children: _jsx(Section, { title: 'Autres', children: visible_components })
92
+ });
93
+ }
74
94
  return (_jsxs(_Fragment, { children: [_jsx(Helmet, { children: _jsx("title", { children: name }) }), _jsx(DatasetRegistryContext.Provider, { value: pushDataset, children: _jsx(DatasetContext.Provider, { value: datasets, children: _jsxs(PaletteContext.Provider, { value: { palette, setPalette }, children: [control_components.length > 0 && _jsx(Header, { style: {
75
95
  padding: 12,
76
96
  position: "sticky",
@@ -79,5 +99,12 @@ export const DSL_DashboardPage = ({ name = 'Tableau de bord', columns = 2, child
79
99
  backgroundColor: "#fff",
80
100
  height: "auto",
81
101
  width: "100%",
82
- }, children: control_components }), _jsx(Row, { gutter: [8, 8], style: { margin: 16 }, children: visible_components.map((component, idx) => _jsx(Col, { xl: 24 / columns, xs: 24, children: _jsx(DSL_ChartBlock, { children: component }) }, idx)) }), logic_components] }) }) })] }));
102
+ }, children: control_components }), items.length > 1 ?
103
+ _jsx(Tabs, { defaultActiveKey: "1", items: items, centered: true, tabBarStyle: { margin: 6,
104
+ padding: 4,
105
+ background: token.colorBgContainer,
106
+ borderRadius: token.borderRadiusLG }, style: { margin: 4 } })
107
+ :
108
+ _jsxs("div", { style: { margin: 4 }, children: [" ", items?.[0].children, " "] }) //Show content without tabs if only one
109
+ , logic_components] }) }) })] }));
83
110
  };
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ export interface SectionProps {
3
+ title: string;
4
+ children?: React.ReactElement | React.ReactElement[];
5
+ icon?: React.ReactElement | string;
6
+ }
7
+ export declare const Section: React.FC<SectionProps>;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Col, Row } from "antd";
3
+ import React, { isValidElement } from "react";
4
+ import { DSL_ChartBlock } from "./Block";
5
+ export const Section = ({ children }) => {
6
+ const columns = 2;
7
+ const childrenArray = React.Children.toArray(children).filter(isValidElement);
8
+ return (_jsx(Row, { gutter: [8, 8], style: { margin: 0 }, children: childrenArray.map((component, idx) => (_jsx(Col, { xl: 24 / columns, xs: 24, children: _jsx(DSL_ChartBlock, { children: component }) }, idx))) }));
9
+ };
@@ -19,4 +19,5 @@ import { ChartEcharts } from "../components/Charts/ChartEcharts";
19
19
  import { useBlockConfig } from "../components/DashboardPage/Block";
20
20
  import { Statistics, StatisticsCollection } from "../components/Charts/Statistics";
21
21
  import { MapLayer, Map } from "../components/Map/Map";
22
- export { Dashboard, Dataset, Provider, Transform, Join, Filter, DataPreview, ChartEcharts, ChartPie, ChartYearSerie, Statistics, StatisticsCollection, useDataset, useDatasets, useAllDatasets, useBlockConfig, Producer, Control, useControl, useAllControls, Radio, Select, Input, Palette, usePalette, PalettePreview, Debug, Map, MapLayer };
22
+ import { Section } from "../components/DashboardPage/Section";
23
+ export { Dashboard, Dataset, Provider, Transform, Join, Filter, Section, DataPreview, ChartEcharts, ChartPie, ChartYearSerie, Statistics, StatisticsCollection, useDataset, useDatasets, useAllDatasets, useBlockConfig, Producer, Control, useControl, useAllControls, Radio, Select, Input, Palette, usePalette, PalettePreview, Debug, Map, MapLayer };
package/dist/dsl/index.js CHANGED
@@ -19,4 +19,5 @@ import { ChartEcharts } from "../components/Charts/ChartEcharts";
19
19
  import { useBlockConfig } from "../components/DashboardPage/Block";
20
20
  import { Statistics, StatisticsCollection } from "../components/Charts/Statistics";
21
21
  import { MapLayer, Map } from "../components/Map/Map";
22
- export { Dashboard, Dataset, Provider, Transform, Join, Filter, DataPreview, ChartEcharts, ChartPie, ChartYearSerie, Statistics, StatisticsCollection, useDataset, useDatasets, useAllDatasets, useBlockConfig, Producer, Control, useControl, useAllControls, Radio, Select, Input, Palette, usePalette, PalettePreview, Debug, Map, MapLayer };
22
+ import { Section } from "../components/DashboardPage/Section";
23
+ export { Dashboard, Dataset, Provider, Transform, Join, Filter, Section, DataPreview, ChartEcharts, ChartPie, ChartYearSerie, Statistics, StatisticsCollection, useDataset, useDatasets, useAllDatasets, useBlockConfig, Producer, Control, useControl, useAllControls, Radio, Select, Input, Palette, usePalette, PalettePreview, Debug, Map, MapLayer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geo2france/api-dashboard",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "private": false,
5
5
  "description": "Build dashboards with JSX/TSX",
6
6
  "main": "dist/index.js",
@@ -1 +0,0 @@
1
- export declare const mapOperator: (operator: any) => string;
@@ -1,36 +0,0 @@
1
- export const mapOperator = (operator) => {
2
- switch (operator) {
3
- case "ne":
4
- return '<>';
5
- case "gte":
6
- return '>=';
7
- case "gt":
8
- return '>';
9
- case "lte":
10
- return `<=`;
11
- case "lt":
12
- return `<`;
13
- case "eq":
14
- return "=";
15
- case "contains":
16
- case "startswith":
17
- case "endswith":
18
- return "ilike";
19
- case "containss":
20
- case "startswiths":
21
- case "endswiths":
22
- return "like";
23
- case "ncontains":
24
- case "nstartswith":
25
- case "nendswith":
26
- return "not ilike";
27
- case "ncontainss":
28
- case "nstartswiths":
29
- case "nendswiths":
30
- return "not like";
31
- case "in":
32
- return operator;
33
- default:
34
- return "";
35
- }
36
- };
@@ -1,7 +0,0 @@
1
- import { SimpleRecord } from "../types";
2
- interface BlocConfig {
3
- title?: string;
4
- dataExport?: SimpleRecord[];
5
- }
6
- export declare const useBlockConfig: ({ title, dataExport }: BlocConfig) => void;
7
- export {};
@@ -1,9 +0,0 @@
1
- import { useContext, useEffect } from "react";
2
- import { ChartBlockContext } from "../components/DashboardPage/Block";
3
- export const useBlockConfig = ({ title, dataExport }) => {
4
- const blockContext = useContext(ChartBlockContext);
5
- useEffect(() => blockContext?.setConfig({
6
- title: title,
7
- dataExport: dataExport
8
- }), [title, dataExport]);
9
- };