Skip to content

Commit df9635f

Browse files
Search bar for circuits (#350)
* Removed the component of search bar and filter options * Reinstate the search function matching the logic of filters --------- Co-authored-by: Loris Olivier <53363974+loris-maru@users.noreply.github.com>
1 parent 5e58c6f commit df9635f

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

src/components/explore-section/Circuit/global/circuit-table.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import DownloadContainer from './download/download-container';
1111
import SubcircuitTable from './subcircuit-table';
1212

1313
import NumericFilters from './numeric-filter';
14+
import SearchBar from './search-bar';
1415

1516
import { classNames } from '@/util/utils';
1617
import styles from './exploreCircuitTable.module.scss';
@@ -28,7 +29,7 @@ export default function CircuitTable({
2829
const [expandedRowKeys, setExpandedRowKeys] = useState<Key[]>([]);
2930

3031
// FILTERING
31-
// const [searchQuery, setSearchQuery] = useState<string>('');
32+
const [searchQuery, setSearchQuery] = useState<string>('');
3233
const [numericFilter, setNumericFilter] = useState<NumericFilterOptions | null>(null);
3334
const [minValue, setMinValue] = useState<number | undefined>(undefined);
3435
const [maxValue, setMaxValue] = useState<number | undefined>(undefined);
@@ -88,6 +89,7 @@ export default function CircuitTable({
8889
numericFilter={numericFilter} // Pass filter props
8990
minValue={minValue}
9091
maxValue={maxValue}
92+
searchQuery={searchQuery}
9193
/>
9294
) : null,
9395
[
@@ -99,14 +101,15 @@ export default function CircuitTable({
99101
numericFilter,
100102
minValue,
101103
maxValue,
104+
searchQuery,
102105
]
103106
);
104107

105108
return (
106109
<div className="relative flex w-full flex-col">
107110
{hasSearch && (
108111
<div className="relative mb-8 flex w-full flex-row justify-between px-8">
109-
{/* <SearchBar searchQuery={searchQuery} onSearchChange={setSearchQuery} /> */}
112+
<SearchBar searchQuery={searchQuery} onSearchChange={setSearchQuery} />
110113
<NumericFilters
111114
filter={numericFilter}
112115
minValue={minValue}
@@ -138,7 +141,7 @@ export default function CircuitTable({
138141
rowExpandable: (record) => !!record.subcircuits && record.subcircuits.length > 0,
139142
}}
140143
rowClassName={(record) =>
141-
circuitMatchFilter(record, numericFilter, minValue, maxValue)
144+
circuitMatchFilter(record, numericFilter, minValue, maxValue, searchQuery)
142145
? styles.matchingRow
143146
: styles.nonMatchingRow
144147
}

src/components/explore-section/Circuit/global/download/download-container.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function DownloadContainer({
7373
) : (
7474
<div className="text-primary-2">Full circuit data is not available.</div>
7575
)}
76-
<div className="my-8 border-y border-solid border-primary-7 py-4 text-base font-bold text-primary-4">
76+
<div className="my-8 border-y border-solid border-primary-7 py-4 text-xl font-bold uppercase tracking-wide text-primary-4">
7777
Download components only
7878
</div>
7979
<div className="flex w-full flex-col gap-y-12">

src/components/explore-section/Circuit/global/subcircuit-table.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type SubcircuitsTableProps = {
1818
numericFilter: NumericFilterOptions | null;
1919
minValue: number | undefined;
2020
maxValue: number | undefined;
21+
searchQuery: string;
2122
};
2223

2324
export default function SubcircuitTable({
@@ -28,6 +29,7 @@ export default function SubcircuitTable({
2829
numericFilter,
2930
minValue,
3031
maxValue,
32+
searchQuery,
3133
}: SubcircuitsTableProps) {
3234
const renderSubcircuits = (subCircuit: CircuitSchemaProps) => (
3335
<SubcircuitTable
@@ -38,6 +40,7 @@ export default function SubcircuitTable({
3840
numericFilter={numericFilter}
3941
minValue={minValue}
4042
maxValue={maxValue}
43+
searchQuery={searchQuery}
4144
/>
4245
);
4346

@@ -62,7 +65,7 @@ export default function SubcircuitTable({
6265
rowExpandable: (record) => !!record.subcircuits && record.subcircuits.length > 0,
6366
}}
6467
rowClassName={(record) =>
65-
circuitMatchFilter(record, numericFilter, minValue, maxValue)
68+
circuitMatchFilter(record, numericFilter, minValue, maxValue, searchQuery)
6669
? styles.matchingRow
6770
: styles.nonMatchingRow
6871
}

src/components/explore-section/Circuit/utils/circuits-match-filter.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,42 @@ export function circuitMatchFilter(
44
circuit: CircuitSchemaProps,
55
filter: NumericFilterOptions | null,
66
minValue: number | undefined,
7-
maxValue: number | undefined
7+
maxValue: number | undefined,
8+
searchQuery: string
89
): boolean {
9-
if (!filter) return true;
10+
let numericMatch = true;
1011

11-
const { property, type } = filter;
12-
const value = circuit[property] as number;
12+
if (filter) {
13+
const { property, type } = filter;
14+
const value = circuit[property];
1315

14-
if (type === 'greaterThan' && minValue !== undefined) {
15-
return value > minValue;
16+
if (typeof value !== 'number' || Number.isNaN(value)) {
17+
numericMatch = false;
18+
} else {
19+
if (type === 'greaterThan' && minValue !== undefined) {
20+
numericMatch = value > minValue;
21+
}
22+
if (type === 'lessThan' && maxValue !== undefined) {
23+
numericMatch = value < maxValue;
24+
}
25+
if (type === 'between' && minValue !== undefined && maxValue !== undefined) {
26+
numericMatch = value >= minValue && value <= maxValue;
27+
}
28+
}
1629
}
17-
if (type === 'lessThan' && maxValue !== undefined) {
18-
return value < maxValue;
19-
}
20-
if (type === 'between' && minValue !== undefined && maxValue !== undefined) {
21-
return value >= minValue && value <= maxValue;
30+
31+
let searchMatch = true;
32+
if (searchQuery.trim()) {
33+
const query = searchQuery.toLowerCase().trim();
34+
35+
searchMatch =
36+
circuit.name?.toLowerCase().includes(query) ||
37+
false ||
38+
circuit.brainRegion?.toLowerCase().includes(query) ||
39+
false ||
40+
circuit.description?.toLowerCase().includes(query) ||
41+
false;
2242
}
2343

24-
return true;
44+
return numericMatch && searchMatch;
2545
}

0 commit comments

Comments
 (0)