From ffbd8baae09874388380f566b901f1b08e9cc799 Mon Sep 17 00:00:00 2001 From: Antoine Bouhours <123802855+antoinebhs@users.noreply.github.com> Date: Tue, 12 Dec 2023 13:32:10 +0100 Subject: [PATCH] Remove the need for a secure context for the app (#296) --- package-lock.json | 25 ++++++++++++++++--- package.json | 2 ++ .../contingency-list-utils.js | 6 ++--- .../explicit-naming/explicit-naming-form.js | 3 ++- .../filter/expert/expert-filter-form.tsx | 3 ++- .../explicit-naming-filter-edition-dialog.js | 3 ++- .../explicit-naming-filter-form.tsx | 5 ++-- src/setupTests.js | 9 ------- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 740a7878d..4a399a4ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@types/node": "^20.2.5", "@types/react": "^18.2.9", "@types/react-dom": "^18.2.4", + "@types/uuid": "^9.0.6", "ace-builds": "^1.4.12", "ag-grid-community": "^29.0.0", "ag-grid-react": "^29.0.0", @@ -45,6 +46,7 @@ "redux": "^4.0.5", "typeface-roboto": "^1.0.0", "typescript": "^5.1.3", + "uuid": "^9.0.1", "yup": "^1.0.0" }, "devDependencies": { @@ -4412,6 +4414,11 @@ "resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz", "integrity": "sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==" }, + "node_modules/@types/uuid": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.6.tgz", + "integrity": "sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew==" + }, "node_modules/@types/ws": { "version": "8.5.4", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz", @@ -16045,6 +16052,14 @@ "websocket-driver": "^0.7.4" } }, + "node_modules/sockjs/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/source-list-map": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz", @@ -17170,9 +17185,13 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } diff --git a/package.json b/package.json index edf231a30..1e9ab5c2b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@types/node": "^20.2.5", "@types/react": "^18.2.9", "@types/react-dom": "^18.2.4", + "@types/uuid": "^9.0.6", "ace-builds": "^1.4.12", "ag-grid-community": "^29.0.0", "ag-grid-react": "^29.0.0", @@ -41,6 +42,7 @@ "redux": "^4.0.5", "typeface-roboto": "^1.0.0", "typescript": "^5.1.3", + "uuid": "^9.0.1", "yup": "^1.0.0" }, "scripts": { diff --git a/src/components/dialogs/contingency-list/contingency-list-utils.js b/src/components/dialogs/contingency-list/contingency-list-utils.js index 939a7cfa1..c01b2de01 100644 --- a/src/components/dialogs/contingency-list/contingency-list-utils.js +++ b/src/components/dialogs/contingency-list/contingency-list-utils.js @@ -24,11 +24,11 @@ import { } from '../../utils/field-constants'; import { ContingencyListType } from '../../../utils/elementType'; import { prepareContingencyListForBackend } from '../contingency-list-helper'; - +import { v4 as uuid4 } from 'uuid'; import { getCriteriaBasedFormData } from '../commons/criteria-based/criteria-based-utils'; export const makeDefaultRowData = () => ({ - [AG_GRID_ROW_UUID]: crypto.randomUUID(), + [AG_GRID_ROW_UUID]: uuid4(), [CONTINGENCY_NAME]: '', [EQUIPMENT_IDS]: [], }); @@ -63,7 +63,7 @@ export const getExplicitNamingFormDataFromFetchedElement = (response) => { result = response.identifierContingencyList?.identifiers?.map( (identifiers) => { return { - [AG_GRID_ROW_UUID]: crypto.randomUUID(), + [AG_GRID_ROW_UUID]: uuid4(), [CONTINGENCY_LIST_TYPE]: ContingencyListType.EXPLICIT_NAMING.id, [CONTINGENCY_NAME]: identifiers.contingencyId, diff --git a/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.js b/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.js index d22ac8657..d5b249923 100644 --- a/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.js +++ b/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.js @@ -22,6 +22,7 @@ import yup from '../../../utils/yup-config'; import { makeDefaultRowData } from '../contingency-list-utils'; import ChipsArrayEditor from '../../../utils/rhf-inputs/ag-grid-table-rhf/cell-editors/chips-array-editor'; import { ContingencyListType } from 'utils/elementType'; +import { v4 as uuid4 } from 'uuid'; export const getExplicitNamingSchema = (id) => { return { @@ -119,7 +120,7 @@ const ExplicitNamingForm = () => { if (csvData) { return csvData.map((value) => { return { - [AG_GRID_ROW_UUID]: crypto.randomUUID(), + [AG_GRID_ROW_UUID]: uuid4(), [CONTINGENCY_NAME]: value[0]?.trim() || '', [EQUIPMENT_IDS]: value[1] diff --git a/src/components/dialogs/filter/expert/expert-filter-form.tsx b/src/components/dialogs/filter/expert/expert-filter-form.tsx index 5804f682d..d1f49f79e 100644 --- a/src/components/dialogs/filter/expert/expert-filter-form.tsx +++ b/src/components/dialogs/filter/expert/expert-filter-form.tsx @@ -32,6 +32,7 @@ import yup from '../../../utils/yup-config'; import { FilterType } from '../../../../utils/elementType'; import CustomReactQueryBuilder from '../../../utils/rqb-inputs/custom-react-query-builder'; import { FieldType } from './expert-filter.type'; +import { v4 as uuid4 } from 'uuid'; export const EXPERT_FILTER_QUERY = 'rules'; @@ -74,7 +75,7 @@ const defaultQuery = { combinator: COMBINATOR_OPTIONS.AND.name, rules: [ { - id: crypto.randomUUID(), + id: uuid4(), field: FieldType.ID, operator: OPERATOR_OPTIONS.CONTAINS.name, value: '', diff --git a/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-edition-dialog.js b/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-edition-dialog.js index 7e14da845..e94e43b0d 100644 --- a/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-edition-dialog.js +++ b/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-edition-dialog.js @@ -27,6 +27,7 @@ import { } from '../../../utils/field-constants'; import { FetchStatus } from '../../../../utils/custom-hooks'; import { FilterForm } from '../filter-form'; +import { v4 as uuid4 } from 'uuid'; const formSchema = yup .object() @@ -75,7 +76,7 @@ const ExplicitNamingFilterEditionDialog = ({ [FILTER_EQUIPMENTS_ATTRIBUTES]: response[ FILTER_EQUIPMENTS_ATTRIBUTES ].map((row) => ({ - [AG_GRID_ROW_UUID]: crypto.randomUUID(), + [AG_GRID_ROW_UUID]: uuid4(), ...row, })), }); diff --git a/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-form.tsx b/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-form.tsx index 00bf2fe05..4eb18a3cb 100644 --- a/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-form.tsx +++ b/src/components/dialogs/filter/explicit-naming/explicit-naming-filter-form.tsx @@ -20,6 +20,7 @@ import { FilterType } from '../../../../utils/elementType'; import { NumericEditor } from '../../../utils/rhf-inputs/ag-grid-table-rhf/cell-editors/numericEditor'; import { toFloatOrNullValue } from '../../../utils/dialog-utils'; import InputWithPopupConfirmation from '../../../utils/rhf-inputs/select-inputs/input-with-popup-confirmation'; +import { v4 as uuid4 } from 'uuid'; export const FILTER_EQUIPMENTS_ATTRIBUTES = 'filterEquipmentsAttributes'; export const DISTRIBUTION_KEY = 'distributionKey'; @@ -82,7 +83,7 @@ interface FilterTableRow { function makeDefaultRowData(): FilterTableRow { return { - [AG_GRID_ROW_UUID]: crypto.randomUUID(), + [AG_GRID_ROW_UUID]: uuid4(), [EQUIPMENT_ID]: '', [DISTRIBUTION_KEY]: null, }; @@ -153,7 +154,7 @@ function ExplicitNamingFilterForm() { if (csvData) { return csvData.map((value: any) => { return { - [AG_GRID_ROW_UUID]: crypto.randomUUID(), + [AG_GRID_ROW_UUID]: uuid4(), [EQUIPMENT_ID]: value[0]?.trim(), [DISTRIBUTION_KEY]: toFloatOrNullValue(value[1]?.trim()), }; diff --git a/src/setupTests.js b/src/setupTests.js index 52548dd58..e373e4dd1 100644 --- a/src/setupTests.js +++ b/src/setupTests.js @@ -5,13 +5,4 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import crypto from 'crypto'; - -// make crypto.randomUUID() available in tests -window.crypto = { - randomUUID: function () { - return crypto.randomUUID(); - }, -}; - global.IS_REACT_ACT_ENVIRONMENT = true;