diff --git a/hat/assets/js/apps/Iaso/constants/urls.ts b/hat/assets/js/apps/Iaso/constants/urls.ts index c15d5e70dd..380d940956 100644 --- a/hat/assets/js/apps/Iaso/constants/urls.ts +++ b/hat/assets/js/apps/Iaso/constants/urls.ts @@ -22,6 +22,7 @@ const orgUnitDetailsLinkParams = [ ]; export const FORMS_PREFIX = 'formsParams'; export const LINKS_PREFIX = 'linksParams'; +export const LOGS_PREFIX = 'logsParams'; export const CHANGE_REQUEST = 'changeRequest'; const ORG_UNITS = 'orgunits'; @@ -141,7 +142,7 @@ export const baseRouteConfigs: Record = { ...orgUnitDetailsLinkParams, ...paginationPathParamsWithPrefix(LINKS_PREFIX), ...paginationPathParamsWithPrefix(FORMS_PREFIX), - ...paginationPathParamsWithPrefix('logsParams'), + ...paginationPathParamsWithPrefix(LOGS_PREFIX), ], }, orgUnitsChangeRequest: { diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/components/AddNewEmptyVersion.tsx b/hat/assets/js/apps/Iaso/domains/dataSources/components/AddNewEmptyVersion.tsx index ba2fa87cd9..05c83a4611 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/components/AddNewEmptyVersion.tsx +++ b/hat/assets/js/apps/Iaso/domains/dataSources/components/AddNewEmptyVersion.tsx @@ -10,13 +10,11 @@ type Props = { // eslint-disable-next-line no-unused-vars renderTrigger: ({ openDialog }: { openDialog: any }) => ReactNode; sourceId: number; - forceRefreshParent: () => void; }; export const AddNewEmptyVersion: FunctionComponent = ({ renderTrigger, sourceId, - forceRefreshParent, }) => { // eslint-disable-next-line no-unused-vars const [description, setDescription] = useState(''); @@ -35,7 +33,6 @@ export const AddNewEmptyVersion: FunctionComponent = ({ await createSourceVersion(body); closeDialogCallBack(); reset(); - forceRefreshParent(); }; const onConfirm = async (closeDialog: () => void) => { diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/components/DataSourceDialogComponent.js b/hat/assets/js/apps/Iaso/domains/dataSources/components/DataSourceDialogComponent.js index 2ed811d321..ee5afa10f1 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/components/DataSourceDialogComponent.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/components/DataSourceDialogComponent.js @@ -7,7 +7,7 @@ import { merge } from 'lodash'; import { FormattedMessage } from 'react-intl'; import { useGetProjectsDropdownOptions } from '../../projects/hooks/requests.ts'; import ConfirmCancelDialogComponent from '../../../components/dialogs/ConfirmCancelDialogComponent'; -import InputComponent from '../../../components/forms/InputComponent'; +import InputComponent from '../../../components/forms/InputComponent.tsx'; import MESSAGES from '../messages'; import { commaSeparatedIdsToArray } from '../../../utils/forms'; import { useFormState } from '../../../hooks/form'; @@ -109,7 +109,6 @@ const formIsValid = form => { export const DataSourceDialogComponent = ({ defaultSourceVersion, initialData, - onSuccess, renderTrigger, sourceCredentials, }) => { @@ -123,8 +122,6 @@ export const DataSourceDialogComponent = ({ const onConfirm = async closeDialog => { await saveDataSource(form); - // Notify parents to refetch. Remove if porting parent to react-query - onSuccess(); closeDialog(); }; @@ -314,7 +311,6 @@ DataSourceDialogComponent.defaultProps = { sourceCredentials: {}, }; DataSourceDialogComponent.propTypes = { - onSuccess: PropTypes.func.isRequired, initialData: PropTypes.object, renderTrigger: PropTypes.func.isRequired, defaultSourceVersion: PropTypes.object, diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/components/EditSourceVersion.tsx b/hat/assets/js/apps/Iaso/domains/dataSources/components/EditSourceVersion.tsx index 677cf533e4..b581dd6500 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/components/EditSourceVersion.tsx +++ b/hat/assets/js/apps/Iaso/domains/dataSources/components/EditSourceVersion.tsx @@ -14,7 +14,6 @@ type Props = { description: string | null; dataSourceId: number; sourceVersionNumber: number; - forceRefreshParent: () => void; }; const renderTrigger = ({ openDialog }) => ( @@ -30,7 +29,6 @@ export const EditSourceVersion: FunctionComponent = ({ description, sourceVersionNumber, dataSourceId, - forceRefreshParent, }) => { const { formatMessage } = useSafeIntl(); const [updatedDescription, setUpdatedDescription] = useState( @@ -50,11 +48,9 @@ export const EditSourceVersion: FunctionComponent = ({ sourceVersionNumber, }); closeDialog(); - forceRefreshParent(); }, [ dataSourceId, - forceRefreshParent, sourceVersionId, sourceVersionNumber, updateSourceVersion, diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/components/VersionsDialog.js b/hat/assets/js/apps/Iaso/domains/dataSources/components/VersionsDialog.js index f669550b7d..21ebb6a6b9 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/components/VersionsDialog.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/components/VersionsDialog.js @@ -1,35 +1,23 @@ /* eslint-disable react/jsx-props-no-spreading */ import React, { useState, useMemo, useCallback } from 'react'; import PropTypes from 'prop-types'; -import { - Button, - DialogActions, - Grid, - Tooltip, - Typography, -} from '@mui/material'; +import { Button, DialogActions, Grid, Typography } from '@mui/material'; import { makeStyles } from '@mui/styles'; import Public from '@mui/icons-material/Public'; -import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import AddBox from '@mui/icons-material/AddBoxOutlined'; import { FormattedMessage } from 'react-intl'; import { commonStyles, DHIS2Svg, - IconButton as IconButtonComponent, Table, useSafeIntl, } from 'bluesquare-components'; -// import 'react-table'; -import { CopySourceVersion } from './CopySourceVersion/CopySourceVersion.tsx'; - import DialogComponent from '../../../components/dialogs/DialogComponent'; import MESSAGES from '../messages'; import { AddTask } from './AddTaskComponent'; import { ImportGeoPkgDialog } from './ImportGeoPkgDialog'; import { AddNewEmptyVersion } from './AddNewEmptyVersion.tsx'; -import { DateTimeCell } from '../../../components/Cells/DateTimeCell.tsx'; -import { EditSourceVersion } from './EditSourceVersion.tsx'; + import { getSortedSourceVersions, handleSort, @@ -37,6 +25,7 @@ import { getTableParams, getTablePages, } from '../utils'; +import { useVersionsDialogTableColumns } from '../hooks/useVersionsDialogTableColumns.tsx'; const useStyles = makeStyles(theme => ({ spanStyle: { @@ -45,130 +34,7 @@ const useStyles = makeStyles(theme => ({ ...commonStyles(theme), })); -const tableColumns = (source, forceRefreshParent) => [ - { - Header: , - accessor: 'id', - sortable: false, - Cell: settings => - source.default_version?.id === settings.value && ( - } - > - - - ), - }, - { - Header: ( - - ), - sortable: true, - accessor: 'number', - }, - { - Header: ( - - ), - accessor: 'created_at', - sortable: false, - Cell: DateTimeCell, - }, - { - Header: ( - - ), - accessor: 'updated_at', - sortable: false, - Cell: DateTimeCell, - }, - { - Header: ( - - ), - accessor: 'org_units_count', - }, - { - Header: ( - - ), - accessor: 'description', - sortable: false, - }, - { - Header: ( - - ), - accessor: 'actions', - sortable: false, - width: 200, - Cell: settings => { - return source.read_only ? ( - - ) : ( - <> - - ( - - )} - sourceId={source.id} - sourceVersionNumber={settings.row.original.number} - sourceCredentials={source.credentials ?? {}} - /> - ( - - )} - sourceId={source.id} - sourceName={source.name} - versionNumber={settings.row.original.number} - projects={source.projects.flat()} - /> - - - ); - }, - }, -]; - -const VersionsDialog = ({ renderTrigger, source, forceRefreshParent }) => { +const VersionsDialog = ({ renderTrigger, source }) => { const { spanStyle, ...classes } = useStyles(); const [page, setPage] = useState(0); const [rowsPerPage, setRowsPerPage] = useState(10); @@ -180,6 +46,8 @@ const VersionsDialog = ({ renderTrigger, source, forceRefreshParent }) => { ); const { formatMessage } = useSafeIntl(); + const columns = useVersionsDialogTableColumns(source); + const formatDataForTable = useCallback( (tableData, sortFunc) => tableData @@ -241,17 +109,14 @@ const VersionsDialog = ({ renderTrigger, source, forceRefreshParent }) => { renderActions={({ closeDialog }) => ( )} > { )} sourceId={source.id} - forceRefreshParent={forceRefreshParent} /> @@ -329,7 +193,6 @@ VersionsDialog.propTypes = { credentials: PropTypes.object, projects: PropTypes.array.isRequired, }).isRequired, - forceRefreshParent: PropTypes.func.isRequired, }; VersionsDialog.defaultProps = {}; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/config.js b/hat/assets/js/apps/Iaso/domains/dataSources/config.js index 8b39fcf94b..a8e708568f 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/config.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/config.js @@ -14,16 +14,12 @@ import MESSAGES from './messages'; import { VersionsDialog } from './components/VersionsDialog'; import { YesNoCell } from '../../components/Cells/YesNoCell'; import { ExportToDHIS2Dialog } from './components/ExportToDHIS2Dialog'; -import { useCurrentUser } from '../../utils/usersUtils.ts'; -import { userHasPermission } from '../users/utils'; -import { baseUrls } from '../../constants/urls'; +import { baseUrls } from '../../constants/urls.ts'; import { DateTimeCell } from '../../components/Cells/DateTimeCell.tsx'; import * as Permission from '../../utils/permissions.ts'; +import { DisplayIfUserHasPerm } from '../../components/DisplayIfUserHasPerm.tsx'; -export const useDataSourcesTableColumns = ( - setForceRefresh, - defaultSourceVersion, -) => { +export const useDataSourcesTableColumns = defaultSourceVersion => { const { formatMessage } = useSafeIntl(); return useMemo( () => [ @@ -63,7 +59,6 @@ export const useDataSourcesTableColumns = ( resizable: false, sortable: false, Cell: settings => { - const currentUser = useCurrentUser(); return (
- {userHasPermission( - Permission.SOURCE_WRITE, - currentUser, - ) && ( - <> - ( - - )} - initialData={{ - ...settings.row.original, - projects: - settings.row.original.projects.flat(), - }} - defaultSourceVersion={ - defaultSourceVersion - } - key={settings.row.original.updated_at} - onSuccess={() => setForceRefresh(true)} - sourceCredentials={ - settings.row.original.credentials - ? settings.row.original - .credentials - : {} - } - /> - ( - - )} - defaultSourceVersion={ - defaultSourceVersion - } - source={settings.row.original} - forceRefreshParent={() => - setForceRefresh(true) - } - /> - ( - - )} - dataSourceName={ - settings.row.original.name - } - dataSourceId={settings.row.original.id} - versions={ - settings.row.original.versions - } - defaultVersionId={ - settings.row.original - ?.default_version?.id - } - /> - - )} + + + ( + + )} + initialData={{ + ...settings.row.original, + projects: + settings.row.original.projects.flat(), + }} + defaultSourceVersion={defaultSourceVersion} + key={settings.row.original.updated_at} + sourceCredentials={ + settings.row.original.credentials + ? settings.row.original.credentials + : {} + } + /> + ( + + )} + defaultSourceVersion={defaultSourceVersion} + source={settings.row.original} + /> + ( + + )} + dataSourceName={settings.row.original.name} + dataSourceId={settings.row.original.id} + versions={settings.row.original.versions} + defaultVersionId={ + settings.row.original?.default_version + ?.id + } + /> +
); }, }, ], - [defaultSourceVersion, formatMessage, setForceRefresh], + [defaultSourceVersion, formatMessage], ); }; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/details.tsx b/hat/assets/js/apps/Iaso/domains/dataSources/details.tsx index c81f5dc257..8e3609f851 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/details.tsx +++ b/hat/assets/js/apps/Iaso/domains/dataSources/details.tsx @@ -15,7 +15,7 @@ import { Box, Grid, Typography } from '@mui/material'; import { makeStyles } from '@mui/styles'; import TopBar from '../../components/nav/TopBarComponent'; import MESSAGES from './messages'; -import { useGetDataSource } from './hooks/useGetDataSources'; +import { useGetDataSource } from './hooks/useGetDataSource'; import { DataSource } from './types/dataSources'; import { DataSourceInfo } from './components/DataSourceInfo'; import WidgetPaper from '../../components/papers/WidgetPaperComponent'; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/hooks/useGetDataSources.ts b/hat/assets/js/apps/Iaso/domains/dataSources/hooks/useGetDataSource.ts similarity index 100% rename from hat/assets/js/apps/Iaso/domains/dataSources/hooks/useGetDataSources.ts rename to hat/assets/js/apps/Iaso/domains/dataSources/hooks/useGetDataSource.ts diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/hooks/useVersionsDialogTableColumns.tsx b/hat/assets/js/apps/Iaso/domains/dataSources/hooks/useVersionsDialogTableColumns.tsx new file mode 100644 index 0000000000..1d5635bde2 --- /dev/null +++ b/hat/assets/js/apps/Iaso/domains/dataSources/hooks/useVersionsDialogTableColumns.tsx @@ -0,0 +1,132 @@ +import React, { useMemo } from 'react'; +import { Column, IconButton, useSafeIntl } from 'bluesquare-components'; +import { Tooltip } from '@mui/material'; +import CheckCircleIcon from '@mui/icons-material/CheckCircle'; +import MESSAGES from '../messages'; +import { EditSourceVersion } from '../components/EditSourceVersion'; +import { AddTask } from '../components/AddTaskComponent'; +import { CopySourceVersion } from '../components/CopySourceVersion/CopySourceVersion'; +import { ImportGeoPkgDialog } from '../components/ImportGeoPkgDialog'; +import { DateTimeCell } from '../../../components/Cells/DateTimeCell'; + +export const useVersionsDialogTableColumns = (source): Column[] => { + const { formatMessage } = useSafeIntl(); + return useMemo( + () => [ + { + Header: formatMessage(MESSAGES.defaultVersion), + accessor: 'id', + sortable: false, + Cell: settings => { + return ( + <> + {source.default_version?.id === settings.value && ( + + + + )} + + ); + }, + }, + { + Header: formatMessage(MESSAGES.number), + sortable: true, + accessor: 'number', + }, + { + Header: formatMessage(MESSAGES.createdAt), + accessor: 'created_at', + sortable: false, + Cell: DateTimeCell, + }, + { + Header: formatMessage(MESSAGES.updatedAt), + accessor: 'updated_at', + sortable: false, + Cell: DateTimeCell, + }, + { + Header: formatMessage(MESSAGES.orgUnits), + accessor: 'org_units_count', + }, + { + Header: formatMessage(MESSAGES.description), + accessor: 'description', + sortable: false, + }, + { + Header: formatMessage(MESSAGES.actions), + accessor: 'actions', + sortable: false, + width: 200, + Cell: settings => { + if (source.read_only) { + return {formatMessage(MESSAGES.readOnly)}; + } + return ( + <> + + ( + + )} + sourceId={source.id} + sourceVersionNumber={ + settings.row.original.number + } + sourceCredentials={source.credentials ?? {}} + /> + ( + + )} + sourceId={source.id} + sourceName={source.name} + versionNumber={settings.row.original.number} + projects={source.projects.flat()} + /> + + + ); + }, + }, + ], + [ + formatMessage, + source.credentials, + source.default_version?.id, + source.id, + source.name, + source.projects, + source.read_only, + ], + ); +}; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/index.js b/hat/assets/js/apps/Iaso/domains/dataSources/index.js index 52c54bc5cf..b0d1637340 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/index.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/index.js @@ -1,81 +1,58 @@ -import React, { useState } from 'react'; -import { useDispatch } from 'react-redux'; -import { - AddButton as AddButtonComponent, - useSafeIntl, -} from 'bluesquare-components'; - +import React from 'react'; +import { AddButton, useSafeIntl } from 'bluesquare-components'; import TopBar from '../../components/nav/TopBarComponent'; - import { ErrorBoundary } from './components/ErrorBoundary'; -import { fetchAllDataSources } from '../../utils/requests'; -import { getDefaultSourceVersion } from './utils'; - -import SingleTable from '../../components/tables/SingleTable'; +import { useDefaultSourceVersion } from './utils'; import { DataSourceDialogComponent } from './components/DataSourceDialogComponent'; - -import { baseUrls } from '../../constants/urls'; -import { toggleSidebarMenu } from '../../redux/sidebarMenuReducer'; - +import { baseUrls } from '../../constants/urls.ts'; import { useDataSourcesTableColumns } from './config'; - +import { SOURCE_WRITE } from '../../utils/permissions.ts'; import MESSAGES from './messages'; -import { useCurrentUser } from '../../utils/usersUtils.ts'; - -import { userHasPermission } from '../users/utils'; - -import * as Permission from '../../utils/permissions.ts'; +import { DisplayIfUserHasPerm } from '../../components/DisplayIfUserHasPerm.tsx'; +import { TableWithDeepLink } from '../../components/tables/TableWithDeepLink.tsx'; +import { useParamsObject } from '../../routing/hooks/useParamsObject.tsx'; +import { useGetDataSources } from './useGetDataSources.ts'; const baseUrl = baseUrls.sources; const defaultOrder = 'name'; + const DataSources = () => { - const [forceRefresh, setForceRefresh] = useState(false); - const currentUser = useCurrentUser(); - const dispatch = useDispatch(); + const params = useParamsObject(baseUrl); const { formatMessage } = useSafeIntl(); - const defaultSourceVersion = getDefaultSourceVersion(currentUser); - const columns = useDataSourcesTableColumns( - setForceRefresh, - defaultSourceVersion, - ); + const defaultSourceVersion = useDefaultSourceVersion(); + const columns = useDataSourcesTableColumns(defaultSourceVersion); + const { data, isFetching: loading } = useGetDataSources(params); - const dataSourceDialog = () => { - if (userHasPermission(Permission.SOURCE_WRITE, currentUser)) { - return ( - ( - - )} - onSuccess={() => setForceRefresh(true)} - /> - ); - } - return ''; - }; return ( <> dispatch(toggleSidebarMenu())} /> - + ( + + )} + /> + + setForceRefresh(false)} - extraComponent={dataSourceDialog()} + defaultSorted={[{ id: defaultOrder, desc: false }]} + extraProps={{ + defaultPageSize: data?.limit ?? 20, + loading, + }} /> diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/messages.js b/hat/assets/js/apps/Iaso/domains/dataSources/messages.js index 813875e4b0..05357d3538 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/messages.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/messages.js @@ -384,6 +384,30 @@ const MESSAGES = defineMessages({ id: 'iaso.orgUnits.closingDate', defaultMessage: 'Closing date', }, + number: { + id: 'iaso.versionsDialog.label.number', + defaultMessage: 'Number', + }, + createdAt: { + id: 'iaso.versionsDialog.label.createdAt', + defaultMessage: 'Created', + }, + updatedAt: { + id: 'iaso.versionsDialog.label.updatedAt', + defaultMessage: 'Updated', + }, + description: { + id: 'iaso.versionsDialog.label.description', + defaultMessage: 'Description', + }, + orgUnits: { + id: 'iaso.label.orgUnit', + defaultMessage: 'Org units', + }, + readOnly: { + id: 'iaso.dataSources.dataSourceReadOnly', + defaultMessage: 'Read Only', + }, }); export default MESSAGES; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/requests.js b/hat/assets/js/apps/Iaso/domains/dataSources/requests.js index f9c72bebb1..66740fd971 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/requests.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/requests.js @@ -1,8 +1,13 @@ /* eslint-disable no-else-return */ import React from 'react'; -import { useMutation } from 'react-query'; +import { useMutation, useQueryClient } from 'react-query'; import { useDispatch, useSelector } from 'react-redux'; -import { getRequest, iasoFetch, postRequest, putRequest } from 'Iaso/libs/Api'; +import { + getRequest, + iasoFetch, + postRequest, + putRequest, +} from 'Iaso/libs/Api.ts'; import { useSnackMutation, useSnackQuery } from 'Iaso/libs/apiHooks.ts'; import { dispatch as storeDispatch } from '../../redux/store'; import { enqueueSnackbar } from '../../redux/snackBarsReducer'; @@ -170,6 +175,7 @@ export const useSaveDataSource = setFieldErrors => { const [isSaving, setIsSaving] = React.useState(false); const currentUser = useSelector(state => state.users.current); const dispatch = useDispatch(); + const queryClient = useQueryClient(); const { mutateAsync: saveMutation } = useSnackMutation( campaignData => @@ -199,6 +205,7 @@ export const useSaveDataSource = setFieldErrors => { } else { await createMutation(campaignData); } + queryClient.invalidateQueries('sources'); } catch (error) { // Update error on forms if (error.status === 400) { @@ -329,7 +336,7 @@ export const useCreateSourceVersion = () => { mutationFn: saveSourceVersion, snackErrorMsg: MESSAGES.newEmptyVersionError, snackSuccessMessage: MESSAGES.newEmptyVersionSavedSuccess, - invalidateQueryKey: 'dataSourceVersions', + invalidateQueryKey: ['dataSourceVersions', 'sources'], }); }; @@ -358,6 +365,6 @@ export const usePutSourceVersion = () => { }), undefined, undefined, - [['dataSourceVersions'], ['dataSources']], + [['dataSourceVersions'], ['dataSources'], ['sources']], ); }; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/useGetDataSources.ts b/hat/assets/js/apps/Iaso/domains/dataSources/useGetDataSources.ts new file mode 100644 index 0000000000..f99abc52a2 --- /dev/null +++ b/hat/assets/js/apps/Iaso/domains/dataSources/useGetDataSources.ts @@ -0,0 +1,29 @@ +import { UseQueryResult } from 'react-query'; +import { useApiParams } from '../../hooks/useApiParams'; +import { getRequest } from '../../libs/Api'; +import { useSnackQuery } from '../../libs/apiHooks'; + +const apiUrl = '/api/datasources'; +const tableDefaults = { + order: 'name', + page: 1, + limit: 20, +}; + +export const useGetDataSources = ( + params: Record, +): UseQueryResult => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { accountId, ...tableParams } = params; + const apiParams = useApiParams(tableParams, tableDefaults); + const queryString = new URLSearchParams(apiParams).toString(); + return useSnackQuery({ + queryKey: ['sources', queryString], + queryFn: () => getRequest(`${apiUrl}/?${queryString}`), + options: { + keepPreviousData: true, + staleTime: 60000, + cacheTime: 60000, + }, + }); +}; diff --git a/hat/assets/js/apps/Iaso/domains/dataSources/utils.js b/hat/assets/js/apps/Iaso/domains/dataSources/utils.js index 5171f61548..8535a6d297 100644 --- a/hat/assets/js/apps/Iaso/domains/dataSources/utils.js +++ b/hat/assets/js/apps/Iaso/domains/dataSources/utils.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import { useSafeIntl } from 'bluesquare-components'; import { Chip } from '@mui/material'; import { @@ -6,6 +6,7 @@ import { CheckCircleOutlineOutlined as CheckedIcon, } from '@mui/icons-material'; import MESSAGES from './messages'; +import { useCurrentUser } from '../../utils/usersUtils.ts'; /** * get the first defaultSource and defaultVersion of an user account @@ -32,6 +33,14 @@ export const getDefaultSourceVersion = user => { } return sourceVersion; }; + +export const useDefaultSourceVersion = () => { + const user = useCurrentUser(); + return useMemo(() => { + return getDefaultSourceVersion(user); + }, [user]); +}; + export const FIELDS_TO_EXPORT = { name: 'name', parent: 'parent', diff --git a/hat/assets/js/apps/Iaso/domains/periods/components/PeriodPicker.tsx b/hat/assets/js/apps/Iaso/domains/periods/components/PeriodPicker.tsx index 0533291d7f..decf79bddc 100644 --- a/hat/assets/js/apps/Iaso/domains/periods/components/PeriodPicker.tsx +++ b/hat/assets/js/apps/Iaso/domains/periods/components/PeriodPicker.tsx @@ -69,6 +69,7 @@ const useStyles = makeStyles(theme => ({ type Props = { periodType: string | Record; title: string; + // eslint-disable-next-line no-unused-vars onChange: (_) => any; activePeriodString?: string; hasError?: boolean; diff --git a/hat/assets/js/apps/Iaso/utils/requests.js b/hat/assets/js/apps/Iaso/utils/requests.js index 555b402488..f183ee71fd 100644 --- a/hat/assets/js/apps/Iaso/utils/requests.js +++ b/hat/assets/js/apps/Iaso/utils/requests.js @@ -49,21 +49,6 @@ export const fetchOrgUnitsList = (dispatch, url) => console.error('Error while fetching org unit list:', error); }); -export const fetchAllDataSources = (dispatch, url) => { - return getRequest(url) - .then(data => { - return data; - }) - .catch(error => { - dispatch( - enqueueSnackbar( - errorSnackBar('fetchDataSourcesError', null, error), - ), - ); - console.error('Error while fetching data sources list:', error); - }); -}; - export const fetchAssociatedOrgUnits = ( dispatch, source,