datajunction-ui 0.0.1-a54.dev0 → 0.0.1-a56
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
CHANGED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { useContext, useEffect, useRef, useState } from 'react';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import DJClientContext from '../../providers/djclient';
|
|
4
|
-
import { Field, Form, Formik } from 'formik';
|
|
5
|
-
import { FormikSelect } from '../AddEditNodePage/FormikSelect';
|
|
6
|
-
import EditIcon from '../../icons/EditIcon';
|
|
7
|
-
import { displayMessageAfterSubmit } from '../../../utils/form';
|
|
8
|
-
import LoadingIcon from '../../icons/LoadingIcon';
|
|
9
|
-
import { NodeQueryField } from '../AddEditNodePage/NodeQueryField';
|
|
10
|
-
|
|
11
|
-
export default function LinkComplexDimensionPopover({ link, onSubmit }) {
|
|
12
|
-
const djClient = useContext(DJClientContext).DataJunctionAPI;
|
|
13
|
-
const [popoverAnchor, setPopoverAnchor] = useState(false);
|
|
14
|
-
const ref = useRef(null);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
const handleClickOutside = event => {
|
|
18
|
-
if (ref.current && !ref.current.contains(event.target)) {
|
|
19
|
-
setPopoverAnchor(false);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
document.addEventListener('click', handleClickOutside, true);
|
|
23
|
-
return () => {
|
|
24
|
-
document.removeEventListener('click', handleClickOutside, true);
|
|
25
|
-
};
|
|
26
|
-
}, [setPopoverAnchor]);
|
|
27
|
-
|
|
28
|
-
const handleSubmit = async (
|
|
29
|
-
{ node, column, dimension },
|
|
30
|
-
{ setSubmitting, setStatus },
|
|
31
|
-
) => {
|
|
32
|
-
onSubmit();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const linkDimension = async (node, column, dimension, setStatus) => {
|
|
36
|
-
const response = await djClient.linkDimension(node, column, dimension);
|
|
37
|
-
if (response.status === 200 || response.status === 201) {
|
|
38
|
-
setStatus({ success: 'Saved!' });
|
|
39
|
-
} else {
|
|
40
|
-
setStatus({
|
|
41
|
-
failure: `${response.json.message}`,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const unlinkDimension = async (node, column, currentDimension, setStatus) => {
|
|
47
|
-
const response = await djClient.unlinkDimension(
|
|
48
|
-
node,
|
|
49
|
-
column,
|
|
50
|
-
currentDimension,
|
|
51
|
-
);
|
|
52
|
-
if (response.status === 200 || response.status === 201) {
|
|
53
|
-
setStatus({ success: 'Removed dimension link!' });
|
|
54
|
-
} else {
|
|
55
|
-
setStatus({
|
|
56
|
-
failure: `${response.json.message}`,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<>
|
|
63
|
-
<button
|
|
64
|
-
className="edit_button"
|
|
65
|
-
aria-label="LinkDimension"
|
|
66
|
-
tabIndex="0"
|
|
67
|
-
onClick={() => {
|
|
68
|
-
setPopoverAnchor(!popoverAnchor);
|
|
69
|
-
}}
|
|
70
|
-
>
|
|
71
|
-
<EditIcon />
|
|
72
|
-
</button>
|
|
73
|
-
<div
|
|
74
|
-
className="popover"
|
|
75
|
-
role="dialog"
|
|
76
|
-
aria-label="client-code"
|
|
77
|
-
style={{ display: popoverAnchor === false ? 'none' : 'block' }}
|
|
78
|
-
ref={ref}
|
|
79
|
-
>
|
|
80
|
-
<Formik
|
|
81
|
-
initialValues={{
|
|
82
|
-
link: link,
|
|
83
|
-
}}
|
|
84
|
-
onSubmit={handleSubmit}
|
|
85
|
-
>
|
|
86
|
-
{function Render({ isSubmitting, status, setFieldValue }) {
|
|
87
|
-
console.log('link', link);
|
|
88
|
-
return (
|
|
89
|
-
<Form>
|
|
90
|
-
{displayMessageAfterSubmit(status)}
|
|
91
|
-
<span data-testid="link-dimension"></span>
|
|
92
|
-
<input
|
|
93
|
-
// hidden={true}
|
|
94
|
-
disabled={true}
|
|
95
|
-
name="dimension"
|
|
96
|
-
value={link.dimension.name}
|
|
97
|
-
readOnly={true}
|
|
98
|
-
/>
|
|
99
|
-
<label htmlFor={'join_type'}>Join Type</label>
|
|
100
|
-
<input name="join_type" value={link.join_type} />
|
|
101
|
-
<label htmlFor={'join_sql'}>Join On</label>
|
|
102
|
-
<div style={{ width: '50%' }}>
|
|
103
|
-
<NodeQueryField
|
|
104
|
-
djClient={djClient}
|
|
105
|
-
value={link.join_sql ? link.join_sql : ''}
|
|
106
|
-
/>
|
|
107
|
-
</div>
|
|
108
|
-
<button
|
|
109
|
-
className="add_node"
|
|
110
|
-
type="submit"
|
|
111
|
-
aria-label="SaveLinkDimension"
|
|
112
|
-
aria-hidden="false"
|
|
113
|
-
disabled={isSubmitting}
|
|
114
|
-
>
|
|
115
|
-
{isSubmitting ? <LoadingIcon /> : 'Save'}
|
|
116
|
-
</button>
|
|
117
|
-
</Form>
|
|
118
|
-
);
|
|
119
|
-
}}
|
|
120
|
-
</Formik>
|
|
121
|
-
</div>
|
|
122
|
-
</>
|
|
123
|
-
);
|
|
124
|
-
}
|