@truedat/bg 7.2.11 → 7.3.0
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 +6 -6
- package/src/concepts/components/ConceptCompleteness.js +51 -27
- package/src/concepts/components/ConceptCreate.js +30 -40
- package/src/concepts/components/ConceptEdit.js +17 -24
- package/src/concepts/components/ConceptForm.js +259 -97
- package/src/concepts/components/__tests__/ConceptForm.spec.js +4 -6
- package/src/concepts/components/__tests__/__snapshots__/ConceptEdit.spec.js.snap +105 -98
- package/src/concepts/components/__tests__/__snapshots__/ConceptForm.spec.js.snap +283 -143
- package/src/concepts/components/ConceptFormTabs.js +0 -75
- package/src/concepts/components/ConceptForms.js +0 -200
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import _ from "lodash/fp";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import PropTypes from "prop-types";
|
|
4
|
-
import {
|
|
5
|
-
Button,
|
|
6
|
-
Container,
|
|
7
|
-
Grid,
|
|
8
|
-
Header,
|
|
9
|
-
Icon,
|
|
10
|
-
Segment,
|
|
11
|
-
} from "semantic-ui-react";
|
|
12
|
-
import { useIntl, FormattedMessage } from "react-intl";
|
|
13
|
-
import { HistoryBackButton } from "@truedat/core/components";
|
|
14
|
-
|
|
15
|
-
import ConceptFormTabs from "./ConceptFormTabs";
|
|
16
|
-
import ConceptForm from "./ConceptForm";
|
|
17
|
-
|
|
18
|
-
const isNonEmptyString = _.flow(_.trim, _.negate(_.isEmpty));
|
|
19
|
-
|
|
20
|
-
const ConceptForms = ({
|
|
21
|
-
actionKey,
|
|
22
|
-
domainId,
|
|
23
|
-
template,
|
|
24
|
-
i18nConcept,
|
|
25
|
-
loading,
|
|
26
|
-
langs,
|
|
27
|
-
noTranslatableFields,
|
|
28
|
-
translatableFields,
|
|
29
|
-
setI18nConcept,
|
|
30
|
-
setDomainId,
|
|
31
|
-
setTemplate,
|
|
32
|
-
onSubmit,
|
|
33
|
-
}) => {
|
|
34
|
-
const { formatMessage } = useIntl();
|
|
35
|
-
|
|
36
|
-
const handleI18nNameChange = (lang, name) => {
|
|
37
|
-
setI18nConcept(_.set(`${lang}.name`, name)(i18nConcept));
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const handleDomainChange = (_e, { value }) => setDomainId(_.toInteger(value));
|
|
41
|
-
|
|
42
|
-
const handleTemplateChange = (value) => setTemplate(value);
|
|
43
|
-
|
|
44
|
-
const handleI18nConceptContentChange = (lang, { content }) => {
|
|
45
|
-
const filteredContent = i18nConcept[lang].is_default
|
|
46
|
-
? content
|
|
47
|
-
: _.flow(_.pick(translatableFields))(content);
|
|
48
|
-
const updateI18nLangContent = _.flow(_.get(lang), (i18nLang) => {
|
|
49
|
-
return {
|
|
50
|
-
[lang]: {
|
|
51
|
-
...i18nLang,
|
|
52
|
-
content: { ...filteredContent },
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
})(i18nConcept);
|
|
56
|
-
|
|
57
|
-
const updateI18nConcept = {
|
|
58
|
-
...i18nConcept,
|
|
59
|
-
...updateI18nLangContent,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
setI18nConcept(updateI18nConcept);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const validDomain = () => _.isFinite(domainId);
|
|
66
|
-
|
|
67
|
-
const validNames = () =>
|
|
68
|
-
_.flow(
|
|
69
|
-
_.filter("is_required"),
|
|
70
|
-
_.map("name"),
|
|
71
|
-
_.every(isNonEmptyString)
|
|
72
|
-
)(i18nConcept);
|
|
73
|
-
|
|
74
|
-
const validTemplate = () =>
|
|
75
|
-
_.isObject(template) && isNonEmptyString(template?.name);
|
|
76
|
-
|
|
77
|
-
const isInvalid = !validDomain() || !validNames() || !validTemplate();
|
|
78
|
-
|
|
79
|
-
const renderSingle = () => {
|
|
80
|
-
const singleLang = _.get("lang")(_.first(langs.default));
|
|
81
|
-
return (
|
|
82
|
-
<Container as={Segment} text>
|
|
83
|
-
<Header as="h2">
|
|
84
|
-
<Icon name="book" />
|
|
85
|
-
<Header.Content>
|
|
86
|
-
{actionKey == "create" ? (
|
|
87
|
-
<FormattedMessage id="concepts.actions.create" />
|
|
88
|
-
) : (
|
|
89
|
-
<FormattedMessage id="concepts.header.edit" />
|
|
90
|
-
)}
|
|
91
|
-
</Header.Content>
|
|
92
|
-
</Header>
|
|
93
|
-
<ConceptForm
|
|
94
|
-
actionKey={actionKey}
|
|
95
|
-
domainId={domainId}
|
|
96
|
-
template={template}
|
|
97
|
-
concept={i18nConcept[singleLang]}
|
|
98
|
-
defaultContent={i18nConcept[singleLang].content}
|
|
99
|
-
noTranslatableFields={[]}
|
|
100
|
-
onChangeDomainId={handleDomainChange}
|
|
101
|
-
onChangeName={handleI18nNameChange}
|
|
102
|
-
onChangeTemplate={handleTemplateChange}
|
|
103
|
-
onChangeConceptContent={handleI18nConceptContentChange}
|
|
104
|
-
loading={loading}
|
|
105
|
-
/>
|
|
106
|
-
<div className="concept-forms-actions actions">
|
|
107
|
-
<HistoryBackButton
|
|
108
|
-
content={formatMessage({ id: "actions.cancel" })}
|
|
109
|
-
/>
|
|
110
|
-
<Button
|
|
111
|
-
primary
|
|
112
|
-
disabled={isInvalid}
|
|
113
|
-
onClick={onSubmit}
|
|
114
|
-
content={formatMessage({ id: `actions.${actionKey}` })}
|
|
115
|
-
/>
|
|
116
|
-
</div>
|
|
117
|
-
</Container>
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const renderMultiple = () => {
|
|
122
|
-
return (
|
|
123
|
-
<>
|
|
124
|
-
<Header as="h2">
|
|
125
|
-
<Icon name="book" />
|
|
126
|
-
<Header.Content>
|
|
127
|
-
{actionKey == "create" ? (
|
|
128
|
-
<FormattedMessage id="concepts.actions.create" />
|
|
129
|
-
) : (
|
|
130
|
-
<FormattedMessage id="concepts.header.edit" />
|
|
131
|
-
)}
|
|
132
|
-
</Header.Content>
|
|
133
|
-
</Header>
|
|
134
|
-
|
|
135
|
-
<Grid>
|
|
136
|
-
<Grid.Row columns={2}>
|
|
137
|
-
<ConceptFormTabs
|
|
138
|
-
actionKey={actionKey}
|
|
139
|
-
domainId={domainId}
|
|
140
|
-
template={template}
|
|
141
|
-
langs={langs.default}
|
|
142
|
-
loading={loading}
|
|
143
|
-
i18nConcept={i18nConcept}
|
|
144
|
-
onChangeDomainId={handleDomainChange}
|
|
145
|
-
onChangeName={handleI18nNameChange}
|
|
146
|
-
onChangeTemplate={handleTemplateChange}
|
|
147
|
-
onChangeConceptContent={handleI18nConceptContentChange}
|
|
148
|
-
/>
|
|
149
|
-
<ConceptFormTabs
|
|
150
|
-
actionKey={actionKey}
|
|
151
|
-
domainId={domainId}
|
|
152
|
-
template={template}
|
|
153
|
-
langs={[...langs.required, ...langs.enabled]}
|
|
154
|
-
conceptActionLoading={loading}
|
|
155
|
-
i18nConcept={i18nConcept}
|
|
156
|
-
noTranslatableFields={noTranslatableFields}
|
|
157
|
-
onChangeName={handleI18nNameChange}
|
|
158
|
-
onChangeConceptContent={handleI18nConceptContentChange}
|
|
159
|
-
/>
|
|
160
|
-
</Grid.Row>
|
|
161
|
-
</Grid>
|
|
162
|
-
<div className="concept-forms-actions actions">
|
|
163
|
-
<HistoryBackButton
|
|
164
|
-
content={formatMessage({ id: "actions.cancel" })}
|
|
165
|
-
/>
|
|
166
|
-
<Button
|
|
167
|
-
primary
|
|
168
|
-
disabled={isInvalid}
|
|
169
|
-
onClick={onSubmit}
|
|
170
|
-
content={formatMessage({ id: `actions.${actionKey}` })}
|
|
171
|
-
/>
|
|
172
|
-
</div>
|
|
173
|
-
</>
|
|
174
|
-
);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
return !loading
|
|
178
|
-
? _.isEmpty(langs.required) && _.isEmpty(langs.enabled)
|
|
179
|
-
? renderSingle()
|
|
180
|
-
: renderMultiple()
|
|
181
|
-
: null;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
ConceptForms.propTypes = {
|
|
185
|
-
loading: PropTypes.bool,
|
|
186
|
-
actionKey: PropTypes.string,
|
|
187
|
-
domainId: PropTypes.number,
|
|
188
|
-
template: PropTypes.object,
|
|
189
|
-
i18nConcept: PropTypes.object,
|
|
190
|
-
loading: PropTypes.bool,
|
|
191
|
-
langs: PropTypes.object,
|
|
192
|
-
noTranslatableFields: PropTypes.array,
|
|
193
|
-
translatableFields: PropTypes.array,
|
|
194
|
-
setI18nConcept: PropTypes.func,
|
|
195
|
-
setDomainId: PropTypes.func,
|
|
196
|
-
setTemplate: PropTypes.func,
|
|
197
|
-
onSubmit: PropTypes.func,
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
export default ConceptForms;
|