Skip to content

Commit a6a601a

Browse files
committed
fix: allows long argument
1 parent e85d038 commit a6a601a

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

packages/diracx-web-components/src/components/shared/SearchBar/SearchBar.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ export function SearchBar<T extends string>({
104104
SearchBarTokenEquation[]
105105
>([]);
106106

107+
const currentFilters = useRef<string | null>(null);
108+
107109
const [suggestions, setSuggestions] = useState<SearchBarSuggestions>({
108110
items: [],
109111
nature: [],
@@ -127,7 +129,11 @@ export function SearchBar<T extends string>({
127129

128130
// Effect to initialize the token equations from filters
129131
useEffect(() => {
130-
if (tokenEquations.length !== 0) return; // Avoid reloading if already loaded
132+
const newFiltersString = String(
133+
filters.map((filter) => JSON.stringify(filter)),
134+
);
135+
136+
if (currentFilters && currentFilters.current === newFiltersString) return; // Avoid reloading if already loaded
131137

132138
async function load() {
133139
const promises = filters.map(async (filter, filterIndex) =>
@@ -137,14 +143,15 @@ export function SearchBar<T extends string>({
137143
setTokenEquations(newTokenEquations);
138144
}
139145

140-
if (filters.length !== 0 && tokenEquations.length === 0) load();
141-
}, []);
146+
if (filters.length !== 0) load();
147+
currentFilters.current = newFiltersString;
148+
}, [filters, createSuggestions, currentFilters, tokenEquations.length]);
142149

143150
const usesCurrentInput = useMemo(
144151
() => functionUsesCurrentInput(createSuggestions),
145152
[createSuggestions],
146153
);
147-
// Create a list of options based on the current tokens and data
154+
148155
useEffect(() => {
149156
async function load() {
150157
const params: CreateSuggestionsParams = {
@@ -324,15 +331,17 @@ export function SearchBar<T extends string>({
324331
display: "flex",
325332
border: "1px solid",
326333
borderColor: "grey.400",
327-
overflow: "auto",
334+
overflow: "hidden",
328335
borderRadius: 1,
329336
":focus-within": {
330337
borderColor: "primary.main",
331338
},
332339
}}
333340
data-testid="search-bar"
334341
>
335-
<Box sx={{ gap: 1, display: "flex", padding: 1, width: 0.9 }}>
342+
<Box
343+
sx={{ gap: 1, display: "flex", padding: 1, width: 1, overflow: "auto" }}
344+
>
336345
{tokenEquations.map((equation, index) => (
337346
<DisplayTokenEquation
338347
key={index}

packages/diracx-web-components/src/components/shared/SearchBar/SearchField.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ export default function SearchField({
249249
}, 0);
250250
}
251251

252-
// Calculate the width of the input field based on the input value length
253-
const width = Math.min(Math.max(inputValue.length * 8 + 50, 150), 800);
254-
255252
const handleDateAccepted = (newValue: string | null) => {
256253
if (newValue) {
257254
handleTokenCreation(
@@ -289,8 +286,7 @@ export default function SearchField({
289286
sx={{
290287
marginTop: "2px",
291288
minWidth: "180px",
292-
width: "auto",
293-
maxWidth: 0.9,
289+
flexGrow: 1,
294290
}}
295291
disableClearable={true}
296292
options={suggestions.items}
@@ -309,9 +305,6 @@ export default function SearchField({
309305
input: {
310306
...params.InputProps,
311307
disableUnderline: true,
312-
style: {
313-
width: `${width}px`,
314-
},
315308
},
316309
}}
317310
onKeyDown={(e: React.KeyboardEvent<HTMLDivElement>) => {

0 commit comments

Comments
 (0)