Skip to content

Commit

Permalink
Merge pull request #5734 from beyondessential/master
Browse files Browse the repository at this point in the history
merge: release-2024-25 master -> dev
  • Loading branch information
avaek authored Jun 19, 2024
2 parents e2e210d + 1ecff74 commit 92bb784
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 40 deletions.
1 change: 1 addition & 0 deletions packages/admin-panel/src/api/TupaiaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { saveAs } from 'file-saver';
import { parse } from 'content-disposition-header';
import { logout } from '../authentication';

import { verifyResponseStatus, stringifyQuery } from '@tupaia/utils';

Expand Down
1 change: 0 additions & 1 deletion packages/admin-panel/src/api/mutations/useLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useLogin = homeLink => {
{
onSuccess: async () => {
await queryClient.invalidateQueries();
console.log(from, homeLink);
if (from) {
navigate(from, {
state: null,
Expand Down
3 changes: 2 additions & 1 deletion packages/admin-panel/src/api/mutations/useLogout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import { useMutation, useQueryClient } from 'react-query';
import { post } from '../../VizBuilderApp/api';

export const useLogout = () => {
export const useLogout = onSuccess => {
const queryClient = useQueryClient();

return useMutation('logout', () => post('logout'), {
onSuccess: () => {
queryClient.invalidateQueries();
if (onSuccess) onSuccess();
},
});
};
6 changes: 3 additions & 3 deletions packages/admin-panel/src/authentication/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import { LOGOUT } from './constants';

// workaround for resetting redux state on logout, until we move everything to react-query and hooks
export const logout = dispatch => {
dispatch({ type: LOGOUT });
};
export const logout = () => ({
type: LOGOUT,
});
17 changes: 13 additions & 4 deletions packages/admin-panel/src/layout/navigation/TopNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/
import React from 'react';
import { connect } from 'react-redux';
import styled from 'styled-components';
import PropTypes from 'prop-types';
import { UserButton } from './UserButton';
import { HomeLink } from './HomeLink';
import { useUser } from '../../api/queries';
import { useLogout } from '../../api/mutations';
import { logout as logoutAction } from '../../authentication';

const Wrapper = styled.div`
background-color: ${props => props.theme.palette.secondary.main};
Expand All @@ -28,9 +30,9 @@ const Wrapper = styled.div`
}
`;

export const TopNavbar = ({ logo, homeLink, displayLogoutButton, disableHomeLink }) => {
const TopNavbarComponent = ({ logo, homeLink, displayLogoutButton, disableHomeLink, onLogout }) => {
const { isLoggedIn } = useUser();
const { mutate: logout } = useLogout();
const { mutate: logout } = useLogout(onLogout);
return (
<Wrapper>
<HomeLink logo={logo} homeLink={homeLink} disableHomeLink={disableHomeLink} />
Expand All @@ -39,17 +41,18 @@ export const TopNavbar = ({ logo, homeLink, displayLogoutButton, disableHomeLink
);
};

TopNavbar.propTypes = {
TopNavbarComponent.propTypes = {
logo: PropTypes.shape({
url: PropTypes.string.isRequired,
alt: PropTypes.string.isRequired,
}),
homeLink: PropTypes.string,
displayLogoutButton: PropTypes.bool,
disableHomeLink: PropTypes.bool,
onLogout: PropTypes.func.isRequired,
};

TopNavbar.defaultProps = {
TopNavbarComponent.defaultProps = {
logo: {
url: '/admin-panel-logo-white.svg',
alt: 'Tupaia Admin Panel Logo',
Expand All @@ -58,3 +61,9 @@ TopNavbar.defaultProps = {
displayLogoutButton: true,
disableHomeLink: false,
};

const mapDispatchToProps = dispatch => ({
onLogout: () => dispatch(logoutAction()),
});

export const TopNavbar = connect(null, mapDispatchToProps)(TopNavbarComponent);
17 changes: 13 additions & 4 deletions packages/admin-panel/src/layout/navigation/UserProfileInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
*/
import React from 'react';
import styled from 'styled-components';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import { Avatar, Divider, Typography } from '@material-ui/core';
import { Tooltip } from '@tupaia/ui-components';
import { UserButton } from './UserButton';
import { useUser } from '../../api/queries';
import { useLogout } from '../../api/mutations';
import { logout as logoutAction } from '../../authentication';

const Wrapper = styled.div`
padding-inline: 1.25rem;
Expand All @@ -29,9 +31,9 @@ const UserEmail = styled(Typography)`
margin-block-end: 0.9rem;
`;

export const UserProfileInfo = ({ profileLink, isFullWidth }) => {
const UserProfileInfoComponent = ({ profileLink, isFullWidth, onLogout }) => {
const { isLoggedIn, data: user, isLoading } = useUser();
const { mutate: logout } = useLogout();
const { mutate: logout } = useLogout(onLogout);

if (isLoading) return null;

Expand Down Expand Up @@ -70,14 +72,21 @@ export const UserProfileInfo = ({ profileLink, isFullWidth }) => {
);
};

UserProfileInfo.propTypes = {
UserProfileInfoComponent.propTypes = {
profileLink: PropTypes.shape({
label: PropTypes.string.isRequired,
to: PropTypes.string.isRequired,
}),
isFullWidth: PropTypes.bool.isRequired,
onLogout: PropTypes.func.isRequired,
};

UserProfileInfo.defaultProps = {
UserProfileInfoComponent.defaultProps = {
profileLink: null,
};

const mapDispatchToProps = dispatch => ({
onLogout: () => dispatch(logoutAction()),
});

export const UserProfileInfo = connect(null, mapDispatchToProps)(UserProfileInfoComponent);
19 changes: 15 additions & 4 deletions packages/lesmis/src/routes/LesmisAdminRedirect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@
*
*/
import React from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useUser } from '@tupaia/admin-panel';
import { hasAdminPanelAccess } from '../utils';
import { hasAdminPanelAccess, useAdminPanelUrl, useUrlParams } from '../utils';

export const LesmisAdminRedirect = () => {
const { data: user } = useUser();
const adminUrl = useAdminPanelUrl();
const { data: user, isLoading } = useUser();
const userHasAdminPanelAccess = hasAdminPanelAccess(user);
const location = useLocation();
const { locale } = useUrlParams();

if (isLoading) {
return null;
}
if (!userHasAdminPanelAccess) {
return <Navigate to="/not-authorised" replace />;
return <Navigate to={`/${locale}/not-authorised`} replace />;
}

if (location.pathname === adminUrl) {
return <Navigate to={`${adminUrl}/survey-responses`} replace />;
}

return <Outlet />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const getEntitiesPageConfig = translate => {
const IMPORT_CONFIG = getImportConfigs(translate, entities.importConfig);
return {
...entities,
title: translate('admin.entities'),
label: translate('admin.entities'),
columns: FIELDS,
importConfig: IMPORT_CONFIG,
nestedViews: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { getEntitiesPageConfig } from './getEntitiesPageConfig';

export const getEntitiesTabRoutes = translate => ({
...entitiesTabRoutes,
title: translate('admin.entities'),
label: translate('admin.entities'),
childViews: [getEntitiesPageConfig(translate)],
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const approvedSurveyResponses = (translate, adminUrl) => {
return {
...configs,
reduxId: 'approvedSurveyResponses', // This is used to store the data in the redux store
title: translate('admin.approved'),
label: translate('admin.approved'),
path,
baseFilter: { approval_status: { comparisonValue: 'approved' } },
columns: COLUMNS.filter(column => column.type !== 'delete'),
Expand All @@ -27,7 +27,7 @@ const rejectedSurveyResponses = (translate, adminUrl) => {
return {
...configs,
reduxId: 'rejectedSurveyResponses', // This is used to store the data in the redux store
title: translate('admin.rejected'),
label: translate('admin.rejected'),
path,
baseFilter: { approval_status: { comparisonValue: 'rejected' } },
columns: COLUMNS.filter(column => column.type !== 'delete'),
Expand Down Expand Up @@ -61,7 +61,7 @@ const draftSurveyResponses = (translate, adminUrl) => {
return {
...configs,
reduxId: 'pendingSurveyResponses', // This is used to store the data in the redux store
title: translate('admin.review'),
label: translate('admin.review'),
path,
default: true,
baseFilter: { approval_status: { comparisonValue: 'pending' } },
Expand All @@ -85,7 +85,7 @@ const nonApprovalSurveyResponses = (translate, adminUrl) => {
return {
...configs,
path,
title: translate('admin.approvalNotRequired'),
label: translate('admin.approvalNotRequired'),
baseFilter: { approval_status: { comparisonValue: 'not_required' } },
columns: NON_APPROVAL_COLUMNS,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getDataElementsPageConfig = translate => {

return {
...dataElements,
title: translate('admin.dataElements'),
label: translate('admin.dataElements'),
columns: [
...DATA_ELEMENT_FIELDS,
...getButtonsConfig(DATA_ELEMENT_FIELDS, 'dataElement', translate),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ export const getQuestionPageConfig = translate => {

return {
...questions,
title: translate('admin.questions'),
label: translate('admin.questions'),
columns: QUESTION_COLUMNS,
editorConfig: EDITOR_CONFIG,
nestedViews: [
{
...questions.nestedViews[0],
title: translate('admin.options'),
label: translate('admin.options'),
columns: OPTION_COLUMNS,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ export const getSurveysPageConfig = translate => {

return {
...surveys,
title: translate('admin.surveys'),
label: translate('admin.surveys'),
columns: SURVEY_COLUMNS,
importConfig: IMPORT_CONFIG,
deleteConfig: getDeleteConfigs(translate),
editorConfig: getBaseEditorConfigs(translate),
nestedViews: [
{
...surveys.nestedViews[0],
title: translate('admin.questions'),
label: translate('admin.questions'),
columns: QUESTION_COLUMNS,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const getSyncGroupsPageConfig = translate => {

return {
...syncGroups,
title: translate('admin.syncGroups'),
label: translate('admin.syncGroups'),
columns: COLUMNS,
editorConfig,
createConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const getPermissionsPageConfig = translate => {
const deleteConfig = getDeleteConfigs(translate);
return {
...permissions,
title: translate('admin.permissions'),
label: translate('admin.permissions'),
columns: FIELDS,
editorConfig,
createConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const getUsersPageConfig = translate => {

return {
...users,
title: translate('admin.users'),
label: translate('admin.users'),
columns: COLUMNS,
editorConfig,
importConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const getDashboardItemsPageConfig = (translate, adminUrl, isBESAdmin) =>

return {
...dashboardItems,
title: translate('admin.dashboardItems'),
label: translate('admin.dashboardItems'),
columns,
importConfig,
editorConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const getDashboardRelationsPageConfig = translate => {

return {
...dashboardRelations,
title: translate('admin.dashboardRelations'),
label: translate('admin.dashboardRelations'),
endpoint: dashboardRelations.endpoint,
columns: FIELDS,
createConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const getDashboardsPageConfig = translate => {

return {
...dashboards,
title: translate('admin.dashboards'),
label: translate('admin.dashboards'),
columns: COLUMNS,
createConfig,
editorConfig,
Expand All @@ -138,7 +138,7 @@ export const getDashboardsPageConfig = translate => {
nestedViews: [
{
...dashboards.nestedViews[0],
title: translate('admin.dashboardRelations'),
label: translate('admin.dashboardRelations'),
columns: RELATION_COLUMNS,
},
],
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const getMapOverlayGroupRelationsPageConfig = translate => {

return {
...mapOverlayGroupRelations,
title: translate('admin.mapOverlayGroupRelations'),
label: translate('admin.mapOverlayGroupRelations'),
columns: COLUMNS,
editorConfig,
createConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ export const getMapOverlayGroupsPageConfig = translate => {

return {
...mapOverlayGroups,
title: translate('admin.mapOverlayGroups'),
label: translate('admin.mapOverlayGroups'),
columns: COLUMNS,
editorConfig,
createConfig,
nestedViews: [
{
...mapOverlayGroups.nestedViews[0],
title: translate('admin.mapOverlayGroupRelations'),
label: translate('admin.mapOverlayGroupRelations'),
columns: RELATION_COLUMNS,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const getMapOverlaysPageConfig = (translate, adminUrl, isBESAdmin) => {
const deleteConfig = getDeleteConfigs(translate);
return {
...mapOverlays,
title: translate('admin.mapOverlays'),
label: translate('admin.mapOverlays'),
columns: COLUMNS,
importConfig,
LinksComponent: renderNewMapOverlayVizButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const ExportDate = styled(Typography)`
font-size: 0.75rem;
padding-block: 1rem 0.3rem;
`;

interface EnlargedDashboardVisualProps {
entityName?: Entity['name'];
isPreview?: boolean;
Expand Down Expand Up @@ -178,6 +179,7 @@ export const EnlargedDashboardVisual = ({
isExport: isPreview,
reportCode: currentDashboardItem?.reportCode,
config: mergedConfig,
isEnabled: true,
}}
>
<DashboardItemContent />
Expand Down
Loading

0 comments on commit 92bb784

Please sign in to comment.