bd3303616d7e41a9b7f618ec6742df558c8cc159
[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 * as 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     rules.find(aRule => text.match(aRule) !== null)
20         ? message
21             ? <Tooltip title={message}><ErrorIcon /></Tooltip>
22             : <ErrorIcon />
23         : null;
24
25 interface IllegalNamingWarningProps {
26     name: string;
27     validate: RegExp[];
28 }
29
30
31 export const IllegalNamingWarning = connect(
32     (state: RootState) => {
33         return {
34             validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
35                 [disallowSlash] : [])
36         };
37     })(({ name, validate }: IllegalNamingWarningProps) =>
38         <WarningComponent
39             text={name} rules={validate}
40             message="Names embedding '/' will be renamed or invisible to file system access (arv-mount or WebDAV)" />);