datajunction-ui 0.0.77 → 0.0.78

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,6 +1,6 @@
1
1
  {
2
2
  "name": "datajunction-ui",
3
- "version": "0.0.77",
3
+ "version": "0.0.78",
4
4
  "description": "DataJunction UI",
5
5
  "module": "src/index.tsx",
6
6
  "repository": {
@@ -21,10 +21,12 @@ export const ColumnsSelect = ({
21
21
 
22
22
  // The available columns, determined from validating the node query
23
23
  const [availableColumns, setAvailableColumns] = useState([]);
24
+ const [validationError, setValidationError] = useState(null);
24
25
  const selectableOptions = useMemo(() => {
25
26
  if (availableColumns && availableColumns.length > 0) {
26
27
  return availableColumns;
27
28
  }
29
+ return [];
28
30
  }, [availableColumns]);
29
31
 
30
32
  // Fetch columns by validating the latest node query
@@ -41,9 +43,18 @@ export const ColumnsSelect = ({
41
43
  setAvailableColumns(
42
44
  json.columns.map(col => ({ value: col.name, label: col.name })),
43
45
  );
46
+ setValidationError(null);
47
+ } else if (json?.message) {
48
+ setValidationError(json.message);
49
+ setAvailableColumns([]);
44
50
  }
45
51
  } catch (error) {
46
52
  console.error('Error fetching columns:', error);
53
+ setValidationError(
54
+ error.message ||
55
+ 'Failed to validate query. Please check your query syntax.',
56
+ );
57
+ setAvailableColumns([]);
47
58
  }
48
59
  };
49
60
 
@@ -57,6 +68,22 @@ export const ColumnsSelect = ({
57
68
  <label htmlFor={fieldName} style={labelStyle}>
58
69
  {label}
59
70
  </label>
71
+ {validationError && (
72
+ <div
73
+ className="validation-error"
74
+ style={{
75
+ color: '#d32f2f',
76
+ fontSize: '0.875rem',
77
+ marginBottom: '8px',
78
+ padding: '8px',
79
+ backgroundColor: '#ffebee',
80
+ borderRadius: '4px',
81
+ border: '1px solid #ef9a9a',
82
+ }}
83
+ >
84
+ <strong>Validation Error:</strong> {validationError}
85
+ </div>
86
+ )}
60
87
  <span data-testid={`select-${fieldName}`}>
61
88
  <FormikSelect
62
89
  className={isMulti ? 'MultiSelectInput' : 'SelectInput'}
@@ -41,7 +41,7 @@ export const FormikSelect = ({
41
41
 
42
42
  // Convert Formik field value to React Select format
43
43
  const getSelectValue = () => {
44
- if (!field.value) {
44
+ if (!field.value || !selectOptions) {
45
45
  return isMulti ? [] : null;
46
46
  }
47
47
 
@@ -201,7 +201,7 @@ describe('AddEditNodePage submission succeeded', () => {
201
201
  '',
202
202
  '',
203
203
  '',
204
- undefined,
204
+ '',
205
205
  ['dj'],
206
206
  null,
207
207
  );
@@ -270,7 +270,7 @@ describe('AddEditNodePage submission succeeded', () => {
270
270
  'neutral',
271
271
  'unitless',
272
272
  5,
273
- undefined,
273
+ [],
274
274
  ['dj'],
275
275
  { key1: 'value1', key2: 'value2' },
276
276
  );
@@ -72,4 +72,81 @@ describe('FormikSelect', () => {
72
72
  await userEvent.click(screen.getByRole('combobox')); // to open the dropdown
73
73
  expect(screen.getByText('basic.one')).toBeInTheDocument();
74
74
  });
75
+
76
+ it('handles undefined selectOptions gracefully for single-select', () => {
77
+ const utils = render(
78
+ <Formik initialValues={{ test: '' }} onSubmit={jest.fn()}>
79
+ <Form>
80
+ <FormikSelect
81
+ selectOptions={undefined}
82
+ formikFieldName="test"
83
+ placeholder="Choose Option"
84
+ />
85
+ </Form>
86
+ </Formik>,
87
+ );
88
+
89
+ // Should render without crashing
90
+ const selectInput = screen.getByRole('combobox');
91
+ expect(selectInput).toBeInTheDocument();
92
+ });
93
+
94
+ it('handles undefined selectOptions gracefully for multi-select', () => {
95
+ const utils = render(
96
+ <Formik initialValues={{ test: [] }} onSubmit={jest.fn()}>
97
+ <Form>
98
+ <FormikSelect
99
+ selectOptions={undefined}
100
+ formikFieldName="test"
101
+ placeholder="Choose Options"
102
+ isMulti={true}
103
+ />
104
+ </Form>
105
+ </Formik>,
106
+ );
107
+
108
+ // Should render without crashing
109
+ const selectInput = screen.getByRole('combobox');
110
+ expect(selectInput).toBeInTheDocument();
111
+ });
112
+
113
+ it('handles undefined selectOptions with existing field value for single-select', () => {
114
+ const utils = render(
115
+ <Formik initialValues={{ test: 'existing-value' }} onSubmit={jest.fn()}>
116
+ <Form>
117
+ <FormikSelect
118
+ selectOptions={undefined}
119
+ formikFieldName="test"
120
+ placeholder="Choose Option"
121
+ />
122
+ </Form>
123
+ </Formik>,
124
+ );
125
+
126
+ // Should render without crashing even when field has a value
127
+ const selectInput = screen.getByRole('combobox');
128
+ expect(selectInput).toBeInTheDocument();
129
+ });
130
+
131
+ it('handles undefined selectOptions with existing field value for multi-select', () => {
132
+ const utils = render(
133
+ <Formik
134
+ initialValues={{ test: ['value1', 'value2'] }}
135
+ onSubmit={jest.fn()}
136
+ >
137
+ <Form>
138
+ <FormikSelect
139
+ selectOptions={undefined}
140
+ formikFieldName="test"
141
+ placeholder="Choose Options"
142
+ isMulti={true}
143
+ />
144
+ </Form>
145
+ </Formik>,
146
+ );
147
+
148
+ // Should render without crashing even when field has values
149
+ const selectInput = screen.getByRole('combobox');
150
+ expect(selectInput).toBeInTheDocument();
151
+ });
75
152
  });
@@ -325,6 +325,7 @@ export function AddEditNodePage({ extensions = {} }) {
325
325
  'metric_unit',
326
326
  'metric_direction',
327
327
  'significant_digits',
328
+ 'required_dimensions',
328
329
  'owners',
329
330
  'custom_metadata',
330
331
  ];