IllegalNamingWarning is conditional on ForwardSlashNameSubstitution
[arvados-workbench2.git] / src / components / warning / warning.tsx
index 1a8f44562c99af72ead38972bf0d9b7c3690b223..bd3303616d7e41a9b7f618ec6742df558c8cc159 100644 (file)
@@ -3,8 +3,11 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { WarningIcon } from "~/components/icon/icon";
+import { ErrorIcon } from "~/components/icon/icon";
 import { Tooltip } from "@material-ui/core";
+import { disallowSlash } from "~/validators/valid-name";
+import { connect } from "react-redux";
+import { RootState } from "~/store/store";
 
 interface WarningComponentProps {
     text: string;
@@ -14,16 +17,24 @@ interface WarningComponentProps {
 
 export const WarningComponent = ({ text, rules, message }: WarningComponentProps) =>
     rules.find(aRule => text.match(aRule) !== null)
-    ? message
-        ? <Tooltip title={message}><WarningIcon /></Tooltip>
-        : <WarningIcon />
-    : null;
+        ? message
+            ? <Tooltip title={message}><ErrorIcon /></Tooltip>
+            : <ErrorIcon />
+        : null;
 
 interface IllegalNamingWarningProps {
     name: string;
+    validate: RegExp[];
 }
 
-export const IllegalNamingWarning = ({ name }: IllegalNamingWarningProps) =>
-    <WarningComponent
-        text={name} rules={[/\//, /^\.{1,2}$/]}
-        message="Names being '.', '..' or including '/' cause issues with WebDAV, please edit it to something different." />;
\ No newline at end of file
+
+export const IllegalNamingWarning = connect(
+    (state: RootState) => {
+        return {
+            validate: (state.auth.config.clusterConfig.Collections.ForwardSlashNameSubstitution === "" ?
+                [disallowSlash] : [])
+        };
+    })(({ name, validate }: IllegalNamingWarningProps) =>
+        <WarningComponent
+            text={name} rules={validate}
+            message="Names embedding '/' will be renamed or invisible to file system access (arv-mount or WebDAV)" />);