Skip to content

Commit 2a52513

Browse files
committed
Various fixes in src/components/Tags/*
1 parent f92a9e2 commit 2a52513

File tree

5 files changed

+28
-17
lines changed

5 files changed

+28
-17
lines changed

src/main/webapp/ui/src/components/Tags/AddTag.js

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ type AddTagArgs<
3434
disabled?: boolean,
3535
|};
3636

37+
/**
38+
* This component provides a button to add a tag to a list of tags.
39+
* It is parameterized by the type of tag that it will add, requiring that the
40+
* selected tag have all of the metadata when `enforceOntologies` is true.
41+
*/
3742
export default function AddTag<
3843
Toggle:
3944
| {|

src/main/webapp/ui/src/components/Tags/TagListing.js

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ type TagListingArgs = {|
5050
onClick?: (Tag) => void,
5151
|};
5252

53+
/**
54+
* This component provides a listing of tags, with the ability to delete tags
55+
* if `onDelete` is true, to show the associated metadata if
56+
* `showMetadataPopup` is true, and to perform an action when a tag is clicked
57+
* if `onClick` is provided.
58+
*/
5359
export default function TagListing({
5460
tags,
5561
size = "medium",

src/main/webapp/ui/src/components/Tags/TagValidation.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import { lift2 } from "../../util/optional";
1414
import { type Tag } from "../../stores/definitions/Tag";
1515

16-
/*
16+
/**
1717
* The max length of an individual tag. Chosen rather arbitrarily based on the
1818
* typically length of tags from the ontology file used for testing.
1919
*/
@@ -44,7 +44,7 @@ opaque type TagValidation =
4444

4545
const forbiddenCharacters = new Set("<>\\".split(""));
4646

47-
/*
47+
/**
4848
* Given a Tag, which is to say a simple string, there are some validations
4949
* that can be performed on it alone.
5050
*/
@@ -67,7 +67,7 @@ export const checkTagString = (tag: string): TagValidation => {
6767
return { reason: "NoIssues" };
6868
};
6969

70-
/*
70+
/**
7171
* In addition to the restrictions above, a tag entered by the user also has
7272
* some additional checks
7373
*/
@@ -85,16 +85,16 @@ export const checkUserInputString = (tag: string): TagValidation => {
8585
return checkTagString(tag);
8686
};
8787

88-
/*
88+
type InternalTag = {|
89+
...Tag,
90+
selected: boolean,
91+
|};
92+
/**
8993
* Internal to the components for rendering the means with which a user may
9094
* choose a tag, additional state is used to richly render these tags. This
9195
* additional state gives us additional information with which to validate
9296
* that a tag can be chosen.
9397
*/
94-
type InternalTag = {|
95-
...Tag,
96-
selected: boolean,
97-
|};
9898
export const checkInternalTag = (
9999
tag: InternalTag,
100100
{ enforceOntologies }: { enforceOntologies: boolean }
@@ -126,13 +126,19 @@ export const checkInternalTag = (
126126
* =======================
127127
*/
128128

129+
/**
130+
* For disabling a tab based on the validation of a tag.
131+
*/
129132
export const isAllowed = (tagValidation: TagValidation): boolean => {
130133
return (
131134
tagValidation.reason === "NoIssues" ||
132135
tagValidation.reason === "NoIssuesWithSourceInformation"
133136
);
134137
};
135138

139+
/**
140+
* For explaining why a tag is not allowed.
141+
*/
136142
export const helpText = (tagValidation: TagValidation): ?string => {
137143
if (tagValidation.reason === "NoIssues") return null;
138144
if (tagValidation.reason === "OntologiesAreEnforced")
@@ -156,8 +162,3 @@ export const helpText = (tagValidation: TagValidation): ?string => {
156162
return "Tags cannot contain consecutive whitespace characters.";
157163
}
158164
};
159-
160-
export const filterFieldError = (tagValidation: TagValidation): ?string => {
161-
if (tagValidation.reason === "NoIssues") return null;
162-
return helpText(tagValidation);
163-
};

src/main/webapp/ui/src/components/Tags/TagsCombobox.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
checkUserInputString,
2424
checkInternalTag,
2525
helpText,
26-
filterFieldError,
2726
isAllowed,
2827
} from "./TagValidation";
2928
import Alert from "@mui/material/Alert";
@@ -872,7 +871,7 @@ export default function TagsCombobox<
872871
setKeyboardFocusIndex(null);
873872
}}
874873
error={!isAllowed(checkUserInputString(filter))}
875-
helperText={filterFieldError(checkUserInputString(filter))}
874+
helperText={helpText(checkUserInputString(filter))}
876875
tabIndex={0}
877876
fullWidth
878877
value={filter}

src/main/webapp/ui/src/eln/sysadmin/users/TagsCombobox.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import FilterIcon from "@mui/icons-material/FilterAlt";
2020
import ListItemText from "@mui/material/ListItemText";
2121
import {
2222
checkUserInputString,
23-
filterFieldError,
23+
helpText,
2424
isAllowed,
2525
} from "../../../components/Tags/TagValidation";
2626
import Alert from "@mui/material/Alert";
@@ -607,7 +607,7 @@ export default function TagsCombobox({
607607
setKeyboardFocusIndex(null);
608608
}}
609609
error={!isAllowed(checkUserInputString(filter))}
610-
helperText={filterFieldError(checkUserInputString(filter))}
610+
helperText={helpText(checkUserInputString(filter))}
611611
tabIndex={0}
612612
fullWidth
613613
value={filter}

0 commit comments

Comments
 (0)