Skip to content
Snippets Groups Projects
Commit e37ea25f authored by Rémi PAILHAREY's avatar Rémi PAILHAREY :fork_knife_plate:
Browse files

Merge branch 'backoffice-moteur-de-recherche-a-simplifier' into 'dev'

Backoffice moteur de recherche a simplifier

See merge request !85
parents 63e06105 88ac10f2
No related branches found
No related tags found
4 merge requests!96Deploy OpenShift v2,!95MEP fix liens undefined,!91MEP: removed Meilisearch,!85Backoffice moteur de recherche a simplifier
Pipeline #52504 passed
...@@ -25,5 +25,4 @@ DATABASE_USER= ...@@ -25,5 +25,4 @@ DATABASE_USER=
DATABASE_PASSWORD= DATABASE_PASSWORD=
DATABASE_NAME= DATABASE_NAME=
SGE_API_TOKEN= SGE_API_TOKEN=
MEILI_MASTER_KEY= \ No newline at end of file
\ No newline at end of file
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
.env.development.local .env.development.local
.env.test.local .env.test.local
.env.production.local .env.production.local
meili_data
db_data db_data
npm-debug.log* npm-debug.log*
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"activityBar.activeBackground": "#37cc4e", "activityBar.activeBackground": "#37cc4e",
"sash.hoverBorder": "#37cc4e", "sash.hoverBorder": "#37cc4e",
"statusBarItem.remoteBackground": "#2aa63d", "statusBarItem.remoteBackground": "#2aa63d",
"statusBarItem.remoteForeground": "#e7e7e7" "statusBarItem.remoteForeground": "#e7e7e7",
"commandCenter.border": "#e7e7e799"
}, },
"editor.formatOnSave": true, "editor.formatOnSave": true,
"eslint.format.enable": true, "eslint.format.enable": true,
......
...@@ -30,20 +30,6 @@ services: ...@@ -30,20 +30,6 @@ services:
timeout: 10s timeout: 10s
retries: 60 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: phpmyadmin:
image: phpmyadmin/phpmyadmin:latest image: phpmyadmin/phpmyadmin:latest
depends_on: depends_on:
...@@ -59,8 +45,6 @@ services: ...@@ -59,8 +45,6 @@ services:
depends_on: depends_on:
database-agent: database-agent:
condition: service_healthy condition: service_healthy
meilisearch:
condition: service_healthy
restart: unless-stopped restart: unless-stopped
volumes: volumes:
- ./mnt:/app/mnt - ./mnt:/app/mnt
...@@ -85,5 +69,3 @@ services: ...@@ -85,5 +69,3 @@ services:
- MOCK_OAUTH2=${MOCK_OAUTH2} - MOCK_OAUTH2=${MOCK_OAUTH2}
- IMAGE_FOLDER=${IMAGE_FOLDER} - IMAGE_FOLDER=${IMAGE_FOLDER}
- SGE_API_TOKEN=${SGE_API_TOKEN} - SGE_API_TOKEN=${SGE_API_TOKEN}
- MEILI_HOST=http://meilisearch:7700
- MEILI_MASTER_KEY=${MEILI_MASTER_KEY}
...@@ -157,23 +157,16 @@ const Consents: React.FC = () => { ...@@ -157,23 +157,16 @@ const Consents: React.FC = () => {
async (newSearch: string) => { async (newSearch: string) => {
setSearch(newSearch) setSearch(newSearch)
if (user) { if (user) {
let consentsData: IConsent[] | null = [] const consentPagination = await consentService.searchConsents(
if (newSearch) { newSearch,
consentsData = await consentService.searchConsent( rowsPerPage,
newSearch, page,
getAxiosXSRFHeader(user.xsrftoken) getAxiosXSRFHeader(user.xsrftoken)
) )
} else { if (consentPagination) {
const consentPagination = await consentService.getConsents( setConsents(consentPagination.rows)
rowsPerPage,
page,
getAxiosXSRFHeader(user.xsrftoken)
)
consentsData = consentPagination && consentPagination.rows
}
if (consentsData) {
setConsents(consentsData)
checkSelectedNodes() checkSelectedNodes()
setTotalRows(consentPagination.totalRows)
} }
} }
}, },
...@@ -259,25 +252,12 @@ const Consents: React.FC = () => { ...@@ -259,25 +252,12 @@ const Consents: React.FC = () => {
} }
}, [gridApi]) }, [gridApi])
/** Trigger search when page loads or when admin changes pagination */
useEffect(() => { useEffect(() => {
async function getConsentsData() { handleSearchChange(search)
if (user) { // /!\ Do not change dependencies or effect will not trigger when pagination changes
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
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [user, consentService, rowsPerPage, page]) }, [rowsPerPage, page])
return ( return (
<> <>
...@@ -291,8 +271,8 @@ const Consents: React.FC = () => { ...@@ -291,8 +271,8 @@ const Consents: React.FC = () => {
<input <input
value={search} value={search}
name="search" name="search"
type="text" type="number"
placeholder="N°PDL, Nom, Prénom..." placeholder="N°PDL (14 chiffres)"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
handleSearchChange(e.target.value) handleSearchChange(e.target.value)
} }
...@@ -320,7 +300,7 @@ const Consents: React.FC = () => { ...@@ -320,7 +300,7 @@ const Consents: React.FC = () => {
pagination={false} pagination={false}
suppressCellFocus={true} suppressCellFocus={true}
></AgGridReact> ></AgGridReact>
{search === '' && !isShowingSelection && ( {!isShowingSelection && (
<TablePagination <TablePagination
labelRowsPerPage="Consentements par page" labelRowsPerPage="Consentements par page"
component="div" component="div"
......
...@@ -11,46 +11,19 @@ export class ConsentService { ...@@ -11,46 +11,19 @@ export class ConsentService {
/** /**
* Search for consents * Search for consents
* @param search * @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 limit
* @param page * @param page
* @param axiosHeaders * @param axiosHeaders
*/ */
public getConsents = async ( public searchConsents = async (
search: string,
limit: number, limit: number,
page: number, page: number,
axiosHeaders: AxiosRequestConfig axiosHeaders: AxiosRequestConfig
): Promise<IConsentPagination | null> => { ): Promise<IConsentPagination | null> => {
try { try {
const { data } = await axios.get( const { data } = await axios.get(
`/api/admin/consent?limit=${limit}&page=${page}`, `/api/admin/consent?search=${search}&limit=${limit}&page=${page}`,
axiosHeaders axiosHeaders
) )
const consentPagination = data as ConsentPaginationEntity const consentPagination = data as ConsentPaginationEntity
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment