Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / components / warning / warning.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { ErrorIcon } from "components/icon/icon";
7 import { Tooltip } from "@material-ui/core";
8 import { disallowSlash } from "validators/valid-name";
9 import { connect } from "react-redux";
10 import { RootState } from "store/store";
11
12 interface WarningComponentProps {
13     text: string;
14     rules: RegExp[];
15     message: string;
16 }
17
18 export const WarningComponent = ({ text, rules, message }: WarningComponentProps) =>
19     !text ? <Tooltip title={"No name"}><ErrorIcon /></Tooltip>
20         : (rules.find(aRule => text.match(aRule) !== null)
21             ? message
22                 ? <Tooltip title={message}><ErrorIcon /></Tooltip>
23                 : <ErrorIcon />
24             : null);
25
26 interface IllegalNamingWarningProps {
27     name: string;
28     validate: RegExp[];
29 }
30
31
32 export const IllegalNamingWarning = connect(
33     (state: RootState) => {
34         return {
35             validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
36                 [disallowSlash] : [])
37         };
38     })(({ name, validate }: IllegalNamingWarningProps) =>
39         <WarningComponent
40             text={name} rules={validate}
41             message="Names embedding '/' will be renamed or invisible to file system access (arv-mount or WebDAV)" />);