From de6d53532992710ec4e92919fa24545d3d312487 Mon Sep 17 00:00:00 2001 From: adipaul1981 Date: Wed, 25 Sep 2024 14:14:25 -0400 Subject: [PATCH] fix: CQDG-830 use pattern for validate the name of Sets and Filters (#310) * fix: CQDG-830 use pattern for validate the name of Sets and Filters * fix: CQDG-830 review comments --- src/common/constants.ts | 2 ++ src/locales/en.ts | 1 + src/locales/fr.ts | 1 + src/utils/translation.ts | 6 ++++++ .../DashboardCards/SavedFilters/EditModal/index.tsx | 12 +++++++++++- .../SavedSets/CreateEditModal/index.tsx | 12 +++++++++++- .../DataExploration/components/PageContent/index.tsx | 3 ++- 7 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/common/constants.ts b/src/common/constants.ts index cf3773a6..49b904dc 100644 --- a/src/common/constants.ts +++ b/src/common/constants.ts @@ -15,6 +15,8 @@ export const FILTER_ID_QUERY_PARAM_KEY = 'filterId'; export const SHARED_FILTER_ID_QUERY_PARAM_KEY = 'sharedFilterId'; export const MAX_TITLE_LENGTH = 200; +// This regex needs to match the one set in Users-Api: +export const SET_FILTER_NAME_REGEX = /^[\w\s()\-_,.|:'[\]]+$/iu; export const MAX_ITEMS_QUERY = Number( EnvironmentVariables.configFor('ES_MAX_ITEMS_QUERY') || 10000, diff --git a/src/locales/en.ts b/src/locales/en.ts index af2b1ffc..15c46660 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -762,6 +762,7 @@ const en = { description: 'You are about to delete all your queries. They will be lost forever.', }, }, + pattern: 'Permitted characters: A-Z a-z 0-9 ()[]-_:|.,', }, savedSets: { modal: { diff --git a/src/locales/fr.ts b/src/locales/fr.ts index 749ffa4f..02301a41 100644 --- a/src/locales/fr.ts +++ b/src/locales/fr.ts @@ -769,6 +769,7 @@ const fr = { 'Vous êtes sur le point de supprimer toutes vos requêtes. Ils seront perdus à jamais.', }, }, + pattern: 'Caractères permis : A-Z a-z 0-9 ()[]-_:|,.', }, savedSets: { modal: { diff --git a/src/utils/translation.ts b/src/utils/translation.ts index f78b8609..c6c4bf54 100644 --- a/src/utils/translation.ts +++ b/src/utils/translation.ts @@ -9,6 +9,8 @@ import { ageCategoriesKeyLabel } from 'graphql/participants/models'; import { IUserSetOutput } from 'services/api/savedSet/models'; +import { SET_FILTER_NAME_REGEX } from '../common/constants'; + export const getEntityConsequenceDictionary = () => ({ consequence: intl.get('entities.variant.consequences.consequence'), impactTag: { @@ -162,6 +164,10 @@ export const getQueryBuilderDictionary = ( error: { fieldRequired: intl.get('global.forms.errors.requiredField'), }, + pattern: { + message: intl.get('components.querybuilder.pattern'), + regex: SET_FILTER_NAME_REGEX, + }, }, popupConfirm: { delete: { diff --git a/src/views/Dashboard/components/DashboardCards/SavedFilters/EditModal/index.tsx b/src/views/Dashboard/components/DashboardCards/SavedFilters/EditModal/index.tsx index 44190c33..558e34e0 100644 --- a/src/views/Dashboard/components/DashboardCards/SavedFilters/EditModal/index.tsx +++ b/src/views/Dashboard/components/DashboardCards/SavedFilters/EditModal/index.tsx @@ -3,7 +3,7 @@ import { useDispatch } from 'react-redux'; import { WarningFilled } from '@ant-design/icons'; import { Form, Input, Modal } from 'antd'; -import { MAX_TITLE_LENGTH } from 'common/constants'; +import { MAX_TITLE_LENGTH, SET_FILTER_NAME_REGEX } from 'common/constants'; import { TUserSavedFilter } from 'services/api/savedFilter/models'; import { updateSavedFilter } from 'store/savedFilter/thunks'; @@ -73,6 +73,16 @@ const EditModal = ({ visible = false, onCancel, filter }: OwnProps) => { message: intl.get('global.forms.errors.requiredField'), validateTrigger: 'onSubmit', }, + { + type: 'string', + message: ( + + {intl.get('components.querybuilder.pattern')} + + ), + pattern: SET_FILTER_NAME_REGEX, + validateTrigger: 'onSubmit', + }, ]} required={false} className={styles.filterEditFormItem} diff --git a/src/views/Dashboard/components/DashboardCards/SavedSets/CreateEditModal/index.tsx b/src/views/Dashboard/components/DashboardCards/SavedSets/CreateEditModal/index.tsx index 443fb612..72cb0346 100644 --- a/src/views/Dashboard/components/DashboardCards/SavedSets/CreateEditModal/index.tsx +++ b/src/views/Dashboard/components/DashboardCards/SavedSets/CreateEditModal/index.tsx @@ -6,7 +6,7 @@ import { ISqonGroupFilter } from '@ferlab/ui/core/data/sqon/types'; import { Form, Input, Modal } from 'antd'; import { Store } from 'antd/lib/form/interface'; -import { MAX_TITLE_LENGTH } from 'common/constants'; +import { MAX_TITLE_LENGTH, SET_FILTER_NAME_REGEX } from 'common/constants'; import filtersToName from 'common/sqonToName'; import { SetActionType } from 'components/uiKit/SetsManagementDropdown'; import { IUserSetOutput, SetType } from 'services/api/savedSet/models'; @@ -181,6 +181,16 @@ const CreateEditModal = ({ message: intl.get('global.forms.errors.requiredField'), validateTrigger: 'onSubmit', }, + { + type: 'string', + message: ( + + {intl.get('components.querybuilder.pattern')} + + ), + pattern: SET_FILTER_NAME_REGEX, + validateTrigger: 'onSubmit', + }, ]} required={false} > diff --git a/src/views/DataExploration/components/PageContent/index.tsx b/src/views/DataExploration/components/PageContent/index.tsx index 8125de32..3398afee 100644 --- a/src/views/DataExploration/components/PageContent/index.tsx +++ b/src/views/DataExploration/components/PageContent/index.tsx @@ -36,7 +36,7 @@ import { TAB_IDS, } from 'views/DataExploration/utils/constant'; -import { SHARED_FILTER_ID_QUERY_PARAM_KEY } from 'common/constants'; +import { MAX_TITLE_LENGTH, SHARED_FILTER_ID_QUERY_PARAM_KEY } from 'common/constants'; import GenericFilters from 'components/uiKit/FilterList/GenericFilters'; import useQBStateWithSavedFilters from 'hooks/useQBStateWithSavedFilters'; import { SavedFilterTag } from 'services/api/savedFilter/models'; @@ -260,6 +260,7 @@ const PageContent = ({ onSaveFilter: handleOnSaveFilter, onDeleteFilter: handleOnDeleteFilter, onSetAsFavorite: handleOnSaveAsFavorite, + maxNameCapSavedQuery: MAX_TITLE_LENGTH, }} facetFilterConfig={{ enable: true,