15856: Adds new component to show a conditional warning icon.
[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 { WarningIcon } from "~/components/icon/icon";
7 import { Tooltip } from "@material-ui/core";
8
9 interface WarningComponentProps {
10     text: string;
11     rules: RegExp[];
12     message: string;
13 }
14
15 export const WarningComponent = ({ text, rules, message }: WarningComponentProps) =>
16     rules.find(aRule => text.match(aRule) !== null)
17     ? message
18         ? <Tooltip title={message}><WarningIcon /></Tooltip>
19         : <WarningIcon />
20     : null;
21
22 interface IllegalNamingWarningProps {
23     name: string;
24 }
25
26 export const IllegalNamingWarning = ({ name }: IllegalNamingWarningProps) =>
27     <WarningComponent
28         text={name} rules={[/\//, /^\.{1,2}$/]}
29         message="Names being '.', '..' or including '/' cause issues with WebDAV, please edit it to something different." />;