tycho-components 0.25.0 → 0.25.2
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/dist/common/AppForm/AppForm.js +17 -3
- package/dist/common/AppForm/AppFormField.d.ts +1 -0
- package/dist/common/AppSwitchGroup/AppSwitchGroup.d.ts +12 -0
- package/dist/common/AppSwitchGroup/AppSwitchGroup.js +8 -0
- package/dist/common/AppSwitchGroup/index.d.ts +2 -0
- package/dist/common/AppSwitchGroup/index.js +2 -0
- package/dist/common/AppSwitchGroup/style.scss +18 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +1 -0
- package/dist/configs/types/Corpus.d.ts +1 -0
- package/dist/features/Comments/CommentAdd.d.ts +4 -4
- package/dist/features/Comments/CommentAdd.js +18 -18
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { AsyncSelectField, CheckboxField, DatePickerField, SelectField, SwitchField, TextField, } from 'tycho-storybook';
|
|
2
|
+
import { AsyncSelectField, CheckboxField, DatePickerField, SelectField, SelectMultipleField, SwitchField, TextField, } from 'tycho-storybook';
|
|
3
3
|
import './style.scss';
|
|
4
4
|
const convertList = (values, labelAttr, valueAttr) => {
|
|
5
5
|
if (!values)
|
|
@@ -29,13 +29,27 @@ export default function AppForm({ fields, form, prefix, onChangeFunctions = {},
|
|
|
29
29
|
}
|
|
30
30
|
if (field.type === 'select') {
|
|
31
31
|
const selectOptions = getOptions(field.attr) || field.options || [];
|
|
32
|
-
|
|
32
|
+
const selectProps = {
|
|
33
|
+
key: name,
|
|
34
|
+
attr: name,
|
|
35
|
+
label: field.name,
|
|
36
|
+
createdForm: form,
|
|
37
|
+
options: selectOptions,
|
|
38
|
+
disabled: field.disabled,
|
|
39
|
+
required: field.required,
|
|
40
|
+
onChange: (value) => handleChange?.(value),
|
|
41
|
+
showEndAdornment: false,
|
|
42
|
+
};
|
|
43
|
+
if (field.multiple) {
|
|
44
|
+
return _jsx(SelectMultipleField, { ...selectProps });
|
|
45
|
+
}
|
|
46
|
+
return _jsx(SelectField, { ...selectProps });
|
|
33
47
|
}
|
|
34
48
|
if (field.type === 'check') {
|
|
35
49
|
return (_jsx(CheckboxField, { attr: name, label: field.name, createdForm: form, disabled: field.disabled }, name));
|
|
36
50
|
}
|
|
37
51
|
if (field.type === 'switch') {
|
|
38
|
-
return (_jsx(SwitchField, { attr: name, label: field.name, createdForm: form, disabled: field.disabled }, name));
|
|
52
|
+
return (_jsx(SwitchField, { attr: name, label: field.name, createdForm: form, disabled: field.disabled, onChange: (value) => handleChange?.(value) }, name));
|
|
39
53
|
}
|
|
40
54
|
if (field.type === 'datepicker') {
|
|
41
55
|
const handleBlur = getOnBlurFn(field.attr);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
2
|
+
import { AppFormField } from '../AppForm/AppFormField';
|
|
3
|
+
import './style.scss';
|
|
4
|
+
type Props = {
|
|
5
|
+
fields: AppFormField[];
|
|
6
|
+
form: UseFormReturn<any, any, any>;
|
|
7
|
+
onToggle: (attr: string, value: boolean) => void;
|
|
8
|
+
hasRole?: (role: string) => boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
};
|
|
11
|
+
export default function AppSwitchGroup({ fields, form, onToggle, hasRole, className, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon, SwitchField, Tooltip } from 'tycho-storybook';
|
|
3
|
+
import FormUtils from '../../functions/FormUtils';
|
|
4
|
+
import './style.scss';
|
|
5
|
+
export default function AppSwitchGroup({ fields, form, onToggle, hasRole = () => true, className, }) {
|
|
6
|
+
const visibleFields = FormUtils.filterFieldsByUserRole(fields, hasRole).filter((field) => field.type === 'switch');
|
|
7
|
+
return (_jsx("div", { className: `app-switch-group-container ${className || ''}`, children: visibleFields.map((field) => (_jsxs("div", { className: "app-switch-group-row", children: [_jsx(SwitchField, { attr: field.attr, label: field.name, createdForm: form, disabled: field.disabled, onChange: (value) => onToggle(field.attr, value) }), field.tooltip && field.tooltipText && (_jsx(Tooltip, { title: field.tooltipText, children: _jsx("span", { className: "app-switch-group-tooltip", children: _jsx(Icon, { name: "help", size: "x-small" }) }) }))] }, field.attr))) }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.app-switch-group-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--spacing-200);
|
|
5
|
+
|
|
6
|
+
.app-switch-group-row {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: row;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: var(--spacing-100);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.app-switch-group-tooltip {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
color: var(--icon-secondary);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type { FieldOperations, FormField } from './AppEditable/FormField';
|
|
|
12
12
|
export { default as AppForm } from './AppForm/AppForm';
|
|
13
13
|
export { default as AppFormInfo } from './AppForm/AppFormInfo';
|
|
14
14
|
export type { AppFormField } from './AppForm/AppFormField';
|
|
15
|
+
export { default as AppSwitchGroup } from './AppSwitchGroup';
|
|
15
16
|
export { convertEnum, convertList } from './AppEditable/FormFieldOption';
|
|
16
17
|
export type { FormFieldOption } from './AppEditable/FormFieldOption';
|
|
17
18
|
export { default as AppKeyboard } from './AppKeyboard';
|
package/dist/common/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { default as AppEditable } from './AppEditable';
|
|
|
8
8
|
export { validateFormField } from './AppEditable/FormField';
|
|
9
9
|
export { default as AppForm } from './AppForm/AppForm';
|
|
10
10
|
export { default as AppFormInfo } from './AppForm/AppFormInfo';
|
|
11
|
+
export { default as AppSwitchGroup } from './AppSwitchGroup';
|
|
11
12
|
export { convertEnum, convertList } from './AppEditable/FormFieldOption';
|
|
12
13
|
export { default as AppKeyboard } from './AppKeyboard';
|
|
13
14
|
export { default as AppLoading } from './AppLoading';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { User } from
|
|
2
|
-
import
|
|
3
|
-
import { Comment } from
|
|
1
|
+
import { User } from "../../configs/types/User";
|
|
2
|
+
import "./style.scss";
|
|
3
|
+
import { Comment } from "./types/Comment";
|
|
4
4
|
type Props = {
|
|
5
5
|
uid: string;
|
|
6
|
-
mode:
|
|
6
|
+
mode: "lexicon" | "corpus" | "parser";
|
|
7
7
|
users: User[];
|
|
8
8
|
references: Record<string, string | number | boolean>;
|
|
9
9
|
keywords?: Record<string, string | number | boolean>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { yupResolver } from
|
|
3
|
-
import { useForm } from
|
|
4
|
-
import { useTranslation } from
|
|
5
|
-
import { Button,
|
|
6
|
-
import * as yup from
|
|
7
|
-
import { useMessageUtils } from
|
|
8
|
-
import FormUtils from
|
|
9
|
-
import
|
|
10
|
-
import { EMPTY_COMMENT_REQUEST, } from
|
|
11
|
-
import CommentService from
|
|
2
|
+
import { yupResolver } from "@hookform/resolvers/yup";
|
|
3
|
+
import { useForm } from "react-hook-form";
|
|
4
|
+
import { useTranslation } from "react-i18next";
|
|
5
|
+
import { Button, SelectMultipleField, TextField, } from "tycho-storybook";
|
|
6
|
+
import * as yup from "yup";
|
|
7
|
+
import { useMessageUtils } from "../../configs/useMessageUtils";
|
|
8
|
+
import FormUtils from "../../functions/FormUtils";
|
|
9
|
+
import "./style.scss";
|
|
10
|
+
import { EMPTY_COMMENT_REQUEST, } from "./types/Comment";
|
|
11
|
+
import CommentService from "./CommentService";
|
|
12
12
|
export default function CommentAdd({ uid, mode, users, references, keywords, comment, reply, onClose, onChange, }) {
|
|
13
|
-
const { t } = useTranslation(
|
|
13
|
+
const { t } = useTranslation("comments");
|
|
14
14
|
const { isLoading, dispatchLoading } = useMessageUtils();
|
|
15
15
|
const getFormDefaultValues = () => {
|
|
16
16
|
if (comment)
|
|
@@ -35,7 +35,7 @@ export default function CommentAdd({ uid, mode, users, references, keywords, com
|
|
|
35
35
|
};
|
|
36
36
|
const createdForm = useForm({
|
|
37
37
|
resolver: yupResolver(getFormSchema(t)),
|
|
38
|
-
mode:
|
|
38
|
+
mode: "onChange",
|
|
39
39
|
defaultValues: getFormDefaultValues(),
|
|
40
40
|
});
|
|
41
41
|
const handleAdd = () => {
|
|
@@ -58,18 +58,18 @@ export default function CommentAdd({ uid, mode, users, references, keywords, com
|
|
|
58
58
|
createdForm.reset(EMPTY_COMMENT_REQUEST);
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
|
-
return (_jsxs("div", { className: "form", children: [_jsx(TextField, { label: t(
|
|
61
|
+
return (_jsxs("div", { className: "form", children: [_jsx(TextField, { label: t("input.value"), attr: "value", createdForm: createdForm, showEndAdornment: false, placeholder: t("common:generic.placeholder"), required: true, multiline: true }), _jsx(TextField, { label: t("input.title"), attr: "title", createdForm: createdForm, showEndAdornment: false, placeholder: t("common:generic.placeholder") }), _jsx(SelectMultipleField, { label: reply ? t("input.user.reply") : t("input.user"), attr: "requested", createdForm: createdForm, options: [
|
|
62
62
|
{
|
|
63
|
-
label: t(
|
|
64
|
-
value:
|
|
63
|
+
label: t("common:generic.placeholder.select"),
|
|
64
|
+
value: "",
|
|
65
65
|
},
|
|
66
|
-
...FormUtils.convertList(users,
|
|
67
|
-
], showEndAdornment: false
|
|
66
|
+
...FormUtils.convertList(users, "name", "uid"),
|
|
67
|
+
], showEndAdornment: false }), _jsxs("div", { className: "buttons", children: [_jsx(Button, { onClick: onClose, text: t("button.discard"), color: "danger" }), _jsx(Button, { onClick: comment ? handleUpdate : handleAdd, text: comment ? t("label.button.update") : t("label.button.add"), disabled: !createdForm.formState.isValid })] })] }));
|
|
68
68
|
}
|
|
69
69
|
const getFormSchema = (t) => yup.object().shape({
|
|
70
70
|
id: yup.string().optional(),
|
|
71
71
|
title: yup.string().optional(),
|
|
72
|
-
value: yup.string().required(t(
|
|
72
|
+
value: yup.string().required(t("common:validation.required")),
|
|
73
73
|
requested: yup.array().of(yup.string().defined()).optional(),
|
|
74
74
|
coordinates: yup.array().of(yup.string().defined()).optional(),
|
|
75
75
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tycho-components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.25.
|
|
4
|
+
"version": "0.25.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"react-i18next": "^13.0.2",
|
|
83
83
|
"react-router-dom": "^6.14.2",
|
|
84
84
|
"react-toastify": "^9.1.3",
|
|
85
|
-
"tycho-storybook": "0.9.
|
|
85
|
+
"tycho-storybook": "0.9.3",
|
|
86
86
|
"wavesurfer-react": "^2.2.2",
|
|
87
87
|
"wavesurfer.js": "^6.6.3"
|
|
88
88
|
},
|