@evoke-platform/ui-components 1.1.0-testing.12 → 1.1.0-testing.13

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.
@@ -3,6 +3,7 @@ import { ClearRounded } from '@mui/icons-material';
3
3
  import { Box, darken, lighten, styled } from '@mui/material';
4
4
  import { TimePicker } from '@mui/x-date-pickers';
5
5
  import React, { useEffect, useRef, useState } from 'react';
6
+ import { InvalidDate } from '../../../util';
6
7
  import { Autocomplete, Chip, DatePicker, DateTimePicker, LocalizationProvider, Menu, MenuItem, TextField, Typography, } from '../../core';
7
8
  import { NumericFormat } from '../FormField/InputFieldComponent';
8
9
  const GroupHeader = styled('div')(({ theme }) => ({
@@ -32,6 +33,7 @@ const ValueEditor = (props) => {
32
33
  }));
33
34
  }
34
35
  }
36
+ const [invalidDateTime, setInvalidDateTime] = useState(false);
35
37
  const [anchorEl, setAnchorEl] = useState(null);
36
38
  const inputRef = useRef(null);
37
39
  const [openPresetValues, setOpenPresetValues] = useState(false);
@@ -82,12 +84,47 @@ const ValueEditor = (props) => {
82
84
  const groupRenderGroup = (params) => (React.createElement("li", { key: params.key },
83
85
  React.createElement(GroupHeader, null, params.group),
84
86
  React.createElement(GroupItems, null, params.children)));
85
- function parseISOStringToLocalDateTime(value) {
87
+ function validateDateTime(value) {
86
88
  if (!value) {
87
89
  return null;
88
90
  }
89
- const d = new Date(value);
90
- return LocalDateTime.ofInstant(Instant.ofEpochMilli(d.getTime()), ZoneId.systemDefault());
91
+ // check if it's an ISO string
92
+ const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
93
+ if (isoRegex.test(value)) {
94
+ try {
95
+ const instant = Instant.parse(value);
96
+ return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
97
+ }
98
+ catch (error) {
99
+ console.error('Error parsing ISO string:', error);
100
+ }
101
+ }
102
+ return new InvalidDate(value);
103
+ }
104
+ // Prevents the RangeError issue on keyboard input by returning an empty string for invalid dates
105
+ // lets users type partial dates without crashing the component during the input process.
106
+ function convertToISOString(date) {
107
+ if (!date) {
108
+ return '';
109
+ }
110
+ try {
111
+ if (date instanceof InvalidDate) {
112
+ return '';
113
+ }
114
+ if (date instanceof LocalDateTime) {
115
+ return new Date(date.toString()).toISOString();
116
+ }
117
+ if (date instanceof LocalDate) {
118
+ // Convert LocalDate to LocalDateTime to avoid HourOfDay error
119
+ const dateTime = LocalDateTime.of(date, LocalTime.of(0));
120
+ return new Date(dateTime.toString()).toISOString();
121
+ }
122
+ return '';
123
+ }
124
+ catch (error) {
125
+ console.error('Error converting date to ISO string:', error);
126
+ return '';
127
+ }
91
128
  }
92
129
  const getEditor = () => {
93
130
  if (isPresetValueSelected) {
@@ -106,26 +143,44 @@ const ValueEditor = (props) => {
106
143
  React.createElement(TimePicker, { inputRef: inputRef, disabled: disabled, value: disabled || !value ? null : value, onChange: handleOnChange, renderInput: (params) => (React.createElement(TextField, { ...params, onClick: onClick, placeholder: "Value", size: "small", sx: styles.input })), readOnly: readOnly })));
107
144
  }
108
145
  else if (inputType === 'date-time') {
109
- const dateTimeValue = parseISOStringToLocalDateTime(value);
146
+ const dateTimeValue = validateDateTime(value);
110
147
  return (React.createElement(LocalizationProvider, null,
111
148
  React.createElement(DateTimePicker, { inputRef: inputRef, value: dateTimeValue, onChange: (date) => {
112
149
  if (!date) {
113
150
  handleOnChange('');
151
+ setInvalidDateTime(false);
114
152
  return;
115
153
  }
116
- let localDateTime;
117
- if (date instanceof LocalDate && !(date instanceof LocalDateTime)) {
118
- // onChange initially returns a LocalDate after date is selected
119
- localDateTime = LocalDateTime.of(date, LocalTime.of(0));
154
+ if (date instanceof InvalidDate) {
155
+ setInvalidDateTime(true);
156
+ return;
120
157
  }
121
- else {
122
- localDateTime = date;
158
+ try {
159
+ let localDateTime;
160
+ if (date instanceof LocalDate && !(date instanceof LocalDateTime)) {
161
+ // onChange initially returns a LocalDate after date is selected
162
+ localDateTime = LocalDateTime.of(date, LocalTime.of(0));
163
+ }
164
+ else {
165
+ localDateTime = date;
166
+ }
167
+ const isoString = convertToISOString(localDateTime);
168
+ if (isoString) {
169
+ setInvalidDateTime(false);
170
+ handleOnChange(isoString);
171
+ }
172
+ else {
173
+ setInvalidDateTime(true);
174
+ }
175
+ }
176
+ catch (error) {
177
+ console.error('Error processing date value:', error);
178
+ setInvalidDateTime(true);
123
179
  }
124
- handleOnChange(new Date(localDateTime.toString()).toISOString());
125
180
  }, onClose: onClose, PopperProps: {
126
181
  anchorEl,
127
182
  }, renderInput: (params) => (React.createElement(Box, { sx: styles.input, ref: setAnchorEl },
128
- React.createElement(TextField, { ...params, disabled: disabled, onClick: onClick, placeholder: "Value", size: "small", inputRef: inputRef }))), readOnly: readOnly })));
183
+ React.createElement(TextField, { ...params, disabled: disabled, onClick: onClick, placeholder: "Value", size: "small", inputRef: inputRef, error: invalidDateTime }))), readOnly: readOnly })));
129
184
  }
130
185
  else if (inputType === 'number' || inputType === 'integer') {
131
186
  const isMultiple = ['in', 'notIn'].includes(operator);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.1.0-testing.12",
3
+ "version": "1.1.0-testing.13",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",