-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IA-3628: Change requests: filter use default datasource by default, add advanced filters #1860
base: main
Are you sure you want to change the base?
Changes from all commits
fedba84
bbdee68
e877fbe
dfca861
27924ba
bdfa7f2
c8c4982
bdf7e2a
f154b88
6c72b43
0100ac3
78e2452
1e08b40
a8f2a37
5e51efc
46eac01
da4f083
1139aaf
fd7e331
0616977
52ef6e9
cce736d
9f50992
d506a2a
9e1f1e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import React, { FunctionComponent, useCallback, useMemo } from 'react'; | ||
import { Box, Grid } from '@mui/material'; | ||
import React, { | ||
FunctionComponent, | ||
useCallback, | ||
useEffect, | ||
useMemo, | ||
useState, | ||
} from 'react'; | ||
import { Box, Grid, Typography } from '@mui/material'; | ||
import { useSafeIntl } from 'bluesquare-components'; | ||
import { FilterButton } from '../../../../components/FilterButton'; | ||
import { useFilterState } from '../../../../hooks/useFilterState'; | ||
|
@@ -8,8 +14,6 @@ import { baseUrls } from '../../../../constants/urls'; | |
import MESSAGES from '../messages'; | ||
import { OrgUnitTreeviewModal } from '../../components/TreeView/OrgUnitTreeviewModal'; | ||
import { useGetOrgUnit } from '../../components/TreeView/requests'; | ||
// IA-3641 uncomment when UI has been refactored to limlit size of API call | ||
// import { useGetGroupDropdown } from '../../hooks/requests/useGetGroups'; | ||
import { useGetOrgUnitTypesDropdownOptions } from '../../orgUnitTypes/hooks/useGetOrgUnitTypesDropdownOptions'; | ||
import { DropdownOptions } from '../../../../types/utils'; | ||
import DatesRange from '../../../../components/filters/DatesRange'; | ||
|
@@ -21,23 +25,44 @@ import { useGetProfilesDropdown } from '../../../instances/hooks/useGetProfilesD | |
import { useGetUserRolesDropDown } from '../../../userRoles/hooks/requests/useGetUserRoles'; | ||
import { useGetProjectsDropdownOptions } from '../../../projects/hooks/requests'; | ||
import { usePaymentStatusOptions } from '../hooks/api/useGetPaymentStatusOptions'; | ||
import { useGetGroupDropdown } from '../../hooks/requests/useGetGroups'; | ||
import { useGetDataSources } from '../../hooks/requests/useGetDataSources'; | ||
import { useDefaultSourceVersion } from '../../../dataSources/utils'; | ||
import { useGetVersionLabel } from '../../hooks/useGetVersionLabel'; | ||
|
||
const baseUrl = baseUrls.orgUnitsChangeRequest; | ||
type Props = { params: ApproveOrgUnitParams }; | ||
type Props = { | ||
params: ApproveOrgUnitParams; | ||
selectedVersionId: string; | ||
setSelectedVersionId: (id: string) => void; | ||
dataSource: string; | ||
setDataSource: (id: string) => void; | ||
}; | ||
|
||
const styles = { | ||
advancedSettings: { | ||
color: theme => theme.palette.primary.main, | ||
alignSelf: 'center', | ||
textAlign: 'right', | ||
flex: '1', | ||
cursor: 'pointer', | ||
}, | ||
}; | ||
|
||
export const ReviewOrgUnitChangesFilter: FunctionComponent<Props> = ({ | ||
params, | ||
selectedVersionId, | ||
setSelectedVersionId, | ||
dataSource, | ||
setDataSource, | ||
}) => { | ||
const { formatMessage } = useSafeIntl(); | ||
const defaultSourceVersion = useDefaultSourceVersion(); | ||
|
||
const { filters, handleSearch, handleChange, filtersUpdated } = | ||
useFilterState({ baseUrl, params }); | ||
const { data: dataSources, isFetching: isFetchingDataSources } = | ||
useGetDataSources(true); | ||
const { data: initialOrgUnit } = useGetOrgUnit(params.parent_id); | ||
// IA-3641 hard coding values fro groups dropdown until refactor | ||
// const { data: groupOptions, isLoading: isLoadingGroups } = | ||
// useGetGroupDropdown({}); | ||
const groupOptions = []; | ||
const isLoadingGroups = false; | ||
// IA-3641 -----END | ||
const { data: orgUnitTypeOptions, isLoading: isLoadingTypes } = | ||
useGetOrgUnitTypesDropdownOptions(); | ||
const { data: forms, isFetching: isLoadingForms } = useGetForms(); | ||
|
@@ -49,6 +74,7 @@ export const ReviewOrgUnitChangesFilter: FunctionComponent<Props> = ({ | |
useGetProjectsDropdownOptions(); | ||
const { data: paymentStatuses, isFetching: isFetchingPaymentStatuses } = | ||
usePaymentStatusOptions(); | ||
|
||
const formOptions = useMemo( | ||
() => | ||
forms?.map(form => ({ | ||
|
@@ -57,6 +83,43 @@ export const ReviewOrgUnitChangesFilter: FunctionComponent<Props> = ({ | |
})) || [], | ||
[forms], | ||
); | ||
const initialDataSource = useMemo( | ||
() => | ||
dataSources?.find( | ||
source => | ||
source.value === defaultSourceVersion.source.id.toString(), | ||
)?.value || '', | ||
[dataSources, defaultSourceVersion.source.id], | ||
); | ||
|
||
const [showAdvancedSettings, setShowAdvancedSettings] = useState(false); | ||
const { formatMessage } = useSafeIntl(); | ||
|
||
const { | ||
data: groupOptions, | ||
isLoading: isLoadingGroups, | ||
refetch: refetchGroups, | ||
} = useGetGroupDropdown( | ||
selectedVersionId ? { defaultVersion: selectedVersionId } : {}, | ||
); | ||
|
||
useEffect(() => { | ||
if (selectedVersionId) { | ||
refetchGroups(); | ||
} | ||
}, [selectedVersionId, refetchGroups]); | ||
|
||
Comment on lines
+106
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you don't pass |
||
useEffect(() => { | ||
const updatedDataSource = dataSources?.find( | ||
source => | ||
source.value === defaultSourceVersion.source.id.toString(), | ||
)?.value; | ||
|
||
if (updatedDataSource) { | ||
setDataSource(updatedDataSource as unknown as string); | ||
} | ||
}, [dataSources, defaultSourceVersion.source.id, setDataSource]); | ||
|
||
const statusOptions: DropdownOptions<string>[] = useMemo( | ||
() => [ | ||
{ | ||
|
@@ -82,6 +145,52 @@ export const ReviewOrgUnitChangesFilter: FunctionComponent<Props> = ({ | |
[handleChange], | ||
); | ||
|
||
const handleDataSourceVersionChange = useCallback( | ||
(key, newValue) => { | ||
if (key === 'source') { | ||
setDataSource(newValue); | ||
const selectedSource = dataSources?.filter( | ||
source => source.value === newValue, | ||
)[0]; | ||
setSelectedVersionId( | ||
selectedSource?.original?.default_version.id.toString(), | ||
); | ||
handleChange( | ||
'source_version_id', | ||
selectedSource?.original?.default_version.id, | ||
); | ||
} else { | ||
setSelectedVersionId(newValue.toString()); | ||
handleChange('source_version_id', newValue); | ||
} | ||
Comment on lines
+158
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need additional code here to reset the treeview when changing source/version |
||
filters.groups = []; | ||
}, | ||
[ | ||
dataSources, | ||
filters, | ||
handleChange, | ||
setDataSource, | ||
setSelectedVersionId, | ||
], | ||
); | ||
|
||
const getVersionLabel = useGetVersionLabel(dataSources); | ||
|
||
const versionsDropDown = useMemo(() => { | ||
if (!dataSources || !dataSource) return []; | ||
return ( | ||
dataSources | ||
.filter( | ||
src => (src.value as unknown as string) === dataSource, | ||
)[0] | ||
?.original?.versions.sort((a, b) => a.number - b.number) | ||
.map(version => ({ | ||
label: getVersionLabel(version.id), | ||
value: version.id.toString(), | ||
})) ?? [] | ||
); | ||
}, [dataSource, dataSources, getVersionLabel]); | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid item xs={12} md={4} lg={3}> | ||
|
@@ -117,15 +226,70 @@ export const ReviewOrgUnitChangesFilter: FunctionComponent<Props> = ({ | |
options={groupOptions} | ||
loading={isLoadingGroups} | ||
labelString={formatMessage(MESSAGES.group)} | ||
disabled | ||
helperText={formatMessage(MESSAGES.featureDisabled)} | ||
/> | ||
<Box mt={2}> | ||
{!showAdvancedSettings && ( | ||
<Typography | ||
data-test="advanced-settings" | ||
variant="overline" | ||
sx={styles.advancedSettings} | ||
onClick={() => setShowAdvancedSettings(true)} | ||
> | ||
{formatMessage(MESSAGES.showAdvancedSettings)} | ||
</Typography> | ||
)} | ||
{showAdvancedSettings && ( | ||
<> | ||
<InputComponent | ||
type="select" | ||
disabled={isFetchingDataSources} | ||
keyValue="source" | ||
onChange={handleDataSourceVersionChange} | ||
value={isFetchingDataSources ? '' : dataSource} | ||
label={MESSAGES.source} | ||
options={dataSources} | ||
loading={isFetchingDataSources} | ||
/> | ||
<InputComponent | ||
Comment on lines
+243
to
+252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move this one outside of the advanced settings, so it's the same as in Org Units? |
||
type="select" | ||
disabled={isFetchingDataSources} | ||
keyValue="version" | ||
onChange={handleDataSourceVersionChange} | ||
value={selectedVersionId || ''} | ||
label={MESSAGES.sourceVersion} | ||
options={versionsDropDown} | ||
clearable={false} | ||
loading={isFetchingDataSources} | ||
/> | ||
|
||
<Box ml={1}> | ||
<Typography | ||
data-test="advanced-settings" | ||
variant="overline" | ||
onClick={() => | ||
setShowAdvancedSettings(false) | ||
} | ||
> | ||
{formatMessage( | ||
MESSAGES.hideAdvancedSettings, | ||
)} | ||
</Typography> | ||
</Box> | ||
</> | ||
)} | ||
</Box> | ||
</Grid> | ||
<Grid item xs={12} md={4} lg={3}> | ||
<Box id="ou-tree-input"> | ||
<OrgUnitTreeviewModal | ||
toggleOnLabelClick={false} | ||
titleMessage={MESSAGES.parent} | ||
source={ | ||
dataSource | ||
? dataSource.toString() | ||
: initialDataSource.toString() | ||
} | ||
version={selectedVersionId} | ||
onConfirm={orgUnit => { | ||
handleChange('parent_id', orgUnit?.id); | ||
}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Box } from '@mui/material'; | ||
import { makeStyles } from '@mui/styles'; | ||
import { commonStyles, getTableUrl, useSafeIntl } from 'bluesquare-components'; | ||
import React, { FunctionComponent, useMemo } from 'react'; | ||
import React, { FunctionComponent, useMemo, useState } from 'react'; | ||
import DownloadButtonsComponent from '../../../components/DownloadButtonsComponent'; | ||
import TopBar from '../../../components/nav/TopBarComponent'; | ||
import { ReviewOrgUnitChangesFilter } from './Filter/ReviewOrgUnitChangesFilter'; | ||
|
@@ -11,6 +11,7 @@ import MESSAGES from './messages'; | |
import { ApproveOrgUnitParams } from './types'; | ||
import { useParamsObject } from '../../../routing/hooks/useParamsObject'; | ||
import { baseUrls } from '../../../constants/urls'; | ||
import { useDefaultSourceVersion } from '../../dataSources/utils'; | ||
/* | ||
# Org Unit Change Request | ||
|
||
|
@@ -79,6 +80,7 @@ export const ReviewOrgUnitChanges: FunctionComponent = () => { | |
users: params.userIds, | ||
user_roles: params.userRoles, | ||
with_location: params.withLocation, | ||
source_version_id: params.source_version_id, | ||
}), | ||
[ | ||
params.created_at_after, | ||
|
@@ -87,6 +89,7 @@ export const ReviewOrgUnitChanges: FunctionComponent = () => { | |
params.groups, | ||
params.org_unit_type_id, | ||
params.parent_id, | ||
params.source_version_id, | ||
params.status, | ||
params.userIds, | ||
params.userRoles, | ||
|
@@ -95,12 +98,26 @@ export const ReviewOrgUnitChanges: FunctionComponent = () => { | |
); | ||
|
||
const csv_url = getTableUrl(endPointUrl, csv_params); | ||
const defaultSourceVersion = useDefaultSourceVersion(); | ||
const [selectedVersionId, setSelectedVersionId] = useState<string>( | ||
defaultSourceVersion.version.id.toString(), | ||
); | ||
const [dataSource, setDataSource] = useState<string>( | ||
defaultSourceVersion.source.id.toString(), | ||
); | ||
|
||
params.source_version_id = selectedVersionId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We try to avoid mutating
Comment on lines
+101
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could move all this code to the Filters, since you only pass it as props. You could use a redirection from within the filters instead of mutating the |
||
return ( | ||
<div> | ||
<TopBar title={formatMessage(MESSAGES.reviewChangeProposals)} /> | ||
<Box className={classes.containerFullHeightNoTabPadded}> | ||
<ReviewOrgUnitChangesFilter params={params} /> | ||
<ReviewOrgUnitChangesFilter | ||
params={params} | ||
selectedVersionId={selectedVersionId} | ||
setSelectedVersionId={setSelectedVersionId} | ||
dataSource={dataSource} | ||
setDataSource={setDataSource} | ||
/> | ||
<Box mb={2} display="flex" justifyContent="flex-end"> | ||
<DownloadButtonsComponent csvUrl={csv_url} /> | ||
</Box> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is where the deep linking is broken. You need to check the params for a source version and use it as initial source