mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-07 21:18:11 +08:00
fix: more accurate validation on geneset name (#2429)
This commit is contained in:
@@ -42,7 +42,7 @@ class AnnoDialog extends React.PureComponent {
|
|||||||
<p
|
<p
|
||||||
style={{
|
style={{
|
||||||
marginTop: 7,
|
marginTop: 7,
|
||||||
visibility: validationError ? "visible" : "hidden",
|
visibility: errorMessage !== "" ? "visible" : "hidden",
|
||||||
color: Colors.ORANGE3,
|
color: Colors.ORANGE3,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ class GeneSet extends React.Component {
|
|||||||
)}
|
)}
|
||||||
{isOpen && !genesetIsEmpty && this.renderGenes()}
|
{isOpen && !genesetIsEmpty && this.renderGenes()}
|
||||||
<EditGenesetNameDialogue
|
<EditGenesetNameDialogue
|
||||||
parentGeneset={setName}
|
originalGenesetName={setName}
|
||||||
parentGenesetDescription={genesetDescription}
|
originalGenesetDescription={genesetDescription}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -90,14 +90,15 @@ class CreateGenesetDialogue extends React.PureComponent {
|
|||||||
this.setState({ genesetDescription: e });
|
this.setState({ genesetDescription: e });
|
||||||
};
|
};
|
||||||
|
|
||||||
instruction = (genesetName, genesets) => genesets.has(genesetName)
|
instruction = (genesetName, genesets) =>
|
||||||
|
genesets.has(genesetName)
|
||||||
? "Gene set name must be unique."
|
? "Gene set name must be unique."
|
||||||
: "New, unique gene set name";
|
: "New, unique gene set name";
|
||||||
|
|
||||||
validate = (genesetName, genesets) => {
|
validate = (genesetName, genesets) => {
|
||||||
if (genesets.has(genesetName)) {
|
if (genesets.has(genesetName)) {
|
||||||
this.setState({
|
this.setState({
|
||||||
nameErrorMessage: "There is already a geneset with that name",
|
nameErrorMessage: "There is already a gene set with that name",
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,18 @@ class RenameGeneset extends React.PureComponent {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
newGenesetName: props.parentGeneset,
|
newGenesetName: props.originalGenesetName,
|
||||||
newGenesetDescription: props.parentGenesetDescription,
|
newGenesetDescription: props.originalGenesetDescription,
|
||||||
|
nameErrorMessage: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
disableEditGenesetNameMode = (e) => {
|
disableEditGenesetNameMode = (e) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
|
const { originalGenesetDescription, originalGenesetName } = this.props;
|
||||||
this.setState({
|
this.setState({
|
||||||
newGenesetName: "",
|
newGenesetName: originalGenesetName,
|
||||||
newGenesetDescription: "",
|
newGenesetDescription: originalGenesetDescription,
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "geneset: disable rename geneset mode",
|
type: "geneset: disable rename geneset mode",
|
||||||
@@ -59,22 +61,57 @@ class RenameGeneset extends React.PureComponent {
|
|||||||
this.setState({ newGenesetDescription: e });
|
this.setState({ newGenesetDescription: e });
|
||||||
};
|
};
|
||||||
|
|
||||||
validate = (genesetName, genesets) => (
|
validate = (
|
||||||
!genesets.has(genesetName) &&
|
originalGenesetName,
|
||||||
|
newGenesetName,
|
||||||
|
originalGenesetDescription,
|
||||||
|
newGenesetDescription,
|
||||||
|
genesets
|
||||||
|
) => {
|
||||||
|
if (
|
||||||
|
originalGenesetName !== newGenesetName &&
|
||||||
|
genesets.has(newGenesetName)
|
||||||
|
) {
|
||||||
|
this.setState({
|
||||||
|
nameErrorMessage: `There is already a gene set with that name`,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
// eslint-disable-next-line no-control-regex -- unicode 0-31 127-65535
|
// eslint-disable-next-line no-control-regex -- unicode 0-31 127-65535
|
||||||
genesetName.match(/^\s|[\u0000-\u001F\u007F-\uFFFF]|[ ]{2,}|^$|\s$/g)
|
newGenesetName.match(/^[\u0000-\u001F\u007F-\uFFFF]|[ ]{2,}/g)?.length
|
||||||
?.length
|
) {
|
||||||
);
|
this.setState({
|
||||||
|
nameErrorMessage:
|
||||||
|
"Gene set names can only contain alphanumeric characters and the following special characters: ! ” # $ % ’ ( ) * + , - . / : ; < = > ? @ ] ^ _ ` | ~",
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
nameErrorMessage: "",
|
||||||
|
});
|
||||||
|
if (
|
||||||
|
originalGenesetName === newGenesetName &&
|
||||||
|
originalGenesetDescription === newGenesetDescription
|
||||||
|
)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { newGenesetName, newGenesetDescription } = this.state;
|
const { newGenesetName, newGenesetDescription, nameErrorMessage } =
|
||||||
const { genesetsUI, parentGeneset, parentGenesetDescription, genesets } =
|
this.state;
|
||||||
this.props;
|
const {
|
||||||
|
genesetsUI,
|
||||||
|
originalGenesetName,
|
||||||
|
originalGenesetDescription,
|
||||||
|
genesets,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AnnoDialog
|
<AnnoDialog
|
||||||
isActive={genesetsUI.isEditingGenesetName === parentGeneset}
|
isActive={genesetsUI.isEditingGenesetName === originalGenesetName}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
"data-testid": `${genesetsUI.isEditingGenesetName}:rename-geneset-dialog`,
|
"data-testid": `${genesetsUI.isEditingGenesetName}:rename-geneset-dialog`,
|
||||||
}}
|
}}
|
||||||
@@ -82,15 +119,23 @@ class RenameGeneset extends React.PureComponent {
|
|||||||
"data-testid": `${genesetsUI.isEditingGenesetName}:submit-geneset`,
|
"data-testid": `${genesetsUI.isEditingGenesetName}:submit-geneset`,
|
||||||
}}
|
}}
|
||||||
title="Edit gene set name and description"
|
title="Edit gene set name and description"
|
||||||
instruction={`Rename ${genesetsUI.isEditingGenesetName}`}
|
instruction={
|
||||||
|
<>
|
||||||
|
Rename <b>{genesetsUI.isEditingGenesetName}</b>
|
||||||
|
</>
|
||||||
|
}
|
||||||
cancelTooltipContent="Close this dialog without renaming the gene set."
|
cancelTooltipContent="Close this dialog without renaming the gene set."
|
||||||
primaryButtonText="Edit gene set name and description"
|
primaryButtonText="Edit gene set name and description"
|
||||||
text={newGenesetName}
|
text={newGenesetName}
|
||||||
secondaryText={newGenesetDescription}
|
secondaryText={newGenesetDescription}
|
||||||
validationError={
|
validationError={this.validate(
|
||||||
this.validate(newGenesetName, genesets) &&
|
originalGenesetName,
|
||||||
parentGenesetDescription === newGenesetDescription
|
newGenesetName,
|
||||||
}
|
originalGenesetDescription,
|
||||||
|
newGenesetDescription,
|
||||||
|
genesets
|
||||||
|
)}
|
||||||
|
errorMessage={nameErrorMessage}
|
||||||
annoInput={
|
annoInput={
|
||||||
<LabelInput
|
<LabelInput
|
||||||
label={newGenesetName}
|
label={newGenesetName}
|
||||||
|
|||||||
Reference in New Issue
Block a user