@geo2france/api-dashboard 1.11.2 → 1.12.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.
@@ -1,11 +1,13 @@
1
1
  import { ReactElement } from "react";
2
2
  import { SimpleRecord } from "../../types";
3
3
  type comparwithType = "first" | "previous";
4
- interface annotation_params_type {
4
+ interface ICallbackParams {
5
5
  /** Valeur principale */
6
6
  value: number;
7
7
  /** Jeu de données utilisé */
8
8
  data: SimpleRecord[] | undefined;
9
+ /** Ligne courante (pour accéder aux autres champs) */
10
+ row: SimpleRecord | undefined;
9
11
  /** Valeur de comparaison */
10
12
  compareValue: number;
11
13
  }
@@ -33,7 +35,9 @@ interface StatisticsProps {
33
35
  /** Comparer la valeur avec la précédente ou la première du jeu de données */
34
36
  compareWith?: comparwithType;
35
37
  /** Texte d'annotation (remplace evolution si définie) */
36
- annotation?: React.ReactNode | ((param: annotation_params_type) => React.ReactNode);
38
+ annotation?: React.ReactNode | ((param: ICallbackParams) => React.ReactNode);
39
+ /** Fonction a appliquer avant rendu */
40
+ valueFormatter?: ((param: ICallbackParams) => React.ReactNode);
37
41
  }
38
42
  /**
39
43
  * Composant `Statistics` affichant une valeur d'un dataset avec son évolution.
@@ -20,19 +20,20 @@ const { Text, Paragraph } = Typography;
20
20
  * @param {StatisticsProps} props - Propriétés du composant
21
21
  * @returns {ReactElement} Carte statistique
22
22
  */
23
- export const Statistics = ({ dataset: dataset_id, dataKey, unit, evolutionSuffix, title, icon: icon_input, color, invertColor = false, help, compareWith, relativeEvolution = false, annotation }) => {
23
+ export const Statistics = ({ dataset: dataset_id, dataKey, unit, evolutionSuffix, title, icon: icon_input, color, invertColor = false, help, compareWith, relativeEvolution = false, valueFormatter = (param) => (param.value.toLocaleString()), annotation }) => {
24
24
  const icon = typeof icon_input === "string" ? _jsx(Icon, { icon: icon_input }) : icon_input;
25
25
  const dataset = useDataset(dataset_id);
26
- const value = dataset?.data?.slice(-1)[0][dataKey]; // Dernière valeur du dataset. Caster en Number ?
26
+ const row = dataset?.data?.slice(-1)[0];
27
+ const value = row?.[dataKey]; // Dernière valeur du dataset. Caster en Number ?
27
28
  const compare_value = compareWith === 'previous' ? dataset?.data?.slice(-2)[0][dataKey] : dataset?.data?.slice(0, 1)[0][dataKey]; //Première ou avant dernière
28
29
  const evolution = relativeEvolution ? 100 * ((value - compare_value) / compare_value) : value - compare_value;
29
30
  const evolution_unit = relativeEvolution ? '%' : unit;
30
31
  const evolution_is_good = invertColor ? evolution < 0 : evolution > 0;
31
32
  const tooltip = help && _jsx(Tooltip, { title: help, children: _jsx(QuestionCircleOutlined, {}) });
32
- const annotation_params = { value: value || NaN, compareValue: compare_value || NaN, data: dataset?.data || [] };
33
+ const CallbackParams = { value: value || NaN, compareValue: compare_value || NaN, data: dataset?.data || [], row: row };
33
34
  let subtitle;
34
35
  if (annotation !== undefined) {
35
- subtitle = typeof annotation === 'function' ? annotation(annotation_params) : annotation;
36
+ subtitle = typeof annotation === 'function' ? annotation(CallbackParams) : annotation;
36
37
  }
37
38
  else if (evolution) {
38
39
  subtitle = (_jsxs(Paragraph, { style: { marginBottom: "0.5rem" }, children: [_jsxs(Text, { strong: true, type: evolution_is_good ? "success" : "danger", style: { fontSize: "120%" }, children: [evolution < 0.1 ? '' : '+', evolution.toLocaleString(undefined, { maximumFractionDigits: 1 }), "\u00A0", evolution_unit] }), " ", _jsx(Text, { italic: true, type: "secondary", children: evolutionSuffix })] }));
@@ -52,7 +53,7 @@ export const Statistics = ({ dataset: dataset_id, dataKey, unit, evolutionSuffix
52
53
  fontSize: 14,
53
54
  minHeight: 35,
54
55
  },
55
- }, extra: tooltip, children: _jsxs(Flex, { vertical: true, children: [_jsxs(Flex, { justify: "space-between", align: "center", children: [_jsxs(Text, { style: { fontSize: "150%", paddingTop: 8, paddingBottom: 8, paddingLeft: 0 }, children: [value?.toLocaleString(), " ", unit] }), icon && _jsx(Avatar, { size: 32 + 8, icon: icon, style: { backgroundColor: color } })] }), typeof subtitle == 'string' ?
56
+ }, extra: tooltip, children: _jsxs(Flex, { vertical: true, children: [_jsxs(Flex, { justify: "space-between", align: "center", children: [_jsxs(Text, { style: { fontSize: "150%", paddingTop: 8, paddingBottom: 8, paddingLeft: 0 }, children: [valueFormatter(CallbackParams), " ", unit] }), icon && _jsx(Avatar, { size: 32 + 8, icon: icon, style: { backgroundColor: color } })] }), typeof subtitle == 'string' ?
56
57
  _jsx(Text, { italic: true, type: "secondary", children: subtitle })
57
58
  :
58
59
  _jsx("div", { children: subtitle })] }) }));
@@ -0,0 +1 @@
1
+ export declare const mapOperator: (operator: any) => string;
@@ -0,0 +1,36 @@
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
+ };
@@ -0,0 +1,7 @@
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 {};
@@ -0,0 +1,9 @@
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geo2france/api-dashboard",
3
- "version": "1.11.2",
3
+ "version": "1.12.0",
4
4
  "private": false,
5
5
  "description": "Build dashboards with JSX/TSX",
6
6
  "main": "dist/index.js",