Skip to content

Commit

Permalink
fix: CQDG-830 use pattern for validate the name of Sets and Filters (#…
Browse files Browse the repository at this point in the history
…310)

* fix: CQDG-830 use pattern for validate the name of Sets and Filters

* fix: CQDG-830 review comments
  • Loading branch information
adipaul1981 authored Sep 25, 2024
1 parent 7a2d294 commit de6d535
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -73,6 +73,16 @@ const EditModal = ({ visible = false, onCancel, filter }: OwnProps) => {
message: intl.get('global.forms.errors.requiredField'),
validateTrigger: 'onSubmit',
},
{
type: 'string',
message: (
<span>
<WarningFilled /> {intl.get('components.querybuilder.pattern')}
</span>
),
pattern: SET_FILTER_NAME_REGEX,
validateTrigger: 'onSubmit',
},
]}
required={false}
className={styles.filterEditFormItem}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -181,6 +181,16 @@ const CreateEditModal = ({
message: intl.get('global.forms.errors.requiredField'),
validateTrigger: 'onSubmit',
},
{
type: 'string',
message: (
<span>
<WarningFilled /> {intl.get('components.querybuilder.pattern')}
</span>
),
pattern: SET_FILTER_NAME_REGEX,
validateTrigger: 'onSubmit',
},
]}
required={false}
>
Expand Down
3 changes: 2 additions & 1 deletion src/views/DataExploration/components/PageContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -260,6 +260,7 @@ const PageContent = ({
onSaveFilter: handleOnSaveFilter,
onDeleteFilter: handleOnDeleteFilter,
onSetAsFavorite: handleOnSaveAsFavorite,
maxNameCapSavedQuery: MAX_TITLE_LENGTH,
}}
facetFilterConfig={{
enable: true,
Expand Down

0 comments on commit de6d535

Please sign in to comment.