datajunction-ui 0.0.1-a42.dev0 → 0.0.1-a43.dev0

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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/src/app/index.tsx +1 -0
  3. package/src/app/pages/AddEditNodePage/AlertMessage.jsx +10 -0
  4. package/src/app/pages/AddEditNodePage/DescriptionField.jsx +17 -0
  5. package/src/app/pages/AddEditNodePage/DisplayNameField.jsx +16 -0
  6. package/src/app/pages/AddEditNodePage/FormikSelect.jsx +2 -0
  7. package/src/app/pages/AddEditNodePage/FullNameField.jsx +3 -2
  8. package/src/app/pages/AddEditNodePage/MetricMetadataFields.jsx +60 -0
  9. package/src/app/pages/AddEditNodePage/MetricQueryField.jsx +71 -0
  10. package/src/app/pages/AddEditNodePage/NamespaceField.jsx +40 -0
  11. package/src/app/pages/AddEditNodePage/NodeModeField.jsx +14 -0
  12. package/src/app/pages/AddEditNodePage/NodeQueryField.jsx +5 -3
  13. package/src/app/pages/AddEditNodePage/PrimaryKeySelect.jsx +61 -0
  14. package/src/app/pages/AddEditNodePage/RequiredDimensionsSelect.jsx +54 -0
  15. package/src/app/pages/AddEditNodePage/TagsField.jsx +47 -0
  16. package/src/app/pages/AddEditNodePage/UpstreamNodeField.jsx +49 -0
  17. package/src/app/pages/AddEditNodePage/__tests__/AddEditNodePageFormFailed.test.jsx +2 -1
  18. package/src/app/pages/AddEditNodePage/__tests__/AddEditNodePageFormSuccess.test.jsx +150 -14
  19. package/src/app/pages/AddEditNodePage/__tests__/index.test.jsx +35 -8
  20. package/src/app/pages/AddEditNodePage/index.jsx +177 -232
  21. package/src/app/pages/CubeBuilderPage/MetricsSelect.jsx +0 -1
  22. package/src/app/pages/CubeBuilderPage/__tests__/index.test.jsx +1 -1
  23. package/src/app/pages/CubeBuilderPage/index.jsx +1 -1
  24. package/src/app/pages/NodePage/AddMaterializationPopover.jsx +0 -1
  25. package/src/app/pages/NodePage/NodeHistory.jsx +1 -1
  26. package/src/app/pages/NodePage/NodeInfoTab.jsx +54 -13
  27. package/src/app/pages/NodePage/__tests__/NodePage.test.jsx +34 -28
  28. package/src/app/pages/NodePage/__tests__/__snapshots__/NodePage.test.jsx.snap +2 -18
  29. package/src/app/pages/NodePage/index.jsx +30 -27
  30. package/src/app/pages/Root/index.tsx +3 -2
  31. package/src/app/services/DJService.js +37 -0
  32. package/src/app/services/__tests__/DJService.test.jsx +23 -0
  33. package/src/mocks/mockNodes.jsx +63 -0
  34. package/src/styles/index.css +6 -0
  35. package/src/styles/node-creation.scss +63 -5
  36. package/dj.internal.db +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datajunction-ui",
3
- "version": "0.0.1-a42.dev0",
3
+ "version": "0.0.1-a43.dev0",
4
4
  "description": "DataJunction Metrics Platform UI",
5
5
  "module": "src/index.tsx",
6
6
  "repository": {
package/src/app/index.tsx CHANGED
@@ -58,6 +58,7 @@ export function App() {
58
58
  key="edit-cube"
59
59
  element={<CubeBuilderPage />}
60
60
  />
61
+ <Route path=":name/:tab" element={<NodePage />} />
61
62
  </Route>
62
63
 
63
64
  <Route path="/" element={<NamespacePage />} key="index" />
@@ -0,0 +1,10 @@
1
+ import AlertIcon from '../../icons/AlertIcon';
2
+
3
+ export const AlertMessage = ({ message }) => {
4
+ return (
5
+ <div className="message alert">
6
+ <AlertIcon />
7
+ {message}
8
+ </div>
9
+ );
10
+ };
@@ -0,0 +1,17 @@
1
+ import { ErrorMessage, Field } from 'formik';
2
+
3
+ export const DescriptionField = () => {
4
+ return (
5
+ <div className="DescriptionInput NodeCreationInput">
6
+ <ErrorMessage name="description" component="span" />
7
+ <label htmlFor="Description">Description</label>
8
+ <Field
9
+ type="textarea"
10
+ as="textarea"
11
+ name="description"
12
+ id="Description"
13
+ placeholder="Describe your node"
14
+ />
15
+ </div>
16
+ );
17
+ };
@@ -0,0 +1,16 @@
1
+ import { ErrorMessage, Field } from 'formik';
2
+
3
+ export const DisplayNameField = () => {
4
+ return (
5
+ <div className="DisplayNameInput NodeCreationInput">
6
+ <ErrorMessage name="display_name" component="span" />
7
+ <label htmlFor="displayName">Display Name *</label>
8
+ <Field
9
+ type="text"
10
+ name="display_name"
11
+ id="displayName"
12
+ placeholder="Human readable display name"
13
+ />
14
+ </div>
15
+ );
16
+ };
@@ -12,6 +12,7 @@ export const FormikSelect = ({
12
12
  style,
13
13
  className = 'SelectInput',
14
14
  isMulti = false,
15
+ onFocus = event => {},
15
16
  }) => {
16
17
  // eslint-disable-next-line no-unused-vars
17
18
  const [field, _, helpers] = useField(formikFieldName);
@@ -37,6 +38,7 @@ export const FormikSelect = ({
37
38
  onChange={selected => setValue(getValue(selected))}
38
39
  styles={style}
39
40
  isMulti={isMulti}
41
+ onFocus={event => onFocus(event)}
40
42
  />
41
43
  );
42
44
  };
@@ -11,12 +11,13 @@ export const FullNameField = props => {
11
11
 
12
12
  useEffect(() => {
13
13
  // Set the value of the node's full name based on its namespace and display name
14
- if (values.namespace && values.display_name) {
14
+ if (values.namespace || values.display_name) {
15
15
  setFieldValue(
16
16
  props.name,
17
17
  `${values.namespace}.${values.display_name
18
18
  .toLowerCase()
19
- .replace(/ /g, '_')}` || '',
19
+ .replace(/ /g, '_')
20
+ .replace(/[^a-zA-Z0-9_]/g, '')}` || '',
20
21
  );
21
22
  }
22
23
  }, [setFieldValue, props.name, values]);
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Metric unit select component
3
+ */
4
+ import { ErrorMessage, Field } from 'formik';
5
+ import { useContext, useEffect, useState } from 'react';
6
+ import DJClientContext from '../../providers/djclient';
7
+ import { labelize } from '../../../utils/form';
8
+
9
+ export const MetricMetadataFields = () => {
10
+ const djClient = useContext(DJClientContext).DataJunctionAPI;
11
+
12
+ // Metric metadata
13
+ const [metricUnits, setMetricUnits] = useState([]);
14
+ const [metricDirections, setMetricDirections] = useState([]);
15
+
16
+ // Get metric metadata values
17
+ useEffect(() => {
18
+ const fetchData = async () => {
19
+ const metadata = await djClient.listMetricMetadata();
20
+ setMetricDirections(metadata.directions);
21
+ setMetricUnits(metadata.units);
22
+ };
23
+ fetchData().catch(console.error);
24
+ }, [djClient]);
25
+
26
+ return (
27
+ <>
28
+ <div
29
+ className="MetricDirectionInput NodeCreationInput"
30
+ style={{ width: '25%' }}
31
+ >
32
+ <ErrorMessage name="metric_direction" component="span" />
33
+ <label htmlFor="MetricDirection">Metric Direction</label>
34
+ <Field as="select" name="metric_direction" id="MetricDirection">
35
+ <option value=""></option>
36
+ {metricDirections.map(direction => (
37
+ <option value={direction} key={direction}>
38
+ {labelize(direction)}
39
+ </option>
40
+ ))}
41
+ </Field>
42
+ </div>
43
+ <div
44
+ className="MetricUnitInput NodeCreationInput"
45
+ style={{ width: '25%' }}
46
+ >
47
+ <ErrorMessage name="metric_unit" component="span" />
48
+ <label htmlFor="MetricUnit">Metric Unit</label>
49
+ <Field as="select" name="metric_unit" id="MetricUnit">
50
+ <option value=""></option>
51
+ {metricUnits.map(unit => (
52
+ <option value={unit.name} key={unit.name}>
53
+ {unit.label}
54
+ </option>
55
+ ))}
56
+ </Field>
57
+ </div>
58
+ </>
59
+ );
60
+ };
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Metric aggregate expression input field, which consists of a CodeMirror SQL
3
+ * editor with autocompletion for node columns and syntax highlighting.
4
+ */
5
+ import React from 'react';
6
+ import { ErrorMessage, Field, useFormikContext } from 'formik';
7
+ import CodeMirror from '@uiw/react-codemirror';
8
+ import { langs } from '@uiw/codemirror-extensions-langs';
9
+
10
+ export const MetricQueryField = ({ djClient, value }) => {
11
+ const [schema, setSchema] = React.useState([]);
12
+ const formik = useFormikContext();
13
+ const sqlExt = langs.sql({ schema: schema });
14
+
15
+ const initialAutocomplete = async context => {
16
+ // Based on the selected upstream, we load the upstream node's columns
17
+ // into the autocomplete schema
18
+ const nodeName = formik.values['upstream_node'];
19
+ const nodeDetails = await djClient.node(nodeName);
20
+ nodeDetails.columns.forEach(col => {
21
+ schema[col.name] = [];
22
+ });
23
+ setSchema(schema);
24
+ };
25
+
26
+ const updateFormik = val => {
27
+ formik.setFieldValue('aggregate_expression', val);
28
+ };
29
+
30
+ return (
31
+ <div className="QueryInput MetricQueryInput NodeCreationInput">
32
+ <ErrorMessage name="query" component="span" />
33
+ <label htmlFor="Query">Aggregate Expression *</label>
34
+ <Field
35
+ type="textarea"
36
+ style={{ display: 'none' }}
37
+ as="textarea"
38
+ name="aggregate_expression"
39
+ id="Query"
40
+ />
41
+ <div role="button" tabIndex={0} className="relative flex bg-[#282a36]">
42
+ <CodeMirror
43
+ id={'aggregate_expression'}
44
+ name={'aggregate_expression'}
45
+ extensions={[
46
+ sqlExt,
47
+ sqlExt.language.data.of({
48
+ autocomplete: initialAutocomplete,
49
+ }),
50
+ ]}
51
+ value={value}
52
+ options={{
53
+ theme: 'default',
54
+ lineNumbers: true,
55
+ }}
56
+ width="100%"
57
+ height="100px"
58
+ style={{
59
+ margin: '0 0 23px 0',
60
+ flex: 1,
61
+ fontSize: '150%',
62
+ textAlign: 'left',
63
+ }}
64
+ onChange={(value, viewUpdate) => {
65
+ updateFormik(value);
66
+ }}
67
+ />
68
+ </div>
69
+ </div>
70
+ );
71
+ };
@@ -0,0 +1,40 @@
1
+ import { ErrorMessage } from 'formik';
2
+ import { FormikSelect } from './FormikSelect';
3
+ import { useContext, useEffect, useState } from 'react';
4
+ import DJClientContext from '../../providers/djclient';
5
+
6
+ export const NamespaceField = ({ initialNamespace }) => {
7
+ const djClient = useContext(DJClientContext).DataJunctionAPI;
8
+
9
+ const [namespaces, setNamespaces] = useState([]);
10
+
11
+ // Get namespaces, only necessary when creating a node
12
+ useEffect(() => {
13
+ const fetchData = async () => {
14
+ const namespaces = await djClient.namespaces();
15
+ setNamespaces(
16
+ namespaces.map(m => ({
17
+ value: m['namespace'],
18
+ label: m['namespace'],
19
+ })),
20
+ );
21
+ };
22
+ fetchData().catch(console.error);
23
+ }, [djClient]);
24
+
25
+ return (
26
+ <div className="NamespaceInput">
27
+ <ErrorMessage name="namespace" component="span" />
28
+ <label htmlFor="react-select-3-input">Namespace *</label>
29
+ <FormikSelect
30
+ selectOptions={namespaces}
31
+ formikFieldName="namespace"
32
+ placeholder="Choose Namespace"
33
+ defaultValue={{
34
+ value: initialNamespace,
35
+ label: initialNamespace,
36
+ }}
37
+ />
38
+ </div>
39
+ );
40
+ };
@@ -0,0 +1,14 @@
1
+ import { ErrorMessage, Field } from 'formik';
2
+
3
+ export const NodeModeField = () => {
4
+ return (
5
+ <div className="NodeModeInput NodeCreationInput">
6
+ <ErrorMessage name="mode" component="span" />
7
+ <label htmlFor="Mode">Mode</label>
8
+ <Field as="select" name="mode" id="Mode">
9
+ <option value="draft">Draft</option>
10
+ <option value="published">Published</option>
11
+ </Field>
12
+ </div>
13
+ );
14
+ };
@@ -3,7 +3,7 @@
3
3
  * (for node names and columns) and syntax highlighting.
4
4
  */
5
5
  import React from 'react';
6
- import { Field, useFormikContext } from 'formik';
6
+ import { ErrorMessage, Field, useFormikContext } from 'formik';
7
7
  import CodeMirror from '@uiw/react-codemirror';
8
8
  import { langs } from '@uiw/codemirror-extensions-langs';
9
9
 
@@ -47,7 +47,9 @@ export const NodeQueryField = ({ djClient, value }) => {
47
47
  };
48
48
 
49
49
  return (
50
- <>
50
+ <div className="QueryInput NodeCreationInput">
51
+ <ErrorMessage name="query" component="span" />
52
+ <label htmlFor="Query">Query *</label>
51
53
  <Field
52
54
  type="textarea"
53
55
  style={{ display: 'none' }}
@@ -84,6 +86,6 @@ export const NodeQueryField = ({ djClient, value }) => {
84
86
  }}
85
87
  />
86
88
  </div>
87
- </>
89
+ </div>
88
90
  );
89
91
  };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Primary key select component
3
+ */
4
+ import { ErrorMessage, useFormikContext } from 'formik';
5
+ import { useContext, useMemo, useState } from 'react';
6
+ import DJClientContext from '../../providers/djclient';
7
+ import { FormikSelect } from './FormikSelect';
8
+
9
+ export const PrimaryKeySelect = ({ defaultValue }) => {
10
+ const djClient = useContext(DJClientContext).DataJunctionAPI;
11
+
12
+ // Used to pull out current form values for node validation
13
+ const { values } = useFormikContext();
14
+
15
+ // The available columns, determined from validating the node query
16
+ const [availableColumns, setAvailableColumns] = useState([]);
17
+ const selectableOptions = useMemo(() => {
18
+ if (availableColumns && availableColumns.length > 0) {
19
+ return availableColumns;
20
+ }
21
+ }, [availableColumns]);
22
+
23
+ // When focus is on the primary key field, refresh the list of available
24
+ // primary key columns for selection
25
+ const refreshColumns = event => {
26
+ async function fetchData() {
27
+ // eslint-disable-next-line no-unused-vars
28
+ const { status, json } = await djClient.validateNode(
29
+ values.type,
30
+ values.name,
31
+ values.display_name,
32
+ values.description,
33
+ values.query,
34
+ );
35
+ setAvailableColumns(
36
+ json.columns.map(col => {
37
+ return { value: col.name, label: col.name };
38
+ }),
39
+ );
40
+ }
41
+ fetchData();
42
+ };
43
+
44
+ return (
45
+ <div className="CubeCreationInput">
46
+ <ErrorMessage name="primary_key" component="span" />
47
+ <label htmlFor="react-select-3-input">Primary Key</label>
48
+ <span data-testid="select-primary-key">
49
+ <FormikSelect
50
+ className="MultiSelectInput"
51
+ defaultValue={defaultValue}
52
+ selectOptions={selectableOptions}
53
+ formikFieldName="primary_key"
54
+ placeholder="Choose Primary Key"
55
+ onFocus={event => refreshColumns(event)}
56
+ isMulti={true}
57
+ />
58
+ </span>
59
+ </div>
60
+ );
61
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Required dimensions select component
3
+ */
4
+ import { ErrorMessage, useFormikContext } from 'formik';
5
+ import React, { useContext, useEffect, useState } from 'react';
6
+ import DJClientContext from '../../providers/djclient';
7
+ import { FormikSelect } from './FormikSelect';
8
+
9
+ export const RequiredDimensionsSelect = ({
10
+ defaultValue,
11
+ style,
12
+ className = 'MultiSelectInput',
13
+ }) => {
14
+ const djClient = useContext(DJClientContext).DataJunctionAPI;
15
+
16
+ // Used to pull out current form values for node validation
17
+ const { values } = useFormikContext();
18
+
19
+ // Select options, i.e., the available dimensions
20
+ const [selectOptions, setSelectOptions] = useState([]);
21
+
22
+ useEffect(() => {
23
+ const fetchData = async () => {
24
+ if (values.upstream_node) {
25
+ const data = await djClient.node(values.upstream_node);
26
+ setSelectOptions(
27
+ data.columns.map(col => {
28
+ return {
29
+ value: col.name,
30
+ label: col.name,
31
+ };
32
+ }),
33
+ );
34
+ }
35
+ };
36
+ fetchData().catch(console.error);
37
+ }, [djClient, values.upstream_node]);
38
+
39
+ return (
40
+ <div className="RequiredDimensionsInput CubeCreationInput">
41
+ <ErrorMessage name="required_dimensions" component="span" />
42
+ <label htmlFor="requiredDimensions">Required Dimensions</label>
43
+ <FormikSelect
44
+ className={className}
45
+ defaultValue={defaultValue}
46
+ selectOptions={selectOptions}
47
+ formikFieldName={'required_dimensions'}
48
+ placeholder={'Choose Required Dimensions'}
49
+ styles={style}
50
+ isMulti={true}
51
+ />
52
+ </div>
53
+ );
54
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Tags select field
3
+ */
4
+ import { ErrorMessage } from 'formik';
5
+ import { useContext, useEffect, useState } from 'react';
6
+ import DJClientContext from '../../providers/djclient';
7
+ import { FormikSelect } from './FormikSelect';
8
+
9
+ export const TagsField = ({ defaultValue }) => {
10
+ const djClient = useContext(DJClientContext).DataJunctionAPI;
11
+
12
+ // All available tags
13
+ const [tags, setTags] = useState([]);
14
+
15
+ useEffect(() => {
16
+ const fetchData = async () => {
17
+ const tags = await djClient.listTags();
18
+ setTags(
19
+ tags.map(tag => ({
20
+ value: tag.name,
21
+ label: tag.display_name,
22
+ })),
23
+ );
24
+ };
25
+ fetchData().catch(console.error);
26
+ }, [djClient]);
27
+
28
+ return (
29
+ <div
30
+ className="TagsInput"
31
+ style={{ width: '25%', margin: '1rem 0 1rem 1.2rem' }}
32
+ >
33
+ <ErrorMessage name="tags" component="span" />
34
+ <label htmlFor="react-select-3-input">Tags</label>
35
+ <span data-testid="select-tags">
36
+ <FormikSelect
37
+ isMulti={true}
38
+ selectOptions={tags}
39
+ formikFieldName="tags"
40
+ className="MultiSelectInput"
41
+ placeholder="Choose Tags"
42
+ defaultValue={defaultValue}
43
+ />
44
+ </span>
45
+ </div>
46
+ );
47
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Upstream node select field
3
+ */
4
+ import { ErrorMessage } from 'formik';
5
+ import { useContext, useEffect, useState } from 'react';
6
+ import DJClientContext from '../../providers/djclient';
7
+ import { FormikSelect } from './FormikSelect';
8
+
9
+ export const UpstreamNodeField = ({ defaultValue }) => {
10
+ const djClient = useContext(DJClientContext).DataJunctionAPI;
11
+
12
+ // All available nodes
13
+ const [availableNodes, setAvailableNodes] = useState([]);
14
+
15
+ useEffect(() => {
16
+ async function fetchData() {
17
+ const sources = await djClient.nodesWithType('source');
18
+ const transforms = await djClient.nodesWithType('transform');
19
+ const dimensions = await djClient.nodesWithType('dimension');
20
+ const nodes = sources.concat(transforms).concat(dimensions);
21
+ setAvailableNodes(
22
+ nodes.map(node => {
23
+ return {
24
+ value: node,
25
+ label: node,
26
+ };
27
+ }),
28
+ );
29
+ }
30
+ fetchData();
31
+ }, [djClient]);
32
+
33
+ return (
34
+ <div className="NodeCreationInput">
35
+ <ErrorMessage name="mode" component="span" />
36
+ <label htmlFor="Mode">Upstream Node *</label>
37
+ <span data-testid="select-upstream-node">
38
+ <FormikSelect
39
+ className="SelectInput"
40
+ defaultValue={defaultValue}
41
+ selectOptions={availableNodes}
42
+ formikFieldName="upstream_node"
43
+ placeholder="Select Upstream Node"
44
+ isMulti={false}
45
+ />
46
+ </span>
47
+ </div>
48
+ );
49
+ };
@@ -49,11 +49,12 @@ describe('AddEditNodePage submission failed', () => {
49
49
  'Some Test Metric',
50
50
  '',
51
51
  'SELECT * FROM test',
52
- 'draft',
52
+ 'published',
53
53
  'default',
54
54
  null,
55
55
  undefined,
56
56
  undefined,
57
+ undefined,
57
58
  );
58
59
  expect(
59
60
  screen.getByText(/Some columns in the primary key \[] were not found/),