Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ yarn-error.log
testem.log
/typings
.env
/.nx

# System Files
.DS_Store
Expand Down
43 changes: 24 additions & 19 deletions src/components/SearchApp/SearchBar/SearchInputAdvanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ export function SearchInputAdvanced({
Criteria | undefined
>(undefined);
const [selectedOption, setSelectedOption] = useState<DropdownOptions | null>(
null,
null
);
const [inputType, setInputType] = useState<string>('text');
const [operatorValue, setOperatorValue] = useState<string | null>('LIKE');
const handlePropertyOptionClick = (
selected: DropdownOptions | null,
selected: DropdownOptions | null
): void => {
setSelectedOption(selected);
if (criteria && selected) {
const selectedProperties = criteria.find(
(e: Criteria) => e.property === selected.value,
(e: Criteria) => e.property === selected.value
);
setSelectedIndexProperties(selectedProperties);

Expand All @@ -79,7 +79,7 @@ export function SearchInputAdvanced({

const disabled = (operator: string): boolean => {
const isOperator = selectedIndexProperties?.operator.find(
(e: string) => e === operator,
(e: string) => e === operator
);
if (!isOperator) {
return true;
Expand All @@ -90,15 +90,15 @@ export function SearchInputAdvanced({
const handleAddChip = (
newOperator: string,
newProperty: string,
value: string,
value: string
): void => {
const filters = produce<(state: Filter[]) => Filter[]>((draft) => {
if (
!draft.some(
(filterOptions: Filter) =>
filterOptions.value === value &&
filterOptions.operator === newOperator &&
filterOptions.property === newProperty,
filterOptions.property === newProperty
)
) {
draft.push({
Expand All @@ -109,21 +109,26 @@ export function SearchInputAdvanced({
}
});

const updateIndexAttributes = filter(
data,
(item: string) => item !== selectedOption?.value,
);
const isDateProperty = newProperty.toLowerCase().includes('date');

if (!isDateProperty) {
const updateIndexAttributes = filter(
data,
(item: string) => item !== selectedOption?.value
);
onReducedIndexAttributes(updateIndexAttributes);
} else {
onReducedIndexAttributes(data);
}
onSetSelectFilters(filters);
onReducedIndexAttributes(updateIndexAttributes);
};

const addFilter = (): void => {
if (operatorValue && searchValue && selectedIndexProperties) {
handleAddChip(
operatorValue,
selectedIndexProperties.property,
searchValue,
searchValue
);

setSelectedIndexProperties(undefined);
Expand All @@ -142,7 +147,7 @@ export function SearchInputAdvanced({
return (
<Col
xs={{ span: 12, offset: 0 }}
className="p-0 m-0 d-flex justify-content-between"
className='p-0 m-0 d-flex justify-content-between'
>
<SelectWithAutocomplete
options={stringToLoadOptions(data)}
Expand All @@ -159,10 +164,10 @@ export function SearchInputAdvanced({
onClick={onOperatorClick}
disabled={disabled}
/>
<Row className="m-0 bg-white border border-middle rounded-lg p-0">
<Col xs={{ span: 10, offset: 0 }} className="px-1">
<Row className='m-0 bg-white border border-middle rounded-lg p-0'>
<Col xs={{ span: 10, offset: 0 }} className='px-1'>
<Form.Control
className="h-100 border border-white p-0 m-0 shadow-none"
className='h-100 border border-white p-0 m-0 shadow-none'
type={inputType}
value={searchValue}
onChange={(e) => onSetSearchValue(e.target.value)}
Expand All @@ -171,14 +176,14 @@ export function SearchInputAdvanced({
</Col>
<Col
xs={{ span: 1, offset: 0 }}
className="p-0 m-0 d-flex align-items-center"
className='p-0 m-0 d-flex align-items-center'
>
{operatorValue && selectedIndexProperties && searchValue && (
<Icon
icon={BsPlus}
size={28}
color="text-primary"
type="button"
color='text-primary'
type='button'
onClick={addFilter}
/>
)}
Expand Down