@gridsuite/commons-ui 0.55.0 → 0.57.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.
Files changed (162) hide show
  1. package/dist/assets/criteria-based-filter-edition-dialog.css +168 -0
  2. package/dist/chunks/criteria-based-filter-edition-dialog.BEXoNmzz.js +1673 -0
  3. package/dist/chunks/filter-properties.GRon8-ML.js +195 -0
  4. package/dist/components/DirectoryItemSelector/directory-item-selector.d.ts +13 -3
  5. package/dist/components/DirectoryItemSelector/directory-item-selector.js +14 -10
  6. package/dist/components/TopBar/TopBar.js +371 -429
  7. package/dist/components/dialogs/custom-mui-dialog.d.ts +21 -0
  8. package/dist/components/dialogs/custom-mui-dialog.js +87 -0
  9. package/dist/components/dialogs/description-modification-dialog.d.ts +11 -0
  10. package/dist/components/dialogs/description-modification-dialog.js +71 -0
  11. package/dist/components/dialogs/popup-confirmation-dialog.d.ts +11 -0
  12. package/dist/components/dialogs/popup-confirmation-dialog.js +38 -0
  13. package/dist/components/filter/constants/equipment-types.d.ts +72 -0
  14. package/dist/components/filter/constants/equipment-types.js +63 -0
  15. package/dist/components/filter/constants/expert-filter-constants.d.ts +551 -0
  16. package/dist/components/filter/constants/expert-filter-constants.js +668 -0
  17. package/dist/components/filter/constants/field-constants.d.ts +45 -0
  18. package/dist/components/filter/constants/field-constants.js +43 -0
  19. package/dist/components/filter/constants/filter-constants.d.ts +21 -0
  20. package/dist/components/filter/constants/filter-constants.js +10 -0
  21. package/dist/components/filter/criteria-based/criteria-based-filter-edition-dialog.d.ts +29 -0
  22. package/dist/components/filter/criteria-based/criteria-based-filter-edition-dialog.js +19 -0
  23. package/dist/components/filter/criteria-based/criteria-based-filter-form.d.ts +15 -0
  24. package/dist/components/filter/criteria-based/criteria-based-filter-form.js +33 -0
  25. package/dist/components/filter/criteria-based/criteria-based-filter-utils.d.ts +37 -0
  26. package/dist/components/filter/criteria-based/criteria-based-filter-utils.js +127 -0
  27. package/dist/components/filter/criteria-based/criteria-based-form.d.ts +7 -0
  28. package/dist/components/filter/criteria-based/criteria-based-form.js +50 -0
  29. package/dist/components/filter/criteria-based/filter-free-properties.d.ts +10 -0
  30. package/dist/components/filter/criteria-based/filter-free-properties.js +15 -0
  31. package/dist/components/filter/criteria-based/filter-properties.d.ts +21 -0
  32. package/dist/components/filter/criteria-based/filter-properties.js +19 -0
  33. package/dist/components/filter/criteria-based/filter-property.d.ts +19 -0
  34. package/dist/components/filter/criteria-based/filter-property.js +67 -0
  35. package/dist/components/filter/expert/expert-filter-edition-dialog.d.ts +28 -0
  36. package/dist/components/filter/expert/expert-filter-edition-dialog.js +20 -0
  37. package/dist/components/filter/expert/expert-filter-form.d.ts +21 -0
  38. package/dist/components/filter/expert/expert-filter-form.js +22 -0
  39. package/dist/components/filter/expert/expert-filter-utils.d.ts +91 -0
  40. package/dist/components/filter/expert/expert-filter-utils.js +304 -0
  41. package/dist/components/filter/expert/expert-filter.type.d.ts +114 -0
  42. package/dist/components/filter/expert/expert-filter.type.js +104 -0
  43. package/dist/components/filter/explicit-naming/explicit-naming-filter-edition-dialog.d.ts +22 -0
  44. package/dist/components/filter/explicit-naming/explicit-naming-filter-edition-dialog.js +19 -0
  45. package/dist/components/filter/explicit-naming/explicit-naming-filter-form.d.ts +22 -0
  46. package/dist/components/filter/explicit-naming/explicit-naming-filter-form.js +23 -0
  47. package/dist/components/filter/filter-context.d.ts +12 -0
  48. package/dist/components/filter/filter-context.js +10 -0
  49. package/dist/components/filter/filter-creation-dialog.d.ts +21 -0
  50. package/dist/components/filter/filter-creation-dialog.js +17 -0
  51. package/dist/components/filter/filter-form.d.ts +11 -0
  52. package/dist/components/filter/filter-form.js +14 -0
  53. package/dist/components/filter/utils/criteria-based-utils.d.ts +28 -0
  54. package/dist/components/filter/utils/criteria-based-utils.js +197 -0
  55. package/dist/components/filter/utils/filters-utils.d.ts +5 -0
  56. package/dist/components/filter/utils/filters-utils.js +99 -0
  57. package/dist/components/inputs/select-clearable.d.ts +14 -0
  58. package/dist/components/inputs/select-clearable.js +40 -0
  59. package/dist/components/react-hook-form/ExpandingTextField.d.ts +1 -1
  60. package/dist/components/react-hook-form/ExpandingTextField.js +0 -37
  61. package/dist/components/react-hook-form/ag-grid-table-rhf/bottom-right-buttons.d.ts +17 -0
  62. package/dist/components/react-hook-form/ag-grid-table-rhf/bottom-right-buttons.js +15 -0
  63. package/dist/components/react-hook-form/ag-grid-table-rhf/cell-editors/numericEditor.d.ts +23 -0
  64. package/dist/components/react-hook-form/ag-grid-table-rhf/cell-editors/numericEditor.js +70 -0
  65. package/dist/components/react-hook-form/ag-grid-table-rhf/csv-uploader/csv-uploader.d.ts +16 -0
  66. package/dist/components/react-hook-form/ag-grid-table-rhf/csv-uploader/csv-uploader.js +69 -0
  67. package/dist/components/react-hook-form/ag-grid-table-rhf/custom-ag-grid-table.d.ts +23 -0
  68. package/dist/components/react-hook-form/ag-grid-table-rhf/custom-ag-grid-table.js +15 -0
  69. package/dist/components/react-hook-form/autocomplete-input.d.ts +17 -29
  70. package/dist/components/react-hook-form/autocomplete-input.js +4 -15
  71. package/dist/components/react-hook-form/autocomplete-inputs/multiple-autocomplete-input.d.ts +2 -0
  72. package/dist/components/react-hook-form/autocomplete-inputs/multiple-autocomplete-input.js +46 -0
  73. package/dist/components/react-hook-form/directory-items-input.d.ts +0 -3
  74. package/dist/components/react-hook-form/directory-items-input.js +5 -6
  75. package/dist/components/react-hook-form/error-management/error-input.d.ts +13 -4
  76. package/dist/components/react-hook-form/error-management/error-input.js +7 -7
  77. package/dist/components/react-hook-form/error-management/field-error-alert.d.ts +6 -3
  78. package/dist/components/react-hook-form/error-management/field-error-alert.js +3 -1
  79. package/dist/components/react-hook-form/numbers/float-input.d.ts +5 -17
  80. package/dist/components/react-hook-form/numbers/float-input.js +3 -5
  81. package/dist/components/react-hook-form/numbers/integer-input.d.ts +15 -12
  82. package/dist/components/react-hook-form/numbers/utils.d.ts +8 -2
  83. package/dist/components/react-hook-form/provider/custom-form-provider.d.ts +1 -0
  84. package/dist/components/react-hook-form/provider/custom-form-provider.js +12 -3
  85. package/dist/components/react-hook-form/radio-input.d.ts +14 -17
  86. package/dist/components/react-hook-form/radio-input.js +7 -9
  87. package/dist/components/react-hook-form/range-input.d.ts +54 -0
  88. package/dist/components/react-hook-form/range-input.js +118 -0
  89. package/dist/components/react-hook-form/select-inputs/countries-input.d.ts +8 -0
  90. package/dist/components/react-hook-form/select-inputs/countries-input.js +36 -0
  91. package/dist/components/react-hook-form/select-inputs/input-with-popup-confirmation.d.ts +2 -0
  92. package/dist/components/react-hook-form/select-inputs/input-with-popup-confirmation.js +61 -0
  93. package/dist/components/react-hook-form/select-inputs/mui-select-input.d.ts +12 -0
  94. package/dist/components/react-hook-form/select-inputs/mui-select-input.js +25 -0
  95. package/dist/components/react-hook-form/select-inputs/select-input.d.ts +9 -0
  96. package/dist/components/react-hook-form/select-inputs/select-input.js +37 -0
  97. package/dist/components/react-hook-form/text-input.d.ts +23 -32
  98. package/dist/components/react-hook-form/text-input.js +6 -20
  99. package/dist/components/react-hook-form/unique-name-input.d.ts +21 -0
  100. package/dist/components/react-hook-form/unique-name-input.js +129 -0
  101. package/dist/components/react-hook-form/utils/cancel-button.d.ts +9 -8
  102. package/dist/components/react-hook-form/utils/field-label.d.ts +12 -5
  103. package/dist/components/react-hook-form/utils/field-label.js +5 -1
  104. package/dist/components/react-hook-form/utils/functions.d.ts +12 -4
  105. package/dist/components/react-hook-form/utils/functions.js +21 -1
  106. package/dist/components/react-hook-form/utils/submit-button.d.ts +9 -8
  107. package/dist/components/react-hook-form/utils/text-field-with-adornment.d.ts +11 -11
  108. package/dist/components/react-hook-form/utils/text-field-with-adornment.js +18 -23
  109. package/dist/components/react-query-builder-inputs/add-button.d.ts +8 -0
  110. package/dist/components/react-query-builder-inputs/add-button.js +17 -0
  111. package/dist/components/react-query-builder-inputs/combinator-selector.d.ts +5 -0
  112. package/dist/components/react-query-builder-inputs/combinator-selector.js +38 -0
  113. package/dist/components/react-query-builder-inputs/country-value-editor.d.ts +5 -0
  114. package/dist/components/react-query-builder-inputs/country-value-editor.js +46 -0
  115. package/dist/components/react-query-builder-inputs/custom-react-query-builder.d.ts +8 -0
  116. package/dist/components/react-query-builder-inputs/custom-react-query-builder.js +21 -0
  117. package/dist/components/react-query-builder-inputs/element-value-editor.d.ts +14 -0
  118. package/dist/components/react-query-builder-inputs/element-value-editor.js +69 -0
  119. package/dist/components/react-query-builder-inputs/property-value-editor.d.ts +9 -0
  120. package/dist/components/react-query-builder-inputs/property-value-editor.js +100 -0
  121. package/dist/components/react-query-builder-inputs/remove-button.d.ts +5 -0
  122. package/dist/components/react-query-builder-inputs/remove-button.js +9 -0
  123. package/dist/components/react-query-builder-inputs/text-value-editor.d.ts +5 -0
  124. package/dist/components/react-query-builder-inputs/text-value-editor.js +34 -0
  125. package/dist/components/react-query-builder-inputs/translated-value-editor.d.ts +5 -0
  126. package/dist/components/react-query-builder-inputs/translated-value-editor.js +58 -0
  127. package/dist/components/react-query-builder-inputs/use-convert-value.d.ts +9 -0
  128. package/dist/components/react-query-builder-inputs/use-convert-value.js +24 -0
  129. package/dist/components/react-query-builder-inputs/use-valid.d.ts +7 -0
  130. package/dist/components/react-query-builder-inputs/use-valid.js +13 -0
  131. package/dist/components/react-query-builder-inputs/value-editor.d.ts +5 -0
  132. package/dist/components/react-query-builder-inputs/value-editor.js +18 -0
  133. package/dist/components/react-query-builder-inputs/value-selector.d.ts +4 -0
  134. package/dist/components/react-query-builder-inputs/value-selector.js +14 -0
  135. package/dist/components/translations/filter-en.d.ts +22 -0
  136. package/dist/components/translations/filter-en.js +23 -0
  137. package/dist/components/translations/filter-fr.d.ts +22 -0
  138. package/dist/components/translations/filter-fr.js +23 -0
  139. package/dist/hooks/localized-countries-hook.d.ts +6 -0
  140. package/dist/hooks/localized-countries-hook.js +45 -0
  141. package/dist/hooks/predefined-properties-hook.d.ts +18 -0
  142. package/dist/hooks/predefined-properties-hook.js +43 -0
  143. package/dist/hooks/useDebounce.d.ts +7 -1
  144. package/dist/hooks/useSnackMessage.d.ts +23 -5
  145. package/dist/hooks/useSnackMessage.js +14 -12
  146. package/dist/index.d.ts +89 -142
  147. package/dist/index.js +172 -91
  148. package/dist/utils/FetchStatus.d.ts +12 -0
  149. package/dist/utils/FetchStatus.js +9 -0
  150. package/dist/utils/conversion-utils.d.ts +12 -0
  151. package/dist/utils/conversion-utils.js +22 -0
  152. package/dist/utils/equipment-types-for-predefined-properties-mapper.d.ts +3 -0
  153. package/dist/utils/equipment-types-for-predefined-properties-mapper.js +31 -0
  154. package/dist/utils/functions.d.ts +14 -0
  155. package/dist/utils/functions.js +16 -0
  156. package/dist/utils/types.d.ts +21 -0
  157. package/dist/utils/types.js +1 -0
  158. package/dist/utils/yup-config.d.ts +8 -0
  159. package/dist/utils/yup-config.js +16 -0
  160. package/package.json +15 -3
  161. package/dist/components/react-hook-form/select-input.d.ts +0 -17
  162. package/dist/components/react-hook-form/select-input.js +0 -30
@@ -0,0 +1,58 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useMemo } from "react";
3
+ import { MaterialValueEditor } from "@react-querybuilder/material";
4
+ import { useIntl } from "react-intl";
5
+ import useConvertValue from "./use-convert-value.js";
6
+ import { Autocomplete, TextField } from "@mui/material";
7
+ import useValid from "./use-valid.js";
8
+ const TranslatedValueEditor = (props) => {
9
+ const intl = useIntl();
10
+ const translatedValues = useMemo(() => {
11
+ var _a;
12
+ return (_a = props.values) == null ? void 0 : _a.map((v) => {
13
+ return {
14
+ name: v.name,
15
+ label: intl.formatMessage({ id: v.label })
16
+ };
17
+ });
18
+ }, [intl, props.values]);
19
+ const translatedValuesAutocomplete = useMemo(() => {
20
+ if (!props.values) {
21
+ return {};
22
+ }
23
+ return Object.fromEntries(
24
+ props.values.map((v) => [
25
+ v.name,
26
+ intl.formatMessage({ id: v.label })
27
+ ])
28
+ );
29
+ }, [intl, props.values]);
30
+ useConvertValue(props);
31
+ const valid = useValid(props);
32
+ if (!Array.isArray(props.value)) {
33
+ return /* @__PURE__ */ jsx(
34
+ MaterialValueEditor,
35
+ {
36
+ ...props,
37
+ values: translatedValues,
38
+ title: void 0
39
+ }
40
+ );
41
+ } else {
42
+ return /* @__PURE__ */ jsx(
43
+ Autocomplete,
44
+ {
45
+ value: props.value,
46
+ options: Object.keys(translatedValuesAutocomplete),
47
+ getOptionLabel: (code) => translatedValuesAutocomplete[code],
48
+ onChange: (event, value) => props.handleOnChange(value),
49
+ multiple: true,
50
+ fullWidth: true,
51
+ renderInput: (params) => /* @__PURE__ */ jsx(TextField, { ...params, error: !valid })
52
+ }
53
+ );
54
+ }
55
+ };
56
+ export {
57
+ TranslatedValueEditor as default
58
+ };
@@ -0,0 +1,9 @@
1
+ import { ValueEditorProps } from 'react-querybuilder';
2
+
3
+ /**
4
+ * Hook that convert a value of RQB from any to any[] and vice versa when the operator changes
5
+ * PS : can be extended to manage more than the IN operator
6
+ * PS 2 : don't use this if the operator can be another array operator (like BETWEEN) or change a bit the conditions
7
+ */
8
+ declare const useConvertValue: ({ operator, value, fieldData: { defaultValue }, handleOnChange, }: ValueEditorProps) => void;
9
+ export default useConvertValue;
@@ -0,0 +1,24 @@
1
+ import { useEffect } from "react";
2
+ import { OPERATOR_OPTIONS } from "../filter/constants/expert-filter-constants.js";
3
+ const useConvertValue = ({
4
+ operator,
5
+ value,
6
+ fieldData: { defaultValue },
7
+ handleOnChange
8
+ }) => {
9
+ useEffect(
10
+ () => {
11
+ if (operator === OPERATOR_OPTIONS.IN.name && !Array.isArray(value)) {
12
+ handleOnChange(value ? [value] : []);
13
+ } else if (operator !== OPERATOR_OPTIONS.IN.name && Array.isArray(value)) {
14
+ handleOnChange(value.length ? value[0] : defaultValue);
15
+ }
16
+ },
17
+ // We want to trigger this useEffect only if the operator change
18
+ // eslint-disable-next-line
19
+ [operator]
20
+ );
21
+ };
22
+ export {
23
+ useConvertValue as default
24
+ };
@@ -0,0 +1,7 @@
1
+ import { ValueEditorProps } from 'react-querybuilder';
2
+
3
+ /**
4
+ * Hook that return if a field of RQB is valid or not
5
+ */
6
+ declare const useValid: ({ validation }: ValueEditorProps) => boolean;
7
+ export default useValid;
@@ -0,0 +1,13 @@
1
+ const useValid = ({ validation }) => {
2
+ if (validation === void 0 || validation === null) {
3
+ return true;
4
+ }
5
+ if (typeof validation === "boolean") {
6
+ return validation;
7
+ }
8
+ const convertedValidation = validation;
9
+ return convertedValidation.valid;
10
+ };
11
+ export {
12
+ useValid as default
13
+ };
@@ -0,0 +1,5 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { ValueEditorProps } from 'react-querybuilder';
3
+
4
+ declare const ValueEditor: FunctionComponent<ValueEditorProps>;
5
+ export default ValueEditor;
@@ -0,0 +1,18 @@
1
+ import "react/jsx-runtime";
2
+ import "react";
3
+ import "@react-querybuilder/material";
4
+ import "./country-value-editor.js";
5
+ import "./translated-value-editor.js";
6
+ import "./text-value-editor.js";
7
+ import "@mui/material/Box";
8
+ import "react-hook-form";
9
+ import "../filter/constants/field-constants.js";
10
+ import "../filter/expert/expert-filter.type.js";
11
+ import "../filter/constants/equipment-types.js";
12
+ import { V } from "../../chunks/criteria-based-filter-edition-dialog.BEXoNmzz.js";
13
+ import "../../utils/ElementType.js";
14
+ import "./property-value-editor.js";
15
+ import "../filter/constants/filter-constants.js";
16
+ export {
17
+ V as default
18
+ };
@@ -0,0 +1,4 @@
1
+ import { ValueSelectorProps } from 'react-querybuilder';
2
+
3
+ declare const ValueSelector: (props: ValueSelectorProps) => import("react/jsx-runtime").JSX.Element;
4
+ export default ValueSelector;
@@ -0,0 +1,14 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { MaterialValueSelector } from "@react-querybuilder/material";
3
+ const ValueSelector = (props) => {
4
+ return /* @__PURE__ */ jsx(
5
+ MaterialValueSelector,
6
+ {
7
+ ...props,
8
+ title: void 0
9
+ }
10
+ );
11
+ };
12
+ export {
13
+ ValueSelector as default
14
+ };
@@ -0,0 +1,22 @@
1
+ export default filter_en;
2
+ declare namespace filter_en {
3
+ export let OR: string;
4
+ export let AND: string;
5
+ export let rule: string;
6
+ export let subGroup: string;
7
+ export let is: string;
8
+ export let contains: string;
9
+ export let beginsWith: string;
10
+ export let endsWith: string;
11
+ export let exists: string;
12
+ export let not_exists: string;
13
+ export let between: string;
14
+ let _in: string;
15
+ export { _in as in };
16
+ export let isPartOf: string;
17
+ export let isNotPartOf: string;
18
+ export let emptyRule: string;
19
+ export let incorrectRule: string;
20
+ export let betweenRule: string;
21
+ export let emptyGroup: string;
22
+ }
@@ -0,0 +1,23 @@
1
+ const filter_en = {
2
+ OR: "OR",
3
+ AND: "AND",
4
+ rule: "rule",
5
+ subGroup: "subgroup",
6
+ is: "is",
7
+ contains: "contains",
8
+ beginsWith: "begins with",
9
+ endsWith: "ends with",
10
+ exists: "exists",
11
+ not_exists: "not exists",
12
+ between: "between",
13
+ in: "in",
14
+ isPartOf: "is part of",
15
+ isNotPartOf: "is not part of",
16
+ emptyRule: "Filter contains an empty field",
17
+ incorrectRule: "Filter contains an incorrect field",
18
+ betweenRule: "Left value of 'between' rule have to be lower than the right value",
19
+ emptyGroup: "Filter contains an empty group. Consider removing it or adding rules to this group"
20
+ };
21
+ export {
22
+ filter_en as default
23
+ };
@@ -0,0 +1,22 @@
1
+ export default filter_fr;
2
+ declare namespace filter_fr {
3
+ export let OR: string;
4
+ export let AND: string;
5
+ export let rule: string;
6
+ export let subGroup: string;
7
+ export let is: string;
8
+ export let contains: string;
9
+ export let beginsWith: string;
10
+ export let endsWith: string;
11
+ export let exists: string;
12
+ export let not_exists: string;
13
+ export let between: string;
14
+ let _in: string;
15
+ export { _in as in };
16
+ export let isPartOf: string;
17
+ export let isNotPartOf: string;
18
+ export let emptyRule: string;
19
+ export let incorrectRule: string;
20
+ export let betweenRule: string;
21
+ export let emptyGroup: string;
22
+ }
@@ -0,0 +1,23 @@
1
+ const filter_fr = {
2
+ OR: "OU",
3
+ AND: "ET",
4
+ rule: "règle",
5
+ subGroup: "sous-groupe",
6
+ is: "est",
7
+ contains: "contient",
8
+ beginsWith: "commence par",
9
+ endsWith: "finit par",
10
+ exists: "existe",
11
+ not_exists: "n'existe pas",
12
+ between: "entre",
13
+ in: "dans",
14
+ isPartOf: "fait partie de",
15
+ isNotPartOf: "ne fait pas partie de",
16
+ emptyRule: "Le filtre contient un champ vide",
17
+ incorrectRule: "Le filtre contient un champ incorrect",
18
+ betweenRule: "La valeur de gauche d'une règle 'entre' doit être inférieure à la valeur de droite",
19
+ emptyGroup: "Le filtre contient un groupe vide. Supprimez le ou ajoutez des règles à ce groupe"
20
+ };
21
+ export {
22
+ filter_fr as default
23
+ };
@@ -0,0 +1,6 @@
1
+ export function getSystemLanguage(): string;
2
+ export function getComputedLanguage(language: any): any;
3
+ export function useLocalizedCountries(language: any): {
4
+ translate: (countryCode: any) => any;
5
+ countryCodes: string[];
6
+ };
@@ -0,0 +1,45 @@
1
+ import { useState, useEffect, useMemo, useCallback } from "react";
2
+ import localizedCountries from "localized-countries";
3
+ import countriesFr from "localized-countries/data/fr";
4
+ import countriesEn from "localized-countries/data/en";
5
+ import { LANG_ENGLISH, LANG_SYSTEM, LANG_FRENCH } from "../components/TopBar/TopBar.js";
6
+ const supportedLanguages = [LANG_FRENCH, LANG_ENGLISH];
7
+ const getSystemLanguage = () => {
8
+ const systemLanguage = navigator.language.split(/[-_]/)[0];
9
+ return supportedLanguages.includes(systemLanguage) ? systemLanguage : LANG_ENGLISH;
10
+ };
11
+ const getComputedLanguage = (language) => {
12
+ return language === LANG_SYSTEM ? getSystemLanguage() : language;
13
+ };
14
+ const useLocalizedCountries = (language) => {
15
+ const [localizedCountriesModule, setLocalizedCountriesModule] = useState();
16
+ useEffect(() => {
17
+ const lang = getComputedLanguage(language).substring(0, 2);
18
+ let localizedCountriesResult;
19
+ if (lang === "fr") {
20
+ localizedCountriesResult = localizedCountries(countriesFr);
21
+ } else if (lang === "en") {
22
+ localizedCountriesResult = localizedCountries(countriesEn);
23
+ } else {
24
+ console.warn(
25
+ 'Unsupported language "' + lang + '" for countries translation, we use english as default'
26
+ );
27
+ localizedCountriesResult = localizedCountries(countriesEn);
28
+ }
29
+ setLocalizedCountriesModule(localizedCountriesResult);
30
+ }, [language]);
31
+ const countryCodes = useMemo(
32
+ () => localizedCountriesModule ? Object.keys(localizedCountriesModule.object()) : [],
33
+ [localizedCountriesModule]
34
+ );
35
+ const translate = useCallback(
36
+ (countryCode) => localizedCountriesModule ? localizedCountriesModule.get(countryCode) : "",
37
+ [localizedCountriesModule]
38
+ );
39
+ return { translate, countryCodes };
40
+ };
41
+ export {
42
+ getComputedLanguage,
43
+ getSystemLanguage,
44
+ useLocalizedCountries
45
+ };
@@ -0,0 +1,18 @@
1
+ import { EquipmentType, PredefinedProperties } from '../utils/types.ts';
2
+ import { Dispatch, SetStateAction } from 'react';
3
+
4
+ interface Metadata {
5
+ name: string;
6
+ url: string;
7
+ appColor: string;
8
+ hiddenInAppsMenu: boolean;
9
+ resources: unknown;
10
+ }
11
+ export interface StudyMetadata extends Metadata {
12
+ name: 'Study';
13
+ predefinedEquipmentProperties: {
14
+ [networkElementType: string]: PredefinedProperties;
15
+ };
16
+ }
17
+ export declare const usePredefinedProperties: (initialType: EquipmentType | null) => [PredefinedProperties, Dispatch<SetStateAction<EquipmentType | null>>];
18
+ export {};
@@ -0,0 +1,43 @@
1
+ import { useState, useContext, useEffect } from "react";
2
+ import { mapEquipmentTypeForPredefinedProperties } from "../utils/equipment-types-for-predefined-properties-mapper.js";
3
+ import { useSnackMessage } from "./useSnackMessage.js";
4
+ import { FilterContext } from "../components/filter/filter-context.js";
5
+ const isStudyMetadata = (metadata) => {
6
+ return metadata.name === "Study";
7
+ };
8
+ const fetchPredefinedProperties = async (equipmentType, fetchAppsAndUrls) => {
9
+ var _a;
10
+ const networkEquipmentType = mapEquipmentTypeForPredefinedProperties(equipmentType);
11
+ if (networkEquipmentType === void 0) {
12
+ return Promise.resolve(void 0);
13
+ }
14
+ const res = await fetchAppsAndUrls();
15
+ const studyMetadata = res.filter(isStudyMetadata);
16
+ if (!studyMetadata) {
17
+ return Promise.reject("Study entry could not be found in metadata");
18
+ }
19
+ return (_a = studyMetadata[0].predefinedEquipmentProperties) == null ? void 0 : _a[networkEquipmentType];
20
+ };
21
+ const usePredefinedProperties = (initialType) => {
22
+ const [type, setType] = useState(initialType);
23
+ const [equipmentPredefinedProps, setEquipmentPredefinedProps] = useState({});
24
+ const { snackError } = useSnackMessage();
25
+ const { fetchAppsAndUrls } = useContext(FilterContext);
26
+ useEffect(() => {
27
+ if (fetchAppsAndUrls && type !== null) {
28
+ fetchPredefinedProperties(type, fetchAppsAndUrls).then((p) => {
29
+ if (p !== void 0) {
30
+ setEquipmentPredefinedProps(p);
31
+ }
32
+ }).catch((error) => {
33
+ snackError({
34
+ messageTxt: error.message ?? error
35
+ });
36
+ });
37
+ }
38
+ }, [type, setEquipmentPredefinedProps, snackError, fetchAppsAndUrls]);
39
+ return [equipmentPredefinedProps, setType];
40
+ };
41
+ export {
42
+ usePredefinedProperties
43
+ };
@@ -1 +1,7 @@
1
- export function useDebounce(func: any, delay?: number): any;
1
+ /**
2
+ * Copyright (c) 2023, RTE (http://www.rte-france.com)
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+ */
7
+ export declare const useDebounce: (func: (...args: any[]) => any, delay?: number) => ((...args: any[]) => any) & import('@mui/utils/debounce').Cancelable;
@@ -1,5 +1,23 @@
1
- export function useSnackMessage(): {
2
- snackError: (snackInputs: any) => void;
3
- snackInfo: (snackInputs: any) => void;
4
- snackWarning: (snackInputs: any) => void;
5
- };
1
+ /**
2
+ * Copyright (c) 2021, RTE (http://www.rte-france.com)
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
+ */
7
+ interface SnackInputs {
8
+ messageTxt?: string;
9
+ messageId?: string;
10
+ messageValues?: {
11
+ [key: string]: string;
12
+ };
13
+ headerTxt?: string;
14
+ headerId?: string;
15
+ headerValues?: Record<string, string>;
16
+ }
17
+ export interface UseSnackMessageReturn {
18
+ snackError: (snackInputs: SnackInputs) => void;
19
+ snackWarning: (snackInputs: SnackInputs) => void;
20
+ snackInfo: (snackInputs: SnackInputs) => void;
21
+ }
22
+ export declare function useSnackMessage(): UseSnackMessageReturn;
23
+ export {};
@@ -26,26 +26,28 @@ function useSnackMessage() {
26
26
  }
27
27
  function makeSnackbar(snackInputs, intlRef, enqueueSnackbar, level, persistent) {
28
28
  const message = checkAndTranslateIfNecessary(
29
+ intlRef,
29
30
  snackInputs.messageTxt,
30
31
  snackInputs.messageId,
31
- snackInputs.messageValues,
32
- intlRef
32
+ snackInputs.messageValues
33
33
  );
34
34
  const header = checkAndTranslateIfNecessary(
35
+ intlRef,
35
36
  snackInputs.headerTxt,
36
37
  snackInputs.headerId,
37
- snackInputs.headerValues,
38
- intlRef
39
- );
40
- displayMessageWithSnackbar(
41
- message,
42
- header,
43
- enqueueSnackbar,
44
- level,
45
- persistent
38
+ snackInputs.headerValues
46
39
  );
40
+ if (message !== null && header !== null) {
41
+ displayMessageWithSnackbar(
42
+ message,
43
+ header,
44
+ enqueueSnackbar,
45
+ level,
46
+ persistent
47
+ );
48
+ }
47
49
  }
48
- function checkAndTranslateIfNecessary(txt, id, values, intlRef) {
50
+ function checkAndTranslateIfNecessary(intlRef, txt, id, values) {
49
51
  checkInputs(txt, id, values);
50
52
  return txt ?? (id ? intlRef.current.formatMessage(
51
53
  {