feat: ui v2 - Date Range Component (#1537)
* feat: Date Range wrapper component * fix yarn issues * add calendar icon * date range css styles * date range fixes * fix propTypes warning * fix clear method, defaultProps & onChange method * update inline styles to use tailwind classes * date range documentation page * minor refactor
This commit is contained in:
1 parent
0ec277dd56
commit
b183e78f47
13 files changed
+407
-38
No files matched your search
@@ -25,16 +25,16 @@ const filtersMeta = [
|
||||
{
|
||||
name: 'studyDate',
|
||||
displayName: 'Study date',
|
||||
inputType: 'text',
|
||||
inputType: 'date-range',
|
||||
isSortable: true,
|
||||
gridCol: 3,
|
||||
gridCol: 5,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
displayName: 'Description',
|
||||
inputType: 'text',
|
||||
isSortable: true,
|
||||
gridCol: 5,
|
||||
gridCol: 4,
|
||||
},
|
||||
{
|
||||
name: 'modality',
|
||||
@@ -55,7 +55,7 @@ const filtersMeta = [
|
||||
displayName: 'Instances',
|
||||
inputType: 'none',
|
||||
isSortable: false,
|
||||
gridCol: 3,
|
||||
gridCol: 2,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import classnames from 'classnames';
|
||||
|
||||
import { Button, Icon, Input, Typography } from '@ohif/ui';
|
||||
import { Button, Icon, Input, Typography, DateRange } from '@ohif/ui';
|
||||
|
||||
const sortIconMap = {
|
||||
'-1': 'sorting-active-down',
|
||||
@@ -14,7 +14,8 @@ const defaultProps = {
|
||||
filtersValues: {
|
||||
patientName: '',
|
||||
mrn: '',
|
||||
studyDate: '',
|
||||
startDate: null,
|
||||
endDate: null,
|
||||
description: '',
|
||||
modality: '',
|
||||
accession: '',
|
||||
@@ -31,7 +32,6 @@ const FilterLabel = ({
|
||||
isBeingSorted = false,
|
||||
sortDirection = 0,
|
||||
onLabelClick,
|
||||
inputType,
|
||||
className,
|
||||
children,
|
||||
}) => {
|
||||
@@ -70,6 +70,16 @@ const FilterLabel = ({
|
||||
);
|
||||
};
|
||||
|
||||
FilterLabel.propTypes = {
|
||||
label: PropTypes.string,
|
||||
isSortable: PropTypes.bool,
|
||||
isBeingSorted: PropTypes.bool,
|
||||
sortDirection: PropTypes.number,
|
||||
onLabelClick: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
const StudyListFilter = ({
|
||||
filtersMeta = [],
|
||||
filtersValues = defaultProps.filtersValues,
|
||||
@@ -107,22 +117,49 @@ const StudyListFilter = ({
|
||||
};
|
||||
|
||||
const clearFilters = () => {
|
||||
const _filterValues = { ...currentFiltersValues };
|
||||
filtersMeta.forEach(filter => {
|
||||
if (_filterValues[filter.name]) {
|
||||
delete _filterValues[filter.name];
|
||||
}
|
||||
});
|
||||
setcurrentFiltersValues(_filterValues);
|
||||
setcurrentFiltersValues(defaultProps.filtersValues);
|
||||
};
|
||||
|
||||
const isFiltering = () => {
|
||||
return filtersMeta.some(filter => {
|
||||
const filterValue = currentFiltersValues[filter.name];
|
||||
return filterValue && filterValue !== '';
|
||||
return Object.keys(currentFiltersValues).some(name => {
|
||||
const filterValue = currentFiltersValues[name];
|
||||
return filterValue !== defaultProps.filtersValues[name];
|
||||
});
|
||||
};
|
||||
|
||||
const renderInput = (inputType, name) => {
|
||||
switch (inputType) {
|
||||
case 'date-range': {
|
||||
return (
|
||||
<div className="relative">
|
||||
<DateRange
|
||||
startDate={currentFiltersValues.startDate}
|
||||
endDate={currentFiltersValues.endDate}
|
||||
onChange={({ startDate, endDate, preset = false }) => {
|
||||
setcurrentFiltersValues(state => ({
|
||||
...state,
|
||||
startDate,
|
||||
endDate,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
default:
|
||||
return (
|
||||
<Input
|
||||
className="border-custom-blue mt-2 bg-black"
|
||||
type="text"
|
||||
containerClassName="mr-2"
|
||||
value={currentFiltersValues[name] || ''}
|
||||
onChange={event => handleFilterValueChange(event, name)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
@@ -203,17 +240,7 @@ const StudyListFilter = ({
|
||||
onLabelClick={() => handleFilterLabelClick(name)}
|
||||
inputType={inputType}
|
||||
>
|
||||
{inputType !== 'none' && (
|
||||
<Input
|
||||
className="border-custom-blue mt-2 bg-black"
|
||||
type="text"
|
||||
containerClassName="mr-2"
|
||||
value={currentFiltersValues[name] || ''}
|
||||
onChange={event =>
|
||||
handleFilterValueChange(event, name)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{inputType !== 'none' && renderInput(inputType, name)}
|
||||
</FilterLabel>
|
||||
</div>
|
||||
);
|
||||
@@ -237,15 +264,19 @@ const StudyListFilter = ({
|
||||
};
|
||||
|
||||
StudyListFilter.propTypes = {
|
||||
filtersMeta: PropTypes.arrayOf({
|
||||
name: PropTypes.string,
|
||||
dsplayName: PropTypes.string,
|
||||
inputType: PropTypes.oneOf(['text', 'select', 'date-range', 'none']),
|
||||
isSortable: PropTypes.bool,
|
||||
gridCol: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
||||
}),
|
||||
filtersMeta: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
name: PropTypes.string,
|
||||
dsplayName: PropTypes.string,
|
||||
inputType: PropTypes.oneOf(['text', 'select', 'date-range', 'none']),
|
||||
isSortable: PropTypes.bool,
|
||||
gridCol: PropTypes.oneOf([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]),
|
||||
})
|
||||
),
|
||||
filtersValues: PropTypes.object,
|
||||
numOfStudies: PropTypes.number,
|
||||
startDate: PropTypes.string,
|
||||
endDate: PropTypes.string,
|
||||
};
|
||||
|
||||
export default StudyListFilter;
|
||||
Reference in new issue
Block a user