datajunction-ui 0.0.1-rc.20 → 0.0.1-rc.21
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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { useContext, useState } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import DJClientContext from '../../providers/djclient';
|
|
4
|
+
import { ErrorMessage, Field, Form, Formik } from 'formik';
|
|
5
|
+
import { FormikSelect } from '../AddEditNodePage/FormikSelect';
|
|
6
|
+
import EditIcon from '../../icons/EditIcon';
|
|
7
|
+
import { displayMessageAfterSubmit, labelize } from '../../../utils/form';
|
|
8
|
+
|
|
9
|
+
export default function AddNamespacePopover({ namespace, onSubmit }) {
|
|
10
|
+
const djClient = useContext(DJClientContext).DataJunctionAPI;
|
|
11
|
+
const [popoverAnchor, setPopoverAnchor] = useState(false);
|
|
12
|
+
|
|
13
|
+
const addNamespace = async ({ namespace }, { setSubmitting, setStatus }) => {
|
|
14
|
+
setSubmitting(false);
|
|
15
|
+
const response = await djClient.addNamespace(namespace);
|
|
16
|
+
if (response.status === 200 || response.status === 201) {
|
|
17
|
+
setStatus({ success: 'Saved' });
|
|
18
|
+
} else {
|
|
19
|
+
setStatus({
|
|
20
|
+
failure: `${response.json.message}`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
onSubmit();
|
|
24
|
+
window.location.reload();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
<button
|
|
30
|
+
className="edit_button"
|
|
31
|
+
aria-label="AddNamespaceTogglePopover"
|
|
32
|
+
tabIndex="0"
|
|
33
|
+
onClick={() => {
|
|
34
|
+
setPopoverAnchor(!popoverAnchor);
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<EditIcon />
|
|
38
|
+
</button>
|
|
39
|
+
<div
|
|
40
|
+
className="popover"
|
|
41
|
+
role="dialog"
|
|
42
|
+
aria-label="AddNamespacePopover"
|
|
43
|
+
style={{
|
|
44
|
+
display: popoverAnchor === false ? 'none' : 'block',
|
|
45
|
+
width: '200px !important',
|
|
46
|
+
textTransform: 'none',
|
|
47
|
+
fontWeight: 'normal',
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<Formik
|
|
51
|
+
initialValues={{
|
|
52
|
+
namespace: '',
|
|
53
|
+
}}
|
|
54
|
+
onSubmit={addNamespace}
|
|
55
|
+
>
|
|
56
|
+
{function Render({ isSubmitting, status, setFieldValue }) {
|
|
57
|
+
return (
|
|
58
|
+
<Form>
|
|
59
|
+
{displayMessageAfterSubmit(status)}
|
|
60
|
+
<span data-testid="add-namespace">
|
|
61
|
+
<ErrorMessage name="namespace" component="span" />
|
|
62
|
+
<label htmlFor="namespace">Namespace</label>
|
|
63
|
+
<Field
|
|
64
|
+
type="text"
|
|
65
|
+
name="namespace"
|
|
66
|
+
id="namespace"
|
|
67
|
+
placeholder="New namespace"
|
|
68
|
+
/>
|
|
69
|
+
</span>
|
|
70
|
+
<button
|
|
71
|
+
className="add_node"
|
|
72
|
+
type="submit"
|
|
73
|
+
aria-label="SaveNamespace"
|
|
74
|
+
aria-hidden="false"
|
|
75
|
+
style={{ marginTop: '1rem' }}
|
|
76
|
+
>
|
|
77
|
+
Save
|
|
78
|
+
</button>
|
|
79
|
+
</Form>
|
|
80
|
+
);
|
|
81
|
+
}}
|
|
82
|
+
</Formik>
|
|
83
|
+
</div>
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -6,6 +6,7 @@ import DJClientContext from '../../providers/djclient';
|
|
|
6
6
|
import Explorer from '../NamespacePage/Explorer';
|
|
7
7
|
import EditIcon from '../../icons/EditIcon';
|
|
8
8
|
import DeleteNode from '../../components/DeleteNode';
|
|
9
|
+
import AddNamespacePopover from './AddNamespacePopover';
|
|
9
10
|
|
|
10
11
|
export function NamespacePage() {
|
|
11
12
|
const djClient = useContext(DJClientContext).DataJunctionAPI;
|
|
@@ -58,7 +59,7 @@ export function NamespacePage() {
|
|
|
58
59
|
useEffect(() => {
|
|
59
60
|
const fetchData = async () => {
|
|
60
61
|
if (namespace === undefined && namespaceHierarchy !== undefined) {
|
|
61
|
-
namespace = namespaceHierarchy
|
|
62
|
+
namespace = namespaceHierarchy[0].namespace;
|
|
62
63
|
}
|
|
63
64
|
const nodes = await djClient.namespace(namespace);
|
|
64
65
|
const foundNodes = await Promise.all(nodes);
|
|
@@ -159,7 +160,7 @@ export function NamespacePage() {
|
|
|
159
160
|
padding: '1rem 1rem 1rem 0',
|
|
160
161
|
}}
|
|
161
162
|
>
|
|
162
|
-
Namespaces
|
|
163
|
+
Namespaces <AddNamespacePopover />
|
|
163
164
|
</span>
|
|
164
165
|
{namespaceHierarchy
|
|
165
166
|
? namespaceHierarchy.map(child => (
|
|
@@ -487,4 +487,14 @@ export const DataJunctionAPI = {
|
|
|
487
487
|
});
|
|
488
488
|
return { status: response.status, json: await response.json() };
|
|
489
489
|
},
|
|
490
|
+
addNamespace: async function (namespace) {
|
|
491
|
+
const response = await fetch(`${DJ_URL}/namespaces/${namespace}`, {
|
|
492
|
+
method: 'POST',
|
|
493
|
+
headers: {
|
|
494
|
+
'Content-Type': 'application/json',
|
|
495
|
+
},
|
|
496
|
+
credentials: 'include',
|
|
497
|
+
});
|
|
498
|
+
return { status: response.status, json: await response.json() };
|
|
499
|
+
},
|
|
490
500
|
};
|