Skip to content

Commit 6bb573f

Browse files
authored
Merge pull request #5380 from 3drepo/ISSUE_5371
ISSUE #5371 - Ticket filters: boolean filters
2 parents 8fa75e4 + 74b4dd4 commit 6bb573f

File tree

6 files changed

+49
-1
lines changed

6 files changed

+49
-1
lines changed

frontend/src/v5/ui/components/viewer/cards/cardFilters/cardFilters.helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export const getValidOperators = (type: CardFilterType): CardFilterOperator[] =>
8282
if (isTextType(type)) return ['eq', 'neq', 'ss', 'nss', 'ex', 'nex'];
8383
if (type === 'number') return ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'rng', 'nrng', 'ex', 'nex'];
8484
if (isDateType(type)) return ['eq', 'lte', 'gte', 'rng', 'nrng', 'ex', 'nex'];
85+
if (type === 'boolean') return ['eq', 'ex', 'nex'];
8586
if (isSelectType(type)) {
8687
if (type === 'template') return ['eq', 'neq'];
8788
return ['eq', 'neq', 'ex', 'nex'];

frontend/src/v5/ui/components/viewer/cards/cardFilters/filterChip/filterChip.component.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { FormattedMessage } from 'react-intl';
2323
import { CardFilterType, BaseFilter, CardFilterOperator, CardFilterValue } from '../cardFilters.types';
2424
import { formatSimpleDate } from '@/v5/helpers/intl.helper';
2525
import { formatMessage } from '@/v5/services/intl';
26+
import { isBoolean } from 'lodash';
27+
import { FALSE_LABEL, TRUE_LABEL } from '@controls/inputs/booleanSelect/booleanSelect.component';
2628

2729
const valueToDisplayDate = (value) => formatSimpleDate(new Date(value));
2830
const formatDateRange = ([from, to]) => formatMessage(
@@ -33,6 +35,7 @@ const formatDateRange = ([from, to]) => formatMessage(
3335
const getDisplayValue = (values: CardFilterValue[], operator: CardFilterOperator, type: CardFilterType) => {
3436
const isRange = isRangeOperator(operator);
3537
if (isDateType(type)) return values.map(isRange ? formatDateRange : valueToDisplayDate);
38+
if (type === 'boolean' && isBoolean(values[0])) return values[0] ? TRUE_LABEL : FALSE_LABEL;
3639
return (isRange ? values.map(([a, b]: any) => `[${a}, ${b}]`) : values).join(', ') ?? '';
3740
};
3841

frontend/src/v5/ui/components/viewer/cards/cardFilters/filterForm/filterFormValues/filterFormValues.component.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { useFieldArray, useFormContext } from 'react-hook-form';
1919
import { getOperatorMaxFieldsAllowed } from '../filterForm.helpers';
2020
import { isRangeOperator, isTextType, isSelectType, isDateType } from '../../cardFilters.helpers';
21-
import { FormNumberField, FormTextField, FormMultiSelect, FormDateTime } from '@controls/inputs/formInputs.component';
21+
import { FormBooleanSelect, FormMultiSelect, FormDateTime, FormNumberField, FormTextField } from '@controls/inputs/formInputs.component';
2222
import { ArrayFieldContainer } from '@controls/inputs/arrayFieldContainer/arrayFieldContainer.component';
2323
import { useEffect } from 'react';
2424
import { compact, isArray, isEmpty } from 'lodash';
@@ -135,6 +135,8 @@ export const FilterFormValues = ({ module, property, type }: FilterFolrmValuesTy
135135
);
136136
}
137137

138+
if (type === 'boolean') return (<FormBooleanSelect name={`${name}.0.value`} />);
139+
138140
return (
139141
<>
140142
type not created yet: {type}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright (C) 2025 3D Repo Ltd
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, either version 3 of the
7+
* License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
import { formatMessage } from '@/v5/services/intl';
19+
import { Select, SelectProps } from '../select/select.component';
20+
import { MenuItem } from '@mui/material';
21+
import { isBoolean } from 'lodash';
22+
23+
export const TRUE_LABEL = formatMessage({ id: 'select.booleanValue.true', defaultMessage: 'True' });
24+
export const FALSE_LABEL = formatMessage({ id: 'select.booleanValue.false', defaultMessage: 'False' });
25+
26+
export type BooleanSelectProps = Omit<SelectProps, 'children'>;
27+
export const BooleanSelect = (props: BooleanSelectProps) => {
28+
const renderValue = (value) => {
29+
if (!isBoolean(value)) return '';
30+
return value ? TRUE_LABEL : FALSE_LABEL;
31+
};
32+
33+
return (
34+
<Select renderValue={renderValue} {...props}>
35+
<MenuItem value={true as any}>{TRUE_LABEL}</MenuItem>
36+
<MenuItem value={false as any}>{FALSE_LABEL}</MenuItem>
37+
</Select>
38+
);
39+
};

frontend/src/v5/ui/controls/inputs/formInputs.component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { TextArea, TextAreaProps } from './textArea/textArea.component';
2929
import { TextAreaFixedSize, TextAreaFixedSizeProps } from './textArea/textAreaFixedSize.component';
3030
import { TextField, TextFieldProps } from './textField/textField.component';
3131
import { DateTimePicker, DateTimePickerProps } from './datePicker/dateTimePicker.component';
32+
import { BooleanSelect, BooleanSelectProps } from './booleanSelect/booleanSelect.component';
3233
import { MultiSelect } from './multiSelect/multiSelect.component';
3334

3435
// text inputs
@@ -48,6 +49,7 @@ export const FormSelect = (props: InputControllerProps<SelectProps>) => (<InputC
4849
export const FormMultiSelect = (props: InputControllerProps<SelectProps>) => (<InputController Input={MultiSelect} {...props} />);
4950
export const FormChipSelect = (props: InputControllerProps<ChipSelectProps>) => (<InputController Input={({ inputRef, ...chipProps }: any) => <ChipSelect {...chipProps} />} {...props} />);
5051
export const FormSearchSelect = (props: InputControllerProps<SelectProps>) => (<InputController Input={SearchSelect} {...props} />);
52+
export const FormBooleanSelect = (props: InputControllerProps<BooleanSelectProps>) => (<InputController Input={BooleanSelect} {...props} />);
5153

5254
// control inputs
5355
export const FormCheckbox = (props: InputControllerProps<CheckboxProps>) => (<InputController Input={({ error, helperText, ...checkboxProps }: any) => <Checkbox {...checkboxProps} />} {...props} />);

frontend/src/v5/validation/ticketSchemes/validators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const getValueValidator = (type: CardFilterType) => {
3737
);
3838
}
3939
if (isDateType(type) || type === 'number') return requiredNumber();
40+
if (type === 'boolean') return Yup.bool().required(ERROR_REQUIRED_FIELD_MESSAGE);
4041
return trimmedString;
4142
};
4243

0 commit comments

Comments
 (0)