import React from "react"; import { connect } from "react-redux"; import { Button, Classes, Code, Colors, Dialog, InputGroup, Tooltip, } from "@blueprintjs/core"; @connect((state) => ({ idhash: state.config?.parameters?.["annotations-user-data-idhash"] ?? null, annotations: state.annotations, auth: state.config?.authentication, userInfo: state.userInfo, writableCategoriesEnabled: state.config?.parameters?.annotations ?? false, writableGenesetsEnabled: !( state.config?.parameters?.annotations_genesets_readonly ?? true ), })) class FilenameDialog extends React.Component { constructor(props) { super(props); this.state = { filenameText: "", }; } dismissFilenameDialog = () => {}; handleCreateFilename = () => { const { dispatch } = this.props; const { filenameText } = this.state; dispatch({ type: "set annotations collection name", data: filenameText, }); }; filenameError = () => { const legalNames = /^\w+$/; const { filenameText } = this.state; let err = false; if (filenameText === "") { err = "empty_string"; } else if (!legalNames.test(filenameText)) { /* IMPORTANT: this test must ultimately match the test applied by the backend, which is designed to ensure a safe file name can be created from the data collection name. If you change this, you will also need to change the validation code in the backend, or it will have no effect. */ err = "characters"; } return err; }; filenameErrorMessage = () => { const err = this.filenameError(); let markup = null; if (err === "empty_string") { markup = ( Name cannot be blank ); } else if (err === "characters") { markup = ( Only alphanumeric and underscore allowed ); } return markup; }; render() { const { writableCategoriesEnabled, writableGenesetsEnabled, annotations, idhash, userInfo, } = this.props; const { filenameText } = this.state; return (writableCategoriesEnabled || writableGenesetsEnabled) && annotations.promptForFilename && !annotations.dataCollectionNameIsReadOnly && !annotations.dataCollectionName && userInfo.is_authenticated ? ( { e.preventDefault(); this.handleCreateFilename(); }} > Name your user generated data directory: this.setState({ filenameText: e.target.value }) } leftIcon="tag" data-testid="new-annotation-name" /> {this.filenameErrorMessage(filenameText)} {"Your annotations are stored in this file: "} {filenameText}-cell-labels-{idhash}.csv {"Your gene sets are stored in this file: "} {filenameText}-gene-sets-{idhash}.csv (We added a unique ID to your filename) Cancel Create user generated data directory ) : null; } } export default FilenameDialog;
Name your user generated data directory:
{this.filenameErrorMessage(filenameText)}
{"Your annotations are stored in this file: "} {filenameText}-cell-labels-{idhash}.csv
{filenameText}-cell-labels-{idhash}.csv
{"Your gene sets are stored in this file: "} {filenameText}-gene-sets-{idhash}.csv
{filenameText}-gene-sets-{idhash}.csv
(We added a unique ID to your filename)