mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
[Bugfix] fix filter change with select component and scroll options with multiple filters (#4404)
* fixes: selecting colum filter with react-select component * add scrolling for multiple filters * handles chaning * updates: exposed variables
This commit is contained in:
parent
544f6c403f
commit
ba178a131a
1 changed files with 41 additions and 22 deletions
|
|
@ -14,10 +14,11 @@ export function Filter(props) {
|
||||||
|
|
||||||
const [activeFilters, set] = React.useState(filters);
|
const [activeFilters, set] = React.useState(filters);
|
||||||
|
|
||||||
function filterColumnChanged(index, value, name) {
|
function filterColumnChanged(index, value) {
|
||||||
|
const filter = props.columns.find((column) => column.value === value);
|
||||||
const newFilters = filters;
|
const newFilters = filters;
|
||||||
newFilters[index].id = value;
|
newFilters[index].id = filter.value;
|
||||||
newFilters[index].value.where = name;
|
newFilters[index].value.column = filter.name;
|
||||||
mergeToFilterDetails({
|
mergeToFilterDetails({
|
||||||
filters: newFilters,
|
filters: newFilters,
|
||||||
});
|
});
|
||||||
|
|
@ -28,8 +29,14 @@ export function Filter(props) {
|
||||||
const newFilters = filters;
|
const newFilters = filters;
|
||||||
newFilters[index].value = {
|
newFilters[index].value = {
|
||||||
...newFilters[index].value,
|
...newFilters[index].value,
|
||||||
operation: value,
|
condition: value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//* if condition is "is empty" or "is not empty" then clear the filter query value
|
||||||
|
if (value === 'isEmpty' || value === 'isNotEmpty') {
|
||||||
|
newFilters[index].value.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
mergeToFilterDetails({
|
mergeToFilterDetails({
|
||||||
filters: newFilters,
|
filters: newFilters,
|
||||||
});
|
});
|
||||||
|
|
@ -49,7 +56,7 @@ export function Filter(props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFilter() {
|
function addFilter() {
|
||||||
mergeToFilterDetails({ filters: [...filters, { id: '', value: { operation: 'contains', value: '' } }] });
|
mergeToFilterDetails({ filters: [...filters, { id: '', value: { condition: 'contains', value: '' } }] });
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFilter(index) {
|
function removeFilter(index) {
|
||||||
|
|
@ -114,20 +121,24 @@ export function Filter(props) {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div
|
||||||
|
style={{
|
||||||
|
overflowY: 'auto',
|
||||||
|
overflowX: 'hidden',
|
||||||
|
}}
|
||||||
|
className="card-body"
|
||||||
|
>
|
||||||
{props.filters.map((filter, index) => (
|
{props.filters.map((filter, index) => (
|
||||||
<div className="row mb-2" key={index}>
|
<div className="row mb-2" key={index}>
|
||||||
<div className="col p-2" style={{ maxWidth: '70px' }}>
|
<div className="col p-2" style={{ maxWidth: '70px' }}>
|
||||||
<small>{index > 0 ? 'and' : 'where'}</small>
|
<small>{index > 0 ? 'and' : 'column'}</small>
|
||||||
</div>
|
</div>
|
||||||
<div className="col">
|
<div className="col">
|
||||||
<Select
|
<Select
|
||||||
options={props.columns}
|
options={props.columns}
|
||||||
value={filter.id}
|
value={filter.id}
|
||||||
search={true}
|
search={true}
|
||||||
onChange={(value, item) => {
|
onChange={(value) => filterColumnChanged(index, value)}
|
||||||
filterColumnChanged(index, value, item.name);
|
|
||||||
}}
|
|
||||||
placeholder={t('globals.select', 'Select') + '...'}
|
placeholder={t('globals.select', 'Select') + '...'}
|
||||||
styles={selectStyles('100%')}
|
styles={selectStyles('100%')}
|
||||||
/>
|
/>
|
||||||
|
|
@ -148,7 +159,7 @@ export function Filter(props) {
|
||||||
{ name: 'greater than or equals', value: 'gte' },
|
{ name: 'greater than or equals', value: 'gte' },
|
||||||
{ name: 'less than or equals', value: 'lte' },
|
{ name: 'less than or equals', value: 'lte' },
|
||||||
]}
|
]}
|
||||||
value={filter.value.operation}
|
value={filter.value.condition}
|
||||||
search={true}
|
search={true}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
filterOperationChanged(index, value);
|
filterOperationChanged(index, value);
|
||||||
|
|
@ -158,7 +169,7 @@ export function Filter(props) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col">
|
<div className="col">
|
||||||
{['isEmpty', 'isNotEmpty'].includes(filter.value.operation) || (
|
{['isEmpty', 'isNotEmpty'].includes(filter.value.condition) || (
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={filter.value.value}
|
value={filter.value.value}
|
||||||
|
|
@ -202,16 +213,16 @@ const findFilterDiff = (oldFilters, newFilters) => {
|
||||||
const filterDiff = deepDiff(oldFilters, newFilters);
|
const filterDiff = deepDiff(oldFilters, newFilters);
|
||||||
|
|
||||||
const getType = (obj) => {
|
const getType = (obj) => {
|
||||||
if (!obj?.where && !obj?.operation) {
|
if (!obj?.column && !obj?.condition) {
|
||||||
return 'value';
|
return 'value';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj?.where) {
|
if (obj?.column) {
|
||||||
return 'where';
|
return 'column';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj?.operation) {
|
if (obj?.condition) {
|
||||||
return 'operation';
|
return 'condition';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -226,15 +237,23 @@ const findFilterDiff = (oldFilters, newFilters) => {
|
||||||
function shouldFireEvent(diff, filter) {
|
function shouldFireEvent(diff, filter) {
|
||||||
if (!diff || !filter) return false;
|
if (!diff || !filter) return false;
|
||||||
|
|
||||||
|
function forEmptyOperationAndNotEmptyOperation(condition) {
|
||||||
|
if (condition !== 'isEmpty' || condition !== 'isNotEmpty') {
|
||||||
|
return filter[diff.keyIndex]?.value?.column ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filter[diff.keyIndex]?.value?.value && filter[diff.keyIndex]?.value?.column ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (diff.type) {
|
switch (diff.type) {
|
||||||
case 'value':
|
case 'value':
|
||||||
return filter[diff.keyIndex].value.where && filter[diff.keyIndex].value.operation ? true : false;
|
return filter[diff.keyIndex]?.value?.column && filter[diff.keyIndex]?.value?.condition ? true : false;
|
||||||
|
|
||||||
case 'where':
|
case 'column':
|
||||||
return filter[diff.keyIndex].value.value && filter[diff.keyIndex].value.operation ? true : false;
|
return filter[diff.keyIndex]?.value?.value && filter[diff.keyIndex]?.value?.condition ? true : false;
|
||||||
|
|
||||||
case 'operation':
|
case 'condition':
|
||||||
return filter[diff.keyIndex].value.value && filter[diff.keyIndex].value.where ? true : false;
|
return forEmptyOperationAndNotEmptyOperation(filter[diff.keyIndex]?.value?.condition);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue