implement ComboPaysSearch
This commit is contained in:
parent
0012fd3aa5
commit
12d1a5bece
6 changed files with 884 additions and 7 deletions
21
app/javascript/components/ComboPaysSearch.js
Normal file
21
app/javascript/components/ComboPaysSearch.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import React from 'react';
|
||||
import { ReactQueryCacheProvider } from 'react-query';
|
||||
|
||||
import ComboSearch from './ComboSearch';
|
||||
import { queryCache } from './shared/queryCache';
|
||||
|
||||
function ComboPaysSearch(params) {
|
||||
return (
|
||||
<ReactQueryCacheProvider queryCache={queryCache}>
|
||||
<ComboSearch
|
||||
required={params.mandatory}
|
||||
hiddenFieldId={params.hiddenFieldId}
|
||||
scope="pays"
|
||||
minimumInputLength={0}
|
||||
transformResult={({ nom }) => [nom, nom]}
|
||||
/>
|
||||
</ReactQueryCacheProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default ComboPaysSearch;
|
|
@ -1,5 +1,6 @@
|
|||
import { QueryCache } from 'react-query';
|
||||
import { isNumeric } from '@utils';
|
||||
import matchSorter from 'match-sorter';
|
||||
|
||||
const { api_geo_url, api_adresse_url } = gon.autocomplete || {};
|
||||
|
||||
|
@ -31,6 +32,11 @@ function buildOptions() {
|
|||
}
|
||||
|
||||
async function defaultQueryFn(scope, term) {
|
||||
if (scope == 'pays') {
|
||||
const pays = await fetch('/pays.json').then((response) => response.json());
|
||||
return matchSorter(pays, term, { keys: ['nom'] });
|
||||
}
|
||||
|
||||
const url = buildURL(scope, term);
|
||||
const [options, controller] = buildOptions();
|
||||
const promise = fetch(url, options).then((response) => response.json());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue