@truedat/qx 5.14.1 → 5.15.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 +3 -3
- package/src/api.js +3 -2
- package/src/components/QxRoutes.js +4 -4
- package/src/components/common/ResourceSelector.js +80 -0
- package/src/components/common/TestFormWrapper.js +9 -6
- package/src/components/common/TypeSelector.js +3 -1
- package/src/components/common/__tests__/DescriptionInput.spec.js +48 -0
- package/src/components/common/__tests__/ResourceSelector.spec.js +124 -0
- package/src/components/common/__tests__/TypeSelector.spec.js +29 -0
- package/src/components/common/__tests__/__snapshots__/DescriptionInput.spec.js.snap +19 -0
- package/src/components/common/__tests__/__snapshots__/ResourceSelector.spec.js.snap +484 -0
- package/src/components/common/__tests__/__snapshots__/TypeSelector.spec.js.snap +230 -0
- package/src/components/common/expressions/Clauses.js +100 -0
- package/src/components/common/expressions/Condition.js +178 -0
- package/src/components/common/expressions/Expression.js +54 -0
- package/src/components/common/expressions/FieldSelector.js +66 -0
- package/src/components/{functions → common}/expressions/FunctionArgs.js +1 -0
- package/src/components/{functions → common}/expressions/FunctionSelector.js +24 -4
- package/src/components/{functions → common}/expressions/ParamSelector.js +3 -3
- package/src/components/{functions → common}/expressions/ShapeSelector.js +22 -6
- package/src/components/common/expressions/__tests__/Clauses.spec.js +53 -0
- package/src/components/common/expressions/__tests__/Condition.spec.js +33 -0
- package/src/components/{functions → common}/expressions/__tests__/ConstantSelector.spec.js +6 -1
- package/src/components/{functions → common}/expressions/__tests__/Expression.spec.js +7 -5
- package/src/components/common/expressions/__tests__/FieldSelector.spec.js +24 -0
- package/src/components/{functions → common}/expressions/__tests__/FunctionArgs.spec.js +20 -6
- package/src/components/{functions → common}/expressions/__tests__/FunctionSelector.spec.js +1 -1
- package/src/components/{functions → common}/expressions/__tests__/ParamSelector.spec.js +22 -10
- package/src/components/{functions → common}/expressions/__tests__/ShapeSelector.spec.js +3 -3
- package/src/components/common/expressions/__tests__/__snapshots__/Clauses.spec.js.snap +64 -0
- package/src/components/common/expressions/__tests__/__snapshots__/Condition.spec.js.snap +316 -0
- package/src/components/{functions → common}/expressions/__tests__/__snapshots__/ConstantSelector.spec.js.snap +1 -1
- package/src/components/common/expressions/__tests__/__snapshots__/Expression.spec.js.snap +939 -0
- package/src/components/common/expressions/__tests__/__snapshots__/FieldSelector.spec.js.snap +5 -0
- package/src/components/common/expressions/__tests__/__snapshots__/FunctionArgs.spec.js.snap +344 -0
- package/src/components/{functions → common}/expressions/__tests__/__snapshots__/ParamSelector.spec.js.snap +4 -4
- package/src/components/{functions → common}/expressions/__tests__/__snapshots__/ShapeSelector.spec.js.snap +17 -24
- package/src/components/common/expressions/constantInputs/AnySelector.js +44 -0
- package/src/components/{functions → common}/expressions/constantInputs/__tests__/AnySelector.spec.js +21 -14
- package/src/components/{functions → common}/expressions/constantInputs/__tests__/DefaultSelector.spec.js +5 -2
- package/src/components/{functions → common}/expressions/constantInputs/__tests__/__snapshots__/AnySelector.spec.js.snap +2 -2
- package/src/components/common/expressions/index.js +4 -0
- package/src/components/common/resourceSelectors/DataStructureSelector.js +63 -0
- package/src/components/common/resourceSelectors/DataViewSelector.js +65 -0
- package/src/components/common/resourceSelectors/ReferenceDatasetSelector.js +61 -0
- package/src/components/common/resourceSelectors/__tests__/DataStructureSelector.spec.js +31 -0
- package/src/components/common/resourceSelectors/__tests__/DataViewSelector.spec.js +133 -0
- package/src/components/common/resourceSelectors/__tests__/ReferenceDatasetSelector.spec.js +97 -0
- package/src/components/common/resourceSelectors/__tests__/__snapshots__/DataStructureSelector.spec.js.snap +105 -0
- package/src/components/common/resourceSelectors/__tests__/__snapshots__/DataViewSelector.spec.js.snap +50 -0
- package/src/components/common/resourceSelectors/__tests__/__snapshots__/ReferenceDatasetSelector.spec.js.snap +50 -0
- package/src/components/common/resourceSelectors/index.js +5 -0
- package/src/components/dataViews/DataViewEditor.js +170 -0
- package/src/components/dataViews/DataViewSelect.js +47 -0
- package/src/components/dataViews/DataViews.js +169 -0
- package/src/components/dataViews/Queryable.js +138 -0
- package/src/components/dataViews/Queryables.js +53 -0
- package/src/components/dataViews/__tests__/DataViewEditor.spec.js +293 -0
- package/src/components/dataViews/__tests__/DataViewSelect.spec.js +28 -0
- package/src/components/dataViews/__tests__/DataViews.spec.js +57 -0
- package/src/components/dataViews/__tests__/Queryable.spec.js +201 -0
- package/src/components/dataViews/__tests__/Queryables.spec.js +183 -0
- package/src/components/dataViews/__tests__/__snapshots__/DataViewEditor.spec.js.snap +1000 -0
- package/src/components/dataViews/__tests__/__snapshots__/DataViewSelect.spec.js.snap +55 -0
- package/src/components/dataViews/__tests__/__snapshots__/DataViews.spec.js.snap +77 -0
- package/src/components/dataViews/__tests__/__snapshots__/Queryable.spec.js.snap +874 -0
- package/src/components/dataViews/__tests__/__snapshots__/Queryables.spec.js.snap +911 -0
- package/src/components/dataViews/__tests__/queryableFunctions.spec.js +193 -0
- package/src/components/dataViews/queryableFunctions.js +80 -0
- package/src/components/dataViews/queryableProperties/From.js +15 -0
- package/src/components/dataViews/queryableProperties/GroupBy.js +124 -0
- package/src/components/dataViews/queryableProperties/Join.js +62 -0
- package/src/components/dataViews/queryableProperties/JoinTypeIcon.js +49 -0
- package/src/components/dataViews/queryableProperties/Select.js +76 -0
- package/src/components/dataViews/queryableProperties/SelectField.js +116 -0
- package/src/components/dataViews/queryableProperties/Where.js +15 -0
- package/src/components/dataViews/queryableProperties/__tests__/From.spec.js +30 -0
- package/src/components/dataViews/queryableProperties/__tests__/GroupBy.spec.js +75 -0
- package/src/components/dataViews/queryableProperties/__tests__/Join.spec.js +38 -0
- package/src/components/dataViews/queryableProperties/__tests__/JoinTypeIcon.spec.js +36 -0
- package/src/components/dataViews/queryableProperties/__tests__/Select.spec.js +144 -0
- package/src/components/dataViews/queryableProperties/__tests__/SelectField.spec.js +107 -0
- package/src/components/dataViews/queryableProperties/__tests__/Where.spec.js +27 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/From.spec.js.snap +75 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/GroupBy.spec.js.snap +276 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/Join.spec.js.snap +252 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/JoinTypeIcon.spec.js.snap +77 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/Select.spec.js.snap +411 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/SelectField.spec.js.snap +343 -0
- package/src/components/dataViews/queryableProperties/__tests__/__snapshots__/Where.spec.js.snap +22 -0
- package/src/components/dataViews/queryableProperties/index.js +7 -0
- package/src/components/functions/FunctionEditor.js +30 -29
- package/src/components/functions/Functions.js +3 -11
- package/src/components/functions/__tests__/FunctionEditor.spec.js +6 -0
- package/src/components/functions/__tests__/FunctionParams.spec.js +6 -0
- package/src/components/functions/__tests__/__snapshots__/FunctionEditor.spec.js.snap +490 -466
- package/src/components/functions/__tests__/__snapshots__/FunctionParams.spec.js.snap +1 -1
- package/src/hooks/__tests__/{useDataSets.spec.js → useDataViews.spec.js} +5 -5
- package/src/hooks/useDataViews.js +33 -0
- package/src/styles/Expression.less +150 -0
- package/src/types.js +11 -3
- package/src/components/DataSets.js +0 -64
- package/src/components/__tests__/DataSets.spec.js +0 -46
- package/src/components/__tests__/__snapshots__/DataSets.spec.js.snap +0 -82
- package/src/components/functions/expressions/Expression.js +0 -40
- package/src/components/functions/expressions/FieldSelector.js +0 -56
- package/src/components/functions/expressions/__tests__/__snapshots__/Expression.spec.js.snap +0 -904
- package/src/components/functions/expressions/__tests__/__snapshots__/FunctionArgs.spec.js.snap +0 -392
- package/src/components/functions/expressions/constantInputs/AnySelector.js +0 -29
- package/src/hooks/useDataSets.js +0 -8
- /package/src/components/{functions → common}/expressions/ConstantSelector.js +0 -0
- /package/src/components/{functions → common}/expressions/__tests__/__snapshots__/FunctionSelector.spec.js.snap +0 -0
- /package/src/components/{functions → common/expressions}/__tests__/useWatchParams.spec.js +0 -0
- /package/src/components/{functions → common}/expressions/constantInputs/BooleanSelector.js +0 -0
- /package/src/components/{functions → common}/expressions/constantInputs/DefaultSelector.js +0 -0
- /package/src/components/{functions → common}/expressions/constantInputs/__tests__/BooleanSelector.spec.js +0 -0
- /package/src/components/{functions → common}/expressions/constantInputs/__tests__/__snapshots__/BooleanSelector.spec.js.snap +0 -0
- /package/src/components/{functions → common}/expressions/constantInputs/__tests__/__snapshots__/DefaultSelector.spec.js.snap +0 -0
- /package/src/components/{functions → common}/expressions/constantInputs/index.js +0 -0
- /package/src/components/{functions → common/expressions}/useWatchParams.js +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import React, { Fragment, useEffect } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Divider,
|
|
7
|
+
Grid,
|
|
8
|
+
GridColumn,
|
|
9
|
+
Header,
|
|
10
|
+
Form,
|
|
11
|
+
} from "semantic-ui-react";
|
|
12
|
+
import { FormProvider, useForm, Controller } from "react-hook-form";
|
|
13
|
+
import { ConfirmModal } from "@truedat/core/components";
|
|
14
|
+
import { DescriptionInput } from "@truedat/qx/components/common";
|
|
15
|
+
import QxContext from "@truedat/qx/components/QxContext";
|
|
16
|
+
import DataViewSelect from "./DataViewSelect";
|
|
17
|
+
import Queryables from "./Queryables";
|
|
18
|
+
|
|
19
|
+
export default function DataViewEditor({
|
|
20
|
+
selectedDataView,
|
|
21
|
+
context,
|
|
22
|
+
onSubmit,
|
|
23
|
+
onCancel,
|
|
24
|
+
onDelete,
|
|
25
|
+
isSubmitting,
|
|
26
|
+
setDirty,
|
|
27
|
+
}) {
|
|
28
|
+
const { formatMessage } = useIntl();
|
|
29
|
+
const form = useForm({
|
|
30
|
+
mode: "onTouched",
|
|
31
|
+
defaultValues: selectedDataView,
|
|
32
|
+
});
|
|
33
|
+
const { control, handleSubmit, watch, formState } = form;
|
|
34
|
+
const { isDirty, isValid } = formState;
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
setDirty(isDirty);
|
|
38
|
+
}, [setDirty, isDirty]);
|
|
39
|
+
|
|
40
|
+
if (!selectedDataView) return null;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Fragment>
|
|
44
|
+
<FormProvider {...form}>
|
|
45
|
+
<Form>
|
|
46
|
+
<Header as="h3" dividing>
|
|
47
|
+
{watch("name") || formatMessage({ id: "dataViews.action.new" })}
|
|
48
|
+
</Header>
|
|
49
|
+
<Grid>
|
|
50
|
+
<GridColumn>
|
|
51
|
+
<Grid.Row>
|
|
52
|
+
<Controller
|
|
53
|
+
control={control}
|
|
54
|
+
name="name"
|
|
55
|
+
rules={{
|
|
56
|
+
required: formatMessage(
|
|
57
|
+
{ id: "form.validation.required" },
|
|
58
|
+
{ prop: formatMessage({ id: "dataViews.form.name" }) }
|
|
59
|
+
),
|
|
60
|
+
}}
|
|
61
|
+
render={({
|
|
62
|
+
field: { onBlur, onChange, value },
|
|
63
|
+
fieldState: { error },
|
|
64
|
+
}) => (
|
|
65
|
+
<Form.Field required>
|
|
66
|
+
<label>{formatMessage({ id: "group.props.name" })}</label>
|
|
67
|
+
<Form.Input
|
|
68
|
+
autoComplete="off"
|
|
69
|
+
placeholder={formatMessage({
|
|
70
|
+
id: "dataViews.form.name",
|
|
71
|
+
})}
|
|
72
|
+
error={error?.message}
|
|
73
|
+
onBlur={onBlur}
|
|
74
|
+
onChange={(_e, { value }) => onChange(value)}
|
|
75
|
+
value={value}
|
|
76
|
+
/>
|
|
77
|
+
</Form.Field>
|
|
78
|
+
)}
|
|
79
|
+
/>
|
|
80
|
+
</Grid.Row>
|
|
81
|
+
<Grid.Row>
|
|
82
|
+
<Controller
|
|
83
|
+
name="description"
|
|
84
|
+
control={control}
|
|
85
|
+
render={({ field: { onBlur, onChange, value } }) => (
|
|
86
|
+
<DescriptionInput
|
|
87
|
+
onBlur={onBlur}
|
|
88
|
+
value={value}
|
|
89
|
+
onChange={(_e, { value }) => onChange(value)}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
/>
|
|
93
|
+
</Grid.Row>
|
|
94
|
+
</GridColumn>
|
|
95
|
+
</Grid>
|
|
96
|
+
<QxContext.Provider value={context}>
|
|
97
|
+
<Queryables />
|
|
98
|
+
<DataViewSelect />
|
|
99
|
+
</QxContext.Provider>
|
|
100
|
+
|
|
101
|
+
<Divider hidden />
|
|
102
|
+
<div className="actions">
|
|
103
|
+
<Button
|
|
104
|
+
onClick={handleSubmit((data) => onSubmit(data))}
|
|
105
|
+
primary
|
|
106
|
+
loading={isSubmitting}
|
|
107
|
+
disabled={!isValid || !isDirty}
|
|
108
|
+
content={formatMessage({ id: "actions.save" })}
|
|
109
|
+
/>
|
|
110
|
+
{isDirty ? (
|
|
111
|
+
<ConfirmModal
|
|
112
|
+
trigger={
|
|
113
|
+
<Button
|
|
114
|
+
content={formatMessage({ id: "actions.cancel" })}
|
|
115
|
+
disabled={isSubmitting}
|
|
116
|
+
/>
|
|
117
|
+
}
|
|
118
|
+
header={formatMessage({
|
|
119
|
+
id: "actions.discard.confirmation.header",
|
|
120
|
+
})}
|
|
121
|
+
content={formatMessage({
|
|
122
|
+
id: "actions.discard.confirmation.content",
|
|
123
|
+
})}
|
|
124
|
+
onConfirm={onCancel}
|
|
125
|
+
onOpen={(e) => e.stopPropagation()}
|
|
126
|
+
onClose={(e) => e.stopPropagation()}
|
|
127
|
+
/>
|
|
128
|
+
) : (
|
|
129
|
+
<Button
|
|
130
|
+
content={formatMessage({ id: "actions.cancel" })}
|
|
131
|
+
disabled={isSubmitting}
|
|
132
|
+
onClick={onCancel}
|
|
133
|
+
/>
|
|
134
|
+
)}
|
|
135
|
+
{onDelete ? (
|
|
136
|
+
<ConfirmModal
|
|
137
|
+
trigger={
|
|
138
|
+
<Button
|
|
139
|
+
color="red"
|
|
140
|
+
content={formatMessage({ id: "actions.delete" })}
|
|
141
|
+
disabled={isSubmitting}
|
|
142
|
+
/>
|
|
143
|
+
}
|
|
144
|
+
header={formatMessage({
|
|
145
|
+
id: "dataViews.action.delete.header",
|
|
146
|
+
})}
|
|
147
|
+
content={formatMessage({
|
|
148
|
+
id: "dataViews.action.delete.content",
|
|
149
|
+
})}
|
|
150
|
+
onConfirm={onDelete}
|
|
151
|
+
onOpen={(e) => e.stopPropagation()}
|
|
152
|
+
onClose={(e) => e.stopPropagation()}
|
|
153
|
+
/>
|
|
154
|
+
) : null}
|
|
155
|
+
</div>
|
|
156
|
+
</Form>
|
|
157
|
+
</FormProvider>
|
|
158
|
+
</Fragment>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
DataViewEditor.propTypes = {
|
|
163
|
+
selectedDataView: PropTypes.object,
|
|
164
|
+
dataViews: PropTypes.array,
|
|
165
|
+
onSubmit: PropTypes.func,
|
|
166
|
+
onCancel: PropTypes.func,
|
|
167
|
+
onDelete: PropTypes.func,
|
|
168
|
+
isSubmitting: PropTypes.bool,
|
|
169
|
+
setDirty: PropTypes.func,
|
|
170
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React, { useContext } from "react";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
import { useFormContext } from "react-hook-form";
|
|
5
|
+
import { Grid, Label, Segment } from "semantic-ui-react";
|
|
6
|
+
import QxContext from "@truedat/qx/components/QxContext";
|
|
7
|
+
import { Select } from "./queryableProperties";
|
|
8
|
+
import { reduceQueryableFields } from "./queryableFunctions";
|
|
9
|
+
|
|
10
|
+
export default function DataViewSelect() {
|
|
11
|
+
const { formatMessage } = useIntl();
|
|
12
|
+
const { watch } = useFormContext();
|
|
13
|
+
const context = useContext(QxContext);
|
|
14
|
+
|
|
15
|
+
const fields = _.flow(
|
|
16
|
+
watch,
|
|
17
|
+
reduceQueryableFields(formatMessage)
|
|
18
|
+
)("queryables");
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div>
|
|
22
|
+
<Grid>
|
|
23
|
+
<Grid.Column>
|
|
24
|
+
<Segment>
|
|
25
|
+
<div className="queryable-label">
|
|
26
|
+
<Label ribbon>
|
|
27
|
+
{formatMessage({ id: `dataViews.form.select` })}
|
|
28
|
+
</Label>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<Grid.Row className="vertical-space">
|
|
32
|
+
<QxContext.Provider
|
|
33
|
+
value={{
|
|
34
|
+
...context,
|
|
35
|
+
field: `select.properties`,
|
|
36
|
+
fields,
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<Select />
|
|
40
|
+
</QxContext.Provider>
|
|
41
|
+
</Grid.Row>
|
|
42
|
+
</Segment>
|
|
43
|
+
</Grid.Column>
|
|
44
|
+
</Grid>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import { useIntl, FormattedMessage } from "react-intl";
|
|
4
|
+
import { useQuery } from "@apollo/client";
|
|
5
|
+
import {
|
|
6
|
+
Button,
|
|
7
|
+
Grid,
|
|
8
|
+
GridColumn,
|
|
9
|
+
Header,
|
|
10
|
+
Icon,
|
|
11
|
+
List,
|
|
12
|
+
Segment,
|
|
13
|
+
} from "semantic-ui-react";
|
|
14
|
+
import { REFERENCE_DATASETS_HEADERS_QUERY } from "@truedat/dd/api/queries";
|
|
15
|
+
import { lowerDeburrTrim } from "@truedat/core/services/sort";
|
|
16
|
+
import {
|
|
17
|
+
useDataViews,
|
|
18
|
+
useDataViewCreate,
|
|
19
|
+
useDataViewDelete,
|
|
20
|
+
useDataViewUpdate,
|
|
21
|
+
} from "@truedat/qx/hooks/useDataViews";
|
|
22
|
+
import { useFunctions } from "@truedat/qx/hooks/useFunctions";
|
|
23
|
+
import DataViewEditor from "./DataViewEditor";
|
|
24
|
+
|
|
25
|
+
const NEW_DATA_VIEW = {
|
|
26
|
+
name: "",
|
|
27
|
+
description: "",
|
|
28
|
+
queryables: [
|
|
29
|
+
{
|
|
30
|
+
id: 0,
|
|
31
|
+
alias: "",
|
|
32
|
+
type: "from",
|
|
33
|
+
properties: {
|
|
34
|
+
resource: null,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
select: {
|
|
39
|
+
type: "select",
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default function DataViews() {
|
|
44
|
+
const { formatMessage } = useIntl();
|
|
45
|
+
const { data, loading: dataViewsLoading, mutate } = useDataViews();
|
|
46
|
+
const { data: functionsData, loading: functionsLoading } = useFunctions();
|
|
47
|
+
const { data: referenceDatasetsData, loading: referenceDatasetsLoading } =
|
|
48
|
+
useQuery(REFERENCE_DATASETS_HEADERS_QUERY);
|
|
49
|
+
|
|
50
|
+
const loading =
|
|
51
|
+
dataViewsLoading || functionsLoading || referenceDatasetsLoading;
|
|
52
|
+
const [selectedDataView, setSelectedDataView] = useState();
|
|
53
|
+
const [isDirty, setDirty] = useState(false);
|
|
54
|
+
|
|
55
|
+
const dataViews = _.orderBy(["id"], ["asc"])(data?.data);
|
|
56
|
+
const functions = functionsData?.data;
|
|
57
|
+
const referenceDatasets = _.flow(
|
|
58
|
+
_.getOr([], "referenceDatasets"),
|
|
59
|
+
_.sortBy([({ name }) => lowerDeburrTrim(name), "name"]),
|
|
60
|
+
_.map((row) => ({ ...row, id: Number(row?.id) }))
|
|
61
|
+
)(referenceDatasetsData);
|
|
62
|
+
|
|
63
|
+
const context = {
|
|
64
|
+
dataViews,
|
|
65
|
+
referenceDatasets,
|
|
66
|
+
functions,
|
|
67
|
+
currentDataViewId: selectedDataView?.id,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const changeSelectedDataView = (selection) => {
|
|
71
|
+
setSelectedDataView(null);
|
|
72
|
+
setSelectedDataView(selection);
|
|
73
|
+
};
|
|
74
|
+
const setStateNewDataView = () => changeSelectedDataView(NEW_DATA_VIEW);
|
|
75
|
+
const clearForm = () => {
|
|
76
|
+
setSelectedDataView(null);
|
|
77
|
+
setDirty(false);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const { trigger: createDataView, isMutating: isCreating } =
|
|
81
|
+
useDataViewCreate();
|
|
82
|
+
|
|
83
|
+
const { trigger: updateDataView, isMutating: isUpdating } =
|
|
84
|
+
useDataViewUpdate(selectedDataView);
|
|
85
|
+
|
|
86
|
+
const { trigger: deleteDataView, isMutating: isDeleting } =
|
|
87
|
+
useDataViewDelete(selectedDataView);
|
|
88
|
+
|
|
89
|
+
const isSubmitting = isCreating || isUpdating || isDeleting;
|
|
90
|
+
const onDataViewCreate = (data_view) => {
|
|
91
|
+
const mutateDataView = selectedDataView?.id
|
|
92
|
+
? updateDataView
|
|
93
|
+
: createDataView;
|
|
94
|
+
mutateDataView({ data_view }).then(() => {
|
|
95
|
+
clearForm();
|
|
96
|
+
mutate();
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const onDataViewDelete = (data_view) => {
|
|
100
|
+
deleteDataView({ data_view }).then(() => {
|
|
101
|
+
clearForm();
|
|
102
|
+
mutate();
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
return (
|
|
106
|
+
<Segment loading={loading}>
|
|
107
|
+
<Header as="h2">
|
|
108
|
+
<Icon circular name="archive" />
|
|
109
|
+
<Header.Content>
|
|
110
|
+
<FormattedMessage id="dataViews.header" />
|
|
111
|
+
<Header.Subheader>
|
|
112
|
+
<FormattedMessage id="dataViews.subheader" />
|
|
113
|
+
</Header.Subheader>
|
|
114
|
+
</Header.Content>
|
|
115
|
+
</Header>
|
|
116
|
+
|
|
117
|
+
<Grid>
|
|
118
|
+
<GridColumn width={4}>
|
|
119
|
+
<Button fluid onClick={setStateNewDataView} disabled={isDirty}>
|
|
120
|
+
{formatMessage({ id: "dataViews.action.new" })}
|
|
121
|
+
</Button>
|
|
122
|
+
<List divided selection={!isDirty}>
|
|
123
|
+
{!_.isEmpty(dataViews) ? (
|
|
124
|
+
dataViews.map((dataView, key) => (
|
|
125
|
+
<List.Item
|
|
126
|
+
key={key}
|
|
127
|
+
onClick={() => !isDirty && changeSelectedDataView(dataView)}
|
|
128
|
+
>
|
|
129
|
+
<List.Content>
|
|
130
|
+
<List.Header>{dataView.name || "DataView"}</List.Header>
|
|
131
|
+
</List.Content>
|
|
132
|
+
</List.Item>
|
|
133
|
+
))
|
|
134
|
+
) : (
|
|
135
|
+
<List.Item>
|
|
136
|
+
<List.Content>
|
|
137
|
+
<List.Header>
|
|
138
|
+
{formatMessage({ id: "dataViews.empty_list" })}
|
|
139
|
+
</List.Header>
|
|
140
|
+
</List.Content>
|
|
141
|
+
</List.Item>
|
|
142
|
+
)}
|
|
143
|
+
</List>
|
|
144
|
+
</GridColumn>
|
|
145
|
+
<GridColumn width={11}>
|
|
146
|
+
{selectedDataView ? (
|
|
147
|
+
<DataViewEditor
|
|
148
|
+
key={selectedDataView?.id || "new"}
|
|
149
|
+
selectedDataView={selectedDataView}
|
|
150
|
+
context={context}
|
|
151
|
+
onCancel={clearForm}
|
|
152
|
+
onSubmit={onDataViewCreate}
|
|
153
|
+
onDelete={selectedDataView?.id ? onDataViewDelete : null}
|
|
154
|
+
isSubmitting={isSubmitting}
|
|
155
|
+
setDirty={setDirty}
|
|
156
|
+
/>
|
|
157
|
+
) : (
|
|
158
|
+
<Header as="h2" icon textAlign="center">
|
|
159
|
+
<Icon name="hand pointer outline" />
|
|
160
|
+
<Header.Subheader>
|
|
161
|
+
{formatMessage({ id: "dataViews.no_selection" })}
|
|
162
|
+
</Header.Subheader>
|
|
163
|
+
</Header>
|
|
164
|
+
)}
|
|
165
|
+
</GridColumn>
|
|
166
|
+
</Grid>
|
|
167
|
+
</Segment>
|
|
168
|
+
);
|
|
169
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React, { useState, useContext } from "react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import { useIntl } from "react-intl";
|
|
5
|
+
import { Controller, useFormContext } from "react-hook-form";
|
|
6
|
+
import { Button, Grid, Form, Label, Segment } from "semantic-ui-react";
|
|
7
|
+
import QxContext from "@truedat/qx/components/QxContext";
|
|
8
|
+
import { From, GroupBy, Join, Select, Where } from "./queryableProperties";
|
|
9
|
+
import { getColorById, reduceQueryableFields } from "./queryableFunctions";
|
|
10
|
+
|
|
11
|
+
const queryableComponents = {
|
|
12
|
+
from: <From />,
|
|
13
|
+
group_by: <GroupBy />,
|
|
14
|
+
join: <Join />,
|
|
15
|
+
select: <Select />,
|
|
16
|
+
where: <Where />,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default function Queryable({ index, onDelete }) {
|
|
20
|
+
const { formatMessage } = useIntl();
|
|
21
|
+
const { control, watch } = useFormContext();
|
|
22
|
+
const context = useContext(QxContext);
|
|
23
|
+
const [isShownDelete, setIsShownDelete] = useState();
|
|
24
|
+
const { type } = watch(`queryables[${index}]`);
|
|
25
|
+
|
|
26
|
+
const queryables = watch("queryables");
|
|
27
|
+
const fieldsOffset = _.prop(`[${index}].type`)(queryables) === "join" ? 1 : 0;
|
|
28
|
+
const fields = _.flow(
|
|
29
|
+
_.slice(0, index + fieldsOffset),
|
|
30
|
+
reduceQueryableFields(formatMessage)
|
|
31
|
+
)(queryables);
|
|
32
|
+
|
|
33
|
+
const queryable = watch(`queryables[${index}]`);
|
|
34
|
+
const queryableResourceKey = (queryable) => {
|
|
35
|
+
switch (queryable.type) {
|
|
36
|
+
case "join":
|
|
37
|
+
case "from":
|
|
38
|
+
const { alias, properties } = queryable;
|
|
39
|
+
const { id, type } = properties.resource || {};
|
|
40
|
+
return [id, type, alias].join(":");
|
|
41
|
+
default:
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const validateAlias = _.flow(
|
|
47
|
+
_.remove((qry) => qry.id == queryable.id),
|
|
48
|
+
_.map("alias"),
|
|
49
|
+
_.reject((alias) => _.isNil(alias) || _.isEmpty(alias)),
|
|
50
|
+
_.includes(queryable.alias)
|
|
51
|
+
)(queryables)
|
|
52
|
+
? formatMessage({
|
|
53
|
+
id: "dataViews.form.queryable.alias.duplicated",
|
|
54
|
+
})
|
|
55
|
+
: null;
|
|
56
|
+
|
|
57
|
+
const validateResource = _.flow(
|
|
58
|
+
_.remove((qry) => qry.id == queryable.id),
|
|
59
|
+
_.map(queryableResourceKey),
|
|
60
|
+
_.reject(_.isNil),
|
|
61
|
+
_.includes(queryableResourceKey(queryable))
|
|
62
|
+
)(queryables)
|
|
63
|
+
? formatMessage({
|
|
64
|
+
id: "dataViews.form.queryable.resource.duplicated",
|
|
65
|
+
})
|
|
66
|
+
: null;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
onMouseEnter={() => setIsShownDelete(true)}
|
|
71
|
+
onMouseLeave={() => setIsShownDelete(false)}
|
|
72
|
+
>
|
|
73
|
+
<Grid>
|
|
74
|
+
<Grid.Column>
|
|
75
|
+
<Segment>
|
|
76
|
+
<div className="queryable-label">
|
|
77
|
+
<Label ribbon color={getColorById(queryable.id)}>
|
|
78
|
+
{formatMessage({ id: `dataViews.form.queryable.${type}` })}
|
|
79
|
+
</Label>
|
|
80
|
+
{isShownDelete && index != 0 ? (
|
|
81
|
+
<Button
|
|
82
|
+
onClick={onDelete}
|
|
83
|
+
icon="trash alternate outline"
|
|
84
|
+
basic
|
|
85
|
+
color="red"
|
|
86
|
+
aria-label="delete"
|
|
87
|
+
/>
|
|
88
|
+
) : null}
|
|
89
|
+
</div>
|
|
90
|
+
<Grid.Row className="vertical-space">
|
|
91
|
+
<Controller
|
|
92
|
+
control={control}
|
|
93
|
+
name={`queryables[${index}].alias`}
|
|
94
|
+
rules={{
|
|
95
|
+
validate: () => validateAlias || validateResource,
|
|
96
|
+
}}
|
|
97
|
+
render={({
|
|
98
|
+
field: { onBlur, onChange, value },
|
|
99
|
+
fieldState: { error },
|
|
100
|
+
}) => (
|
|
101
|
+
<Form.Input
|
|
102
|
+
label={formatMessage({
|
|
103
|
+
id: "dataViews.form.queryable.alias",
|
|
104
|
+
})}
|
|
105
|
+
autoComplete="off"
|
|
106
|
+
placeholder={formatMessage({
|
|
107
|
+
id: "dataViews.form.queryable.alias",
|
|
108
|
+
})}
|
|
109
|
+
error={error?.message}
|
|
110
|
+
onBlur={onBlur}
|
|
111
|
+
onChange={(_e, { value }) => onChange(value)}
|
|
112
|
+
value={value}
|
|
113
|
+
/>
|
|
114
|
+
)}
|
|
115
|
+
/>
|
|
116
|
+
</Grid.Row>
|
|
117
|
+
<Grid.Row className="vertical-space">
|
|
118
|
+
<QxContext.Provider
|
|
119
|
+
value={{
|
|
120
|
+
...context,
|
|
121
|
+
field: `queryables[${index}].properties`,
|
|
122
|
+
fields,
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
{queryableComponents[type]}
|
|
126
|
+
</QxContext.Provider>
|
|
127
|
+
</Grid.Row>
|
|
128
|
+
</Segment>
|
|
129
|
+
</Grid.Column>
|
|
130
|
+
</Grid>
|
|
131
|
+
</div>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
Queryable.propTypes = {
|
|
136
|
+
index: PropTypes.number,
|
|
137
|
+
onDelete: PropTypes.func,
|
|
138
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
import { useFieldArray } from "react-hook-form";
|
|
5
|
+
import { Button, Divider, List } from "semantic-ui-react";
|
|
6
|
+
import Queryable from "./Queryable";
|
|
7
|
+
|
|
8
|
+
export default function Queryables() {
|
|
9
|
+
const { formatMessage } = useIntl();
|
|
10
|
+
const { fields, append, remove } = useFieldArray({
|
|
11
|
+
name: "queryables",
|
|
12
|
+
keyName: "key",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const newClause = () => [
|
|
16
|
+
{ expressions: [{ shape: "function", value: { isCondition: true } }] },
|
|
17
|
+
];
|
|
18
|
+
const maxParamId = _.flow(_.map("id"), _.max)(fields) || 0;
|
|
19
|
+
const defaultPropertiesForType = {
|
|
20
|
+
where: {
|
|
21
|
+
clauses: newClause(),
|
|
22
|
+
},
|
|
23
|
+
join: {
|
|
24
|
+
clauses: newClause(),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const newQueryable = (type) => ({
|
|
28
|
+
type,
|
|
29
|
+
id: maxParamId + 1,
|
|
30
|
+
properties: _.propOr({}, type)(defaultPropertiesForType),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const queryableTypes = ["join", "where", "select", "group_by"];
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<List>
|
|
37
|
+
{fields.map((param, index) => (
|
|
38
|
+
<List.Item key={param.key}>
|
|
39
|
+
<Queryable index={index} onDelete={() => remove(index)} />
|
|
40
|
+
</List.Item>
|
|
41
|
+
))}
|
|
42
|
+
<List.Item>
|
|
43
|
+
<Divider horizontal>
|
|
44
|
+
{queryableTypes.map((type, idx) => (
|
|
45
|
+
<Button key={idx} onClick={() => append(newQueryable(type))}>
|
|
46
|
+
{formatMessage({ id: `dataViews.form.queryable.${type}` })}
|
|
47
|
+
</Button>
|
|
48
|
+
))}
|
|
49
|
+
</Divider>
|
|
50
|
+
</List.Item>
|
|
51
|
+
</List>
|
|
52
|
+
);
|
|
53
|
+
}
|