Skip to content

Commit e433439

Browse files
committed
fix: adapt search bar to review comments
1 parent 62e48a4 commit e433439

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export function DisplayTokenEquation({
7171
key={tokenIndex}
7272
label={chipLabel}
7373
color={chipColor}
74-
size="small"
7574
onClick={(e) => handleClick(e, tokenIndex)}
7675
onDelete={isLast ? handleDelete : undefined}
7776
id={`tokenid:equation-${equationIndex}-token-${tokenIndex}`}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ export function SearchBar<T extends string>({
471471
disabled={
472472
!tokenEquations.every((eq) => eq.status === EquationStatus.VALID)
473473
}
474-
size="small"
475474
>
476475
<RefreshIcon />
477476
</IconButton>
@@ -482,7 +481,6 @@ export function SearchBar<T extends string>({
482481
setInputValue("");
483482
clearFunction(setFilters, setTokenEquations);
484483
}}
485-
size="small"
486484
>
487485
<DeleteIcon />
488486
</IconButton>

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
convertListToString,
2727
} from "./Utils";
2828

29-
import "dayjs/locale/en-gb"; // Import the locale for dayjs
30-
3129
import { MyDateTimePicker } from "./DatePicker";
3230

3331
/** Merge multiple React refs into a single callback ref. */
@@ -39,7 +37,7 @@ function mergeRefs<T>(
3937
if (typeof ref === "function") {
4038
ref(node);
4139
} else if (ref && typeof ref === "object") {
42-
(ref as React.MutableRefObject<T | null>).current = node;
40+
(ref as React.RefObject<T | null>).current = node;
4341
}
4442
}
4543
};
@@ -278,12 +276,15 @@ export default function SearchField({
278276

279277
function handleBackspaceKeyDown() {
280278
if (inputValue === "" && tokenEquations.length > 0) {
281-
const updatedTokens = [...tokenEquations];
282-
const lastEquation = updatedTokens[updatedTokens.length - 1];
279+
const lastEquation = tokenEquations[tokenEquations.length - 1];
280+
let updatedTokens: SearchBarTokenEquation[];
283281
if (lastEquation.items.length > 1) {
284-
lastEquation.items = lastEquation.items.slice(0, -1);
282+
updatedTokens = [
283+
...tokenEquations.slice(0, -1),
284+
{ ...lastEquation, items: lastEquation.items.slice(0, -1) },
285+
];
285286
} else {
286-
updatedTokens.pop();
287+
updatedTokens = tokenEquations.slice(0, -1);
287288
}
288289
handleEquationsVerification(updatedTokens, setTokenEquations);
289290
setFocusedTokenIndex(null);
@@ -295,13 +296,14 @@ export default function SearchField({
295296

296297
/** Submit the current input value as a new token. */
297298
function handleSubmit() {
298-
if (inputValue && inputValue.trim()) {
299+
const trimmed = inputValue.trim();
300+
if (trimmed) {
299301
const { nature, type } = getTokenMetadata(
300-
inputValue.trim(),
302+
trimmed,
301303
suggestions,
302304
previousToken,
303305
);
304-
handleTokenCreation(inputValue.trim(), nature, type);
306+
handleTokenCreation(trimmed, nature, type);
305307
}
306308
}
307309

@@ -350,7 +352,7 @@ export default function SearchField({
350352
optionSelectedRef.current = option !== null;
351353
}}
352354
onKeyDown={(e: React.KeyboardEvent<HTMLDivElement>) => {
353-
if (e.key === "Enter" && inputValue && inputValue.trim()) {
355+
if (e.key === "Enter" && inputValue.trim()) {
354356
if (optionSelectedRef.current) {
355357
optionSelectedRef.current = false;
356358
return;

0 commit comments

Comments
 (0)