Skip to content

Commit

Permalink
front: handle accents in STDCM vias autocomplete
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Valais <leo.valais97@gmail.com>
  • Loading branch information
leovalais committed Oct 15, 2024
1 parent 3de9229 commit 1f3cac3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import nextId from 'react-id-generator';
import type { SearchResultItemOperationalPoint } from 'common/api/osrdEditoastApi';
import useSearchOperationalPoint from 'common/Map/Search/useSearchOperationalPoint';
import type { PathStep } from 'reducers/osrdconf/types';
import { normalized } from 'utils/strings';
import { createFixedSelectOptions } from 'utils/uiCoreHelpers';

type StdcmOperationalPointProps = {
Expand Down Expand Up @@ -39,7 +40,7 @@ const StdcmOperationalPoint = ({
sortedSearchResults
.filter(
(op) =>
op.name.toLowerCase().startsWith(searchTerm.toLowerCase()) ||
normalized(op.name).startsWith(normalized(searchTerm)) ||
op.trigram === searchTerm.toUpperCase()
)
.reduce((acc, p) => {
Expand Down
14 changes: 14 additions & 0 deletions front/src/utils/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ export function formatUicToCi(uic: number) {
return uic.toString().replace(/^87/, '');
}

/**
* Normalizes a string by removing accents and converting to lowercase.
*
* Accent removal is done using `String.normalize` which converts accented characters to their
* decomposed form (e.g. é -> e + ´). We then remove all characters in the range of U+0300 to U+036f
* which contains all unicode combining diacritical marks (https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
*/
export function normalized(s: string): string {
return s
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '');
}

export const TEXT_AREA_MAX_LENGTH = 4096;
export const SMALL_TEXT_AREA_MAX_LENGTH = 1024;
export const TEXT_INPUT_MAX_LENGTH = 255;
Expand Down

0 comments on commit 1f3cac3

Please sign in to comment.