-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
IA-2871 mappings add filters
- Loading branch information
Showing
11 changed files
with
390 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
hat/assets/js/apps/Iaso/domains/mappings/components/Filter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import React, { useState, FunctionComponent, useCallback } from 'react'; | ||
|
||
import { Grid, Button, Box, useMediaQuery, useTheme } from '@mui/material'; | ||
import { makeStyles } from '@mui/styles'; | ||
import SearchIcon from '@mui/icons-material/Search'; | ||
import { useSafeIntl } from 'bluesquare-components'; | ||
|
||
import InputComponent from '../../../components/forms/InputComponent'; | ||
import { useFilterState } from '../../../hooks/useFilterState'; | ||
import { mappingTypeOptions } from './MappingTypeOptions'; | ||
|
||
import MESSAGES from '../messages'; | ||
|
||
import { baseUrl } from '../config'; | ||
import { useGetFormsDropdownOptions } from '../hooks/requests/useGetFormsDropdownOptions'; | ||
import { useGetProjectsDropdownOptions } from '../../projects/hooks/requests'; | ||
import { useGetOrgUnitTypes } from '../../orgUnits/hooks/requests/useGetOrgUnitTypes'; | ||
|
||
const useStyles = makeStyles(theme => ({})); | ||
|
||
type Params = { | ||
pageSize: string; | ||
order: string; | ||
page: string; | ||
search?: string; | ||
formId?: string; | ||
mappingType?: string; | ||
projectsIds?: string; | ||
}; | ||
|
||
type Props = { | ||
params: Params; | ||
}; | ||
|
||
const Filters: FunctionComponent<Props> = ({ params }) => { | ||
const classes: Record<string, string> = useStyles(); | ||
const { formatMessage } = useSafeIntl(); | ||
const { filters, handleSearch, handleChange, filtersUpdated } = | ||
useFilterState({ baseUrl, params, withPagination: false }); | ||
const [textSearchError, setTextSearchError] = useState<boolean>(false); | ||
const { data: orgUnitTypes, isFetching: isFetchingOuTypes } = | ||
useGetOrgUnitTypes(); | ||
const { data: allProjects, isFetching: isFetchingProjects } = | ||
useGetProjectsDropdownOptions(); | ||
|
||
const { data: allForms, isFetching: isFetchingForms } = | ||
useGetFormsDropdownOptions({}); | ||
|
||
const theme = useTheme(); | ||
const isLargeLayout = useMediaQuery(theme.breakpoints.up('md')); | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid item xs={12} md={3}> | ||
<InputComponent | ||
keyValue="search" | ||
onChange={handleChange} | ||
value={filters.search} | ||
type="search" | ||
label={MESSAGES.search} | ||
blockForbiddenChars | ||
onEnterPressed={handleSearch} | ||
onErrorChange={setTextSearchError} | ||
/> | ||
</Grid> | ||
|
||
<Grid item xs={12} md={3}> | ||
<InputComponent | ||
keyValue="formId" | ||
onChange={handleChange} | ||
value={filters.formId} | ||
type="select" | ||
options={allForms ?? []} | ||
label={MESSAGES.forms} | ||
loading={isFetchingForms} | ||
onEnterPressed={handleSearch} | ||
clearable | ||
multi | ||
/> | ||
</Grid> | ||
|
||
<Grid item xs={12} md={3}> | ||
<InputComponent | ||
type="select" | ||
onChange={handleChange} | ||
keyValue="mappingTypes" | ||
multi | ||
label={MESSAGES.mappingType} | ||
value={filters.mappingTypes} | ||
loading={false} | ||
options={mappingTypeOptions ?? []} | ||
/> | ||
</Grid> | ||
|
||
<Grid item xs={12} md={3}> | ||
<InputComponent | ||
type="select" | ||
onChange={handleChange} | ||
keyValue="orgUnitTypeIds" | ||
multi | ||
label={MESSAGES.orgUnitsTypes} | ||
value={filters.orgUnitTypeIds} | ||
loading={isFetchingOuTypes} | ||
options={orgUnitTypes ?? []} | ||
/> | ||
</Grid> | ||
<Grid item xs={12} md={3}> | ||
<InputComponent | ||
keyValue="projectsIds" | ||
onChange={handleChange} | ||
value={filters.projectsIds} | ||
type="select" | ||
options={allProjects} | ||
label={MESSAGES.projects} | ||
loading={isFetchingProjects} | ||
onEnterPressed={handleSearch} | ||
clearable | ||
multi | ||
/> | ||
</Grid> | ||
|
||
<Grid container item xs={12} md={12} justifyContent="flex-end"> | ||
<Box mt={isLargeLayout ? 3 : 0}> | ||
<Button | ||
data-test="search-button" | ||
disabled={ | ||
(!filtersUpdated) || textSearchError | ||
} | ||
variant="contained" | ||
className={classes.button} | ||
color="primary" | ||
onClick={() => handleSearch()} | ||
> | ||
<SearchIcon className={classes.buttonIcon} /> | ||
{formatMessage(MESSAGES.search)} | ||
</Button> | ||
</Box> | ||
</Grid> | ||
</Grid> | ||
); | ||
}; | ||
|
||
export { Filters }; |
18 changes: 18 additions & 0 deletions
18
hat/assets/js/apps/Iaso/domains/mappings/components/MappingTypeOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import MESSAGES from '../messages'; | ||
|
||
export const mappingTypeOptions = [ | ||
{ | ||
value: 'AGGREGATE', | ||
label: MESSAGES.aggregate, | ||
}, | ||
{ | ||
value: 'EVENT', | ||
label: MESSAGES.event, | ||
}, | ||
{ | ||
value: 'EVENT_TRACKER', | ||
label: MESSAGES.eventTracker, | ||
}, | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
hat/assets/js/apps/Iaso/domains/mappings/hooks/requests/useGetFormsDropdownOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { UseQueryResult } from 'react-query'; | ||
import { getRequest } from '../../../../libs/Api'; | ||
import { useSnackQuery } from '../../../../libs/apiHooks'; | ||
import { Form } from '../../../forms/types/forms'; | ||
import { useApiParams } from '../../../../hooks/useApiParams'; | ||
|
||
const getForms = params => { | ||
const queryString = new URLSearchParams(params).toString(); | ||
return getRequest(`/api/forms/?${queryString}`).then((value) => { | ||
return value.forms.map(f => { | ||
return { | ||
value: f.id, | ||
label: f.name | ||
} | ||
}) | ||
}); | ||
}; | ||
|
||
export const tableDefaults = { | ||
order: 'updated_at', | ||
limit: 50, | ||
page: 1, | ||
}; | ||
|
||
type ValueLabel = { | ||
value: string; | ||
label: string; | ||
}; | ||
export const useGetFormsDropdownOptions = ( | ||
params, | ||
defaults = tableDefaults, | ||
): UseQueryResult<ValueLabel[], Error> => { | ||
const safeParams = useApiParams(params, defaults); | ||
if (safeParams?.accountId) { | ||
delete safeParams.accountId; | ||
} | ||
return useSnackQuery({ | ||
queryKey: ['form', 'options', safeParams], | ||
queryFn: () => getForms({ ...safeParams }), | ||
options: { | ||
staleTime: 60000, | ||
cacheTime: 60000, | ||
keepPreviousData: true, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.