diff --git a/.env.template b/.env.template index ea19ce6ac4fa544be1331404692e841bc037339e..73a2e0b807d8916ea524ee1428113b7178a65efe 100644 --- a/.env.template +++ b/.env.template @@ -25,5 +25,4 @@ DATABASE_USER= DATABASE_PASSWORD= DATABASE_NAME= -SGE_API_TOKEN= -MEILI_MASTER_KEY= \ No newline at end of file +SGE_API_TOKEN= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 386cb38220a9cf4f826ed8bf6a7e51e7cf66820e..045845bef0c82d2dc32e4fb2b4f269716b985f7d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,6 @@ .env.development.local .env.test.local .env.production.local -meili_data db_data npm-debug.log* diff --git a/.vscode/settings.json b/.vscode/settings.json index 1adc76b2940150ae9d2131cf287d205b80852562..a434aa05093c22cb873a5b94b9ad57072ba1eeb1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,7 +16,8 @@ "activityBar.activeBackground": "#37cc4e", "sash.hoverBorder": "#37cc4e", "statusBarItem.remoteBackground": "#2aa63d", - "statusBarItem.remoteForeground": "#e7e7e7" + "statusBarItem.remoteForeground": "#e7e7e7", + "commandCenter.border": "#e7e7e799" }, "editor.formatOnSave": true, "eslint.format.enable": true, diff --git a/docker-compose.local.yml b/docker-compose.local.yml index b8fef645296c3b28c3800f4247cc4aa172e4940a..1a357781a4670cb0902fc0650c123ec89e93071c 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -30,20 +30,6 @@ services: timeout: 10s retries: 60 - meilisearch: - image: getmeili/meilisearch:v0.28.1 - healthcheck: - test: ['CMD', 'curl', '-f', 'http://0.0.0.0:7700'] - interval: 10s - timeout: 10s - retries: 3 - volumes: - - ./meili_data:/meili_data - ports: - - 7700:7700 - environment: - - MEILI_MASTER_KEY=${MEILI_MASTER_KEY} - phpmyadmin: image: phpmyadmin/phpmyadmin:latest depends_on: @@ -59,8 +45,6 @@ services: depends_on: database-agent: condition: service_healthy - meilisearch: - condition: service_healthy restart: unless-stopped volumes: - ./mnt:/app/mnt @@ -85,5 +69,3 @@ services: - MOCK_OAUTH2=${MOCK_OAUTH2} - IMAGE_FOLDER=${IMAGE_FOLDER} - SGE_API_TOKEN=${SGE_API_TOKEN} - - MEILI_HOST=http://meilisearch:7700 - - MEILI_MASTER_KEY=${MEILI_MASTER_KEY} diff --git a/src/components/Consents/Consents.tsx b/src/components/Consents/Consents.tsx index 912d35d5353ae603992462a11be60a809d51a007..2bcd007048a11926af2a37375e377bf6d0e36045 100644 --- a/src/components/Consents/Consents.tsx +++ b/src/components/Consents/Consents.tsx @@ -157,23 +157,16 @@ const Consents: React.FC = () => { async (newSearch: string) => { setSearch(newSearch) if (user) { - let consentsData: IConsent[] | null = [] - if (newSearch) { - consentsData = await consentService.searchConsent( - newSearch, - getAxiosXSRFHeader(user.xsrftoken) - ) - } else { - const consentPagination = await consentService.getConsents( - rowsPerPage, - page, - getAxiosXSRFHeader(user.xsrftoken) - ) - consentsData = consentPagination && consentPagination.rows - } - if (consentsData) { - setConsents(consentsData) + const consentPagination = await consentService.searchConsents( + newSearch, + rowsPerPage, + page, + getAxiosXSRFHeader(user.xsrftoken) + ) + if (consentPagination) { + setConsents(consentPagination.rows) checkSelectedNodes() + setTotalRows(consentPagination.totalRows) } } }, @@ -259,25 +252,12 @@ const Consents: React.FC = () => { } }, [gridApi]) + /** Trigger search when page loads or when admin changes pagination */ useEffect(() => { - async function getConsentsData() { - if (user) { - const consentsPaginationData = await consentService.getConsents( - rowsPerPage, - page, - getAxiosXSRFHeader(user.xsrftoken) - ) - if (consentsPaginationData) { - setConsents(consentsPaginationData.rows) - checkSelectedNodes() - setTotalRows(consentsPaginationData.totalRows) - } - } - } - getConsentsData() - // /!\ Do not add checkSelected in dependencies or effect will trigger on each selection + handleSearchChange(search) + // /!\ Do not change dependencies or effect will not trigger when pagination changes // eslint-disable-next-line react-hooks/exhaustive-deps - }, [user, consentService, rowsPerPage, page]) + }, [rowsPerPage, page]) return ( <> @@ -291,8 +271,8 @@ const Consents: React.FC = () => { <input value={search} name="search" - type="text" - placeholder="N°PDL, Nom, Prénom..." + type="number" + placeholder="N°PDL (14 chiffres)" onChange={(e: React.ChangeEvent<HTMLInputElement>) => handleSearchChange(e.target.value) } @@ -320,7 +300,7 @@ const Consents: React.FC = () => { pagination={false} suppressCellFocus={true} ></AgGridReact> - {search === '' && !isShowingSelection && ( + {!isShowingSelection && ( <TablePagination labelRowsPerPage="Consentements par page" component="div" diff --git a/src/services/consent.service.ts b/src/services/consent.service.ts index 94b6c5ab9851f9a6be1e7c50a178a2c7e874ebd6..a474ca4ca533dacedc4aae5cbc76bf2330f81bb9 100644 --- a/src/services/consent.service.ts +++ b/src/services/consent.service.ts @@ -11,46 +11,19 @@ export class ConsentService { /** * Search for consents * @param search - * @param axiosHeaders - */ - public searchConsent = async ( - search: string, - axiosHeaders: AxiosRequestConfig - ): Promise<IConsent[] | null> => { - try { - const { data } = await axios.get( - `/api/admin/consent?search=${search}`, - axiosHeaders - ) - const consentEntities = data as ConsentEntity[] - return consentEntities.map((entity) => this.parseConsent(entity)) - } catch (e: any) { - if (e.response.status === 403) { - toast.error( - "Unauthorized : You don't have the rights to do this operation" - ) - } else { - toast.error('Failed to search consents') - } - console.error(e) - return null - } - } - - /** - * Gets consents * @param limit * @param page * @param axiosHeaders */ - public getConsents = async ( + public searchConsents = async ( + search: string, limit: number, page: number, axiosHeaders: AxiosRequestConfig ): Promise<IConsentPagination | null> => { try { const { data } = await axios.get( - `/api/admin/consent?limit=${limit}&page=${page}`, + `/api/admin/consent?search=${search}&limit=${limit}&page=${page}`, axiosHeaders ) const consentPagination = data as ConsentPaginationEntity