Skip to content

Commit

Permalink
added datetime-local UI helper in the search form
Browse files Browse the repository at this point in the history
  • Loading branch information
mmadariaga committed May 24, 2024
1 parent 2c5ac9d commit 9cda21b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@irontec/ivoz-ui",
"version": "1.3.5",
"version": "1.3.6",
"description": "UI library used in ivozprovider",
"license": "GPL-3.0",
"main": "index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NullablePropertyFkChoices } from '../../../../entities';
import {
PropertyList,
isPropertyFk,
isPropertyScalar,
} from '../../../../services/api/ParsedApiSpecInterface';
import {
DropdownChoices,
Expand Down Expand Up @@ -80,6 +81,7 @@ export default function ContentFilterRow(
}, [row]);

const column = columns[name];

let enumValue: DropdownChoices | null = null;
if (isPropertyFk(column)) {
enumValue = fkChoices[name] || {};
Expand All @@ -92,6 +94,17 @@ export default function ContentFilterRow(
};
}

const columnFormat = isPropertyScalar(column) && column.format;
let textFieldInputType = 'text';
const inputProps: Record<string, unknown> = {};

switch (columnFormat) {
case 'date-time':
textFieldInputType = 'datetime-local';
inputProps.step = 1;
break;
}

const updateCriteria = () => {
setRow(idx, name, type, value);
};
Expand Down Expand Up @@ -149,14 +162,19 @@ export default function ContentFilterRow(
<StyledTextField
name='value'
value={value}
type='text'
type={textFieldInputType}
error={false}
errorMsg=''
inputProps={{}}
inputProps={inputProps}
InputProps={{}}
hasChanged={false}
onChange={({ target }) => {
setValue(target.value);
let { value } = target;
if (textFieldInputType === 'datetime-local') {
value = value.replace('T', ' ');
}

setValue(value);
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const StyledContentFilterSelector = styled(ContentFilterSelector)(
flexDirection: 'column',
gap: 'var(--spacing-xl)',
padding: 'var(--spacing-lg)',
width: '700px',
width: '735px',
maxWidth: '100%',
[theme.breakpoints.down('md')]: {
width: '320px',
Expand Down
4 changes: 4 additions & 0 deletions library/src/entities/DefaultEntityBehavior/ListDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const ListDecorator: ListDecoratorType = (props) => {
return value?.substring(0, 10) || '';
}

if (isPropertyScalar(property) && property.format === 'date-time') {
return value ? new Date(value).toLocaleString() : '';
}

if (!value && property.null) {
value = property.null;
}
Expand Down

0 comments on commit 9cda21b

Please sign in to comment.