Merge branch '15256-removing-files-during-upload'
[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 { invalidNamingRules } from "~/validators/valid-name";
8 import { Tooltip } from "@material-ui/core";
9
10 interface WarningComponentProps {
11     text: string;
12     rules: RegExp[];
13     message: string;
14 }
15
16 export const WarningComponent = ({ text, rules, message }: WarningComponentProps) =>
17     rules.find(aRule => text.match(aRule) !== null)
18     ? message
19         ? <Tooltip title={message}><ErrorIcon /></Tooltip>
20         : <ErrorIcon />
21     : null;
22
23 interface IllegalNamingWarningProps {
24     name: string;
25 }
26
27 export const IllegalNamingWarning = ({ name }: IllegalNamingWarningProps) =>
28     <WarningComponent
29         text={name} rules={invalidNamingRules}
30         message="Names being '.', '..' or including '/' cause issues with WebDAV, please edit it to something different." />;