@scm-manager/ui-components 2.43.1 → 2.43.2-20230425-175303
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/config/ConfigurationBinder.tsx +43 -10
- package/src/forms/FileInput.tsx +53 -64
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/ui-components",
|
|
3
|
-
"version": "2.43.
|
|
3
|
+
"version": "2.43.2-20230425-175303",
|
|
4
4
|
"description": "UI Components for SCM-Manager and its plugins",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"update-storyshots": "jest --testPathPattern=\"storyshots.test.ts\" --collectCoverage=false -u"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@scm-manager/ui-syntaxhighlighting": "2.43.
|
|
24
|
-
"@scm-manager/ui-shortcuts": "2.43.
|
|
25
|
-
"@scm-manager/ui-text": "2.43.
|
|
23
|
+
"@scm-manager/ui-syntaxhighlighting": "2.43.2-20230425-175303",
|
|
24
|
+
"@scm-manager/ui-shortcuts": "2.43.2-20230425-175303",
|
|
25
|
+
"@scm-manager/ui-text": "2.43.2-20230425-175303",
|
|
26
26
|
"@scm-manager/babel-preset": "^2.13.1",
|
|
27
27
|
"@scm-manager/eslint-config": "^2.17.0",
|
|
28
28
|
"@scm-manager/jest-preset": "^2.13.0",
|
|
29
29
|
"@scm-manager/prettier-config": "^2.10.1",
|
|
30
30
|
"@scm-manager/tsconfig": "^2.13.0",
|
|
31
|
-
"@scm-manager/ui-tests": "2.43.
|
|
31
|
+
"@scm-manager/ui-tests": "2.43.2-20230425-175303",
|
|
32
32
|
"@storybook/addon-actions": "^6.4.20",
|
|
33
33
|
"@storybook/addon-essentials": "^6.4.20",
|
|
34
34
|
"@storybook/addon-interactions": "^6.4.20",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@headlessui/react": "^1.4.3",
|
|
70
|
-
"@scm-manager/ui-api": "2.43.
|
|
71
|
-
"@scm-manager/ui-extensions": "2.43.
|
|
72
|
-
"@scm-manager/ui-types": "2.43.
|
|
70
|
+
"@scm-manager/ui-api": "2.43.2-20230425-175303",
|
|
71
|
+
"@scm-manager/ui-extensions": "2.43.2-20230425-175303",
|
|
72
|
+
"@scm-manager/ui-types": "2.43.2-20230425-175303",
|
|
73
73
|
"classnames": "^2.2.6",
|
|
74
74
|
"date-fns": "^2.4.1",
|
|
75
75
|
"deepmerge": "^4.2.2",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import React, { ComponentProps } from "react";
|
|
24
|
+
import React, { ComponentProps, ComponentType, FC } from "react";
|
|
25
25
|
import { binder, extensionPoints } from "@scm-manager/ui-extensions";
|
|
26
26
|
import { NavLink } from "../navigation";
|
|
27
27
|
import { Route } from "react-router-dom";
|
|
28
|
-
import { WithTranslation, withTranslation } from "react-i18next";
|
|
29
|
-
import { Link, Links, Repository } from "@scm-manager/ui-types";
|
|
28
|
+
import { useTranslation, WithTranslation, withTranslation } from "react-i18next";
|
|
29
|
+
import { Link, Links, Namespace, Repository } from "@scm-manager/ui-types";
|
|
30
30
|
import { urls } from "@scm-manager/ui-api";
|
|
31
31
|
|
|
32
32
|
type GlobalRouteProps = {
|
|
@@ -34,6 +34,11 @@ type GlobalRouteProps = {
|
|
|
34
34
|
links: Links;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
type NamespaceRouteProps = {
|
|
38
|
+
url: string;
|
|
39
|
+
namespace: Namespace;
|
|
40
|
+
};
|
|
41
|
+
|
|
37
42
|
type RepositoryRouteProps = {
|
|
38
43
|
url: string;
|
|
39
44
|
repository: Repository;
|
|
@@ -41,6 +46,8 @@ type RepositoryRouteProps = {
|
|
|
41
46
|
|
|
42
47
|
type RepositoryNavProps = WithTranslation & { url: string };
|
|
43
48
|
|
|
49
|
+
type NamespaceNavProps = WithTranslation & { url: string };
|
|
50
|
+
|
|
44
51
|
class ConfigurationBinder {
|
|
45
52
|
i18nNamespace = "plugins";
|
|
46
53
|
|
|
@@ -54,11 +61,7 @@ class ConfigurationBinder {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
route(path: string, Component: any) {
|
|
57
|
-
return (
|
|
58
|
-
<Route path={urls.escapeUrlForRoute(path)} exact>
|
|
59
|
-
{Component}
|
|
60
|
-
</Route>
|
|
61
|
-
);
|
|
64
|
+
return <Route path={urls.escapeUrlForRoute(path)}>{Component}</Route>;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
bindGlobal(to: string, labelI18nKey: string, linkName: string, ConfigurationComponent: any) {
|
|
@@ -70,7 +73,7 @@ class ConfigurationBinder {
|
|
|
70
73
|
|
|
71
74
|
// create NavigationLink with translated label
|
|
72
75
|
const ConfigNavLink = withTranslation(this.i18nNamespace)(({ t }) => {
|
|
73
|
-
return this.navLink("/admin/settings" + to, labelI18nKey, t);
|
|
76
|
+
return this.navLink("/admin/settings" + to, labelI18nKey, t, { activeOnlyWhenExact: false });
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
// bind navigation link to extension point
|
|
@@ -151,7 +154,7 @@ class ConfigurationBinder {
|
|
|
151
154
|
|
|
152
155
|
// create NavigationLink with translated label
|
|
153
156
|
const RepoNavLink = withTranslation(this.i18nNamespace)(({ t, url }: RepositoryNavProps) => {
|
|
154
|
-
return this.navLink(url + "/settings" + to, labelI18nKey, t);
|
|
157
|
+
return this.navLink(url + "/settings" + to, labelI18nKey, t, { activeOnlyWhenExact: false });
|
|
155
158
|
});
|
|
156
159
|
|
|
157
160
|
// bind navigation link to extension point
|
|
@@ -171,6 +174,36 @@ class ConfigurationBinder {
|
|
|
171
174
|
// bind config route to extension point
|
|
172
175
|
binder.bind("repository.route", RepoRoute, repoPredicate);
|
|
173
176
|
}
|
|
177
|
+
|
|
178
|
+
bindNamespaceSetting(
|
|
179
|
+
to: string,
|
|
180
|
+
labelI18nKey: string,
|
|
181
|
+
linkName: string,
|
|
182
|
+
ConfigurationComponent: ComponentType<{ link: string; namespace: Namespace }>
|
|
183
|
+
) {
|
|
184
|
+
const namespacePredicate = (props: (extensionPoints.NamespaceSetting | extensionPoints.NamespaceRoute)["props"]) =>
|
|
185
|
+
props.namespace && props.namespace._links && props.namespace._links[linkName];
|
|
186
|
+
|
|
187
|
+
const NamespaceNavLink: FC<extensionPoints.NamespaceRoute["props"]> = ({ url }) => {
|
|
188
|
+
const [t] = useTranslation(this.i18nNamespace);
|
|
189
|
+
return this.navLink(url + "/settings" + to, labelI18nKey, t, { activeOnlyWhenExact: false });
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
binder.bind<extensionPoints.NamespaceSetting>("namespace.setting", NamespaceNavLink, namespacePredicate);
|
|
193
|
+
|
|
194
|
+
const NamespaceRoute: FC<extensionPoints.NamespaceRoute["props"]> = ({ url, namespace, ...additionalProps }) => {
|
|
195
|
+
const link = namespace._links[linkName];
|
|
196
|
+
if (link) {
|
|
197
|
+
return this.route(
|
|
198
|
+
urls.unescapeUrlForRoute(url) + "/settings" + to,
|
|
199
|
+
<ConfigurationComponent namespace={namespace} link={(link as Link).href} {...additionalProps} />
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
binder.bind<extensionPoints.NamespaceRoute>("namespace.route", NamespaceRoute, namespacePredicate);
|
|
206
|
+
}
|
|
174
207
|
}
|
|
175
208
|
|
|
176
209
|
export default new ConfigurationBinder();
|
package/src/forms/FileInput.tsx
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import React, { ChangeEvent,
|
|
24
|
+
import React, { ChangeEvent, FocusEvent, useState } from "react";
|
|
25
25
|
import { useTranslation } from "react-i18next";
|
|
26
26
|
import classNames from "classnames";
|
|
27
27
|
import { createAttributesForTesting } from "../devBuild";
|
|
@@ -39,77 +39,66 @@ type Props = {
|
|
|
39
39
|
testId?: string;
|
|
40
40
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
41
41
|
onBlur?: (event: FocusEvent<HTMLInputElement>) => void;
|
|
42
|
-
ref?: React.Ref<HTMLInputElement>;
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
const FileInput
|
|
46
|
-
name,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
helpText,
|
|
50
|
-
placeholder,
|
|
51
|
-
disabled,
|
|
52
|
-
label,
|
|
53
|
-
className,
|
|
54
|
-
ref,
|
|
55
|
-
onBlur,
|
|
56
|
-
onChange,
|
|
57
|
-
}) => {
|
|
58
|
-
const [t] = useTranslation("commons");
|
|
59
|
-
const [file, setFile] = useState<File | null>(null);
|
|
44
|
+
const FileInput = React.forwardRef<HTMLInputElement, Props>(
|
|
45
|
+
({ name, filenamePlaceholder, testId, helpText, placeholder, disabled, label, className, onBlur, onChange }, ref) => {
|
|
46
|
+
const [t] = useTranslation("commons");
|
|
47
|
+
const [file, setFile] = useState<File | null>(null);
|
|
60
48
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
50
|
+
const uploadedFile = event?.target?.files![0];
|
|
51
|
+
// @ts-ignore the uploaded file doesn't match our types
|
|
52
|
+
setFile(uploadedFile);
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
if (onChange && event.target.files) {
|
|
55
|
+
onChange(event);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
70
58
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
60
|
+
if (onBlur && event.target.files) {
|
|
61
|
+
onBlur(event);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
76
64
|
|
|
77
|
-
|
|
65
|
+
const id = createA11yId("file-input");
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
return (
|
|
68
|
+
<div className={classNames("field", className)}>
|
|
69
|
+
<LabelWithHelpIcon label={label} helpText={helpText} id={id} />
|
|
70
|
+
<div className="file is-info has-name is-fullwidth">
|
|
71
|
+
<label className="file-label">
|
|
72
|
+
<input
|
|
73
|
+
ref={ref}
|
|
74
|
+
name={name}
|
|
75
|
+
className="file-input"
|
|
76
|
+
type="file"
|
|
77
|
+
placeholder={placeholder}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
onChange={handleChange}
|
|
80
|
+
onBlur={handleBlur}
|
|
81
|
+
aria-describedby={id}
|
|
82
|
+
{...createAttributesForTesting(testId)}
|
|
83
|
+
/>
|
|
84
|
+
<span className="file-cta">
|
|
85
|
+
<span className="file-icon">
|
|
86
|
+
<i className="fas fa-arrow-circle-up" />
|
|
87
|
+
</span>
|
|
88
|
+
<span className="file-label has-text-weight-bold">{t("fileInput.label")}</span>
|
|
99
89
|
</span>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
</label>
|
|
90
|
+
{file?.name ? (
|
|
91
|
+
<span className="file-name">{file?.name}</span>
|
|
92
|
+
) : (
|
|
93
|
+
<span className="file-name has-text-weight-light has-text-secondary">
|
|
94
|
+
{filenamePlaceholder || t("fileInput.noFileChosen")}
|
|
95
|
+
</span>
|
|
96
|
+
)}
|
|
97
|
+
</label>
|
|
98
|
+
</div>
|
|
110
99
|
</div>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
);
|
|
114
103
|
|
|
115
104
|
export default FileInput;
|