Skip to content

Commit c45cc2a

Browse files
Changed from match regex to denied match
1 parent 679a522 commit c45cc2a

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

frontends/mdr-frontend/src/components/Dialog/Dialog.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export interface DialogField {
4444
help?: string; // potential help text
4545
accept?: string;
4646
inputMode?: InputMode;
47-
pattern?: string;
47+
patternRegex?: string;
48+
patternDeny?: string;
4849
patternErr?: string;
4950
}
5051

@@ -117,9 +118,13 @@ export const CrudDialog: React.FC<CrudDialogProps> = ({
117118
return;
118119
}
119120

120-
const regexFields = fields.filter((f) => f.pattern && createParams[f.name] && !new RegExp(f.pattern).test(createParams[f.name]));
121-
if (regexFields.length) {
122-
setCreateError(`The following fields have invalid values:\n > ${regexFields.map(f => f.patternErr).join("\n > ")}`);
121+
let patternErrors: any = [];
122+
const regexFields = fields.filter((f) => f.patternRegex && createParams[f.name] && !new RegExp(f.patternRegex).test(createParams[f.name]));
123+
patternErrors = [...patternErrors, ...regexFields];
124+
const deniedFields = fields.filter((f) => f.patternDeny && createParams[f.name] && new RegExp(f.patternDeny).test(createParams[f.name]));
125+
patternErrors = [...patternErrors, ...deniedFields];
126+
if (patternErrors.length) {
127+
setCreateError(`The following fields have invalid values:\n > ${patternErrors.map((f: any) => f.patternErr).join("\n > ")}`);
123128
return;
124129
}
125130

@@ -308,7 +313,7 @@ export const CrudDialog: React.FC<CrudDialogProps> = ({
308313
placeholder={`Enter ${field.label.toLowerCase()}`}
309314
onChange={(e) => handleFieldValueChange(field, e.target.value) }
310315
inputMode={field.inputMode}
311-
pattern={field.pattern}
316+
pattern={field.patternRegex}
312317
title={field.patternErr ?? ""}
313318
readOnly={field.readOnly || (isEditMode && field.name === "CreationDate")}
314319
/>

frontends/mdr-frontend/src/components/ModelExplorer/CreateOptFields.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { DialogField } from "../Dialog/Dialog";
22

33

4-
const PatternRegex = "^[A-Za-z][A-Za-z0-9_./-]*$";
5-
const PatternErrStr = " must start with a letter and contain only letters, numbers, underscores, periods, hyphens, and forward slashes.";
4+
const PatternDenyRegex = "[ ,:~]";
5+
const PatternDenyErr = " cannot contain spaces, commas, colons, or tildes.";
66
const capitalize = (s: string): string => { return s?.length ? s.charAt(0).toUpperCase() + s.slice(1) : ""; }
77

88
/** Dev Note: Once we get actual user data we should use that for Contributor and ContributorOrganization */
@@ -21,16 +21,16 @@ export const entityCreateFields = (model: any): DialogField[] => {
2121
type: "text" as const,
2222
label: "Name",
2323
required: true,
24-
pattern: PatternRegex,
25-
patternErr: "Name" + PatternErrStr,
24+
patternDeny: PatternDenyRegex,
25+
patternErr: "Name" + PatternDenyErr,
2626
},
2727
{
2828
name: "UniqueName",
2929
type: "text" as const,
3030
label: "Unique Name",
3131
required: true,
32-
pattern: PatternRegex,
33-
patternErr: "Unique Name" + PatternErrStr,
32+
patternDeny: PatternDenyRegex,
33+
patternErr: "Unique Name" + PatternDenyErr,
3434
},
3535
{ name: "Description", type: "text" as const, label: "Description" },
3636
{
@@ -107,16 +107,16 @@ export const attributeCreateFields = (model: any, valueSetId: string | number |
107107
type: "text" as const,
108108
label: "Name",
109109
required: true,
110-
pattern: PatternRegex,
111-
patternErr: "Name" + PatternErrStr,
110+
patternDeny: PatternDenyRegex,
111+
patternErr: "Name" + PatternDenyErr,
112112
},
113113
{
114114
name: "UniqueName",
115115
type: "text" as const,
116116
label: "Unique Name",
117117
required: true,
118-
pattern: PatternRegex,
119-
patternErr: "Unique Name" + PatternErrStr,
118+
patternDeny: PatternDenyRegex,
119+
patternErr: "Unique Name" + PatternDenyErr,
120120
},
121121
{
122122
name: "DataType",
@@ -199,8 +199,8 @@ export const valueSetCreateFields = (model: any): DialogField[] => {
199199
type: "text" as const,
200200
label: "Name",
201201
required: true,
202-
pattern: PatternRegex,
203-
patternErr: "Name" + PatternErrStr,
202+
patternDeny: PatternDenyRegex,
203+
patternErr: "Name" + PatternDenyErr,
204204
},
205205
{ name: "Description", type: "text" as const, label: "Description" },
206206
{
@@ -251,8 +251,8 @@ export const valueCreateFields = (model: any): DialogField[] => {
251251
type: "text" as const,
252252
label: "Value Name",
253253
required: true,
254-
pattern: PatternRegex,
255-
patternErr: "Value Name" + PatternErrStr,
254+
patternDeny: PatternDenyRegex,
255+
patternErr: "Value Name" + PatternDenyErr,
256256
},
257257
{ name: "Description", type: "text" as const, label: "Description" },
258258
{

0 commit comments

Comments
 (0)