From db276b7f55f6934df1d165010d76e2d7846b3243 Mon Sep 17 00:00:00 2001 From: alexd-bes <129009580+alexd-bes@users.noreply.github.com> Date: Wed, 8 May 2024 09:02:31 +1200 Subject: [PATCH 01/26] refactor(adminPanel): RN-1284: Update admin panel tables (#5602) * Update tables to use v7 package * Sorting * WIP * Update DataFetchingTableNew.jsx * Styling * Fix disableSortBy value * Rename new datafetching table * Remove comment * Update packages/admin-panel/src/table/DataFetchingTable/DataFetchingTable.jsx Co-authored-by: Jasper Lai <33956381+jaskfla@users.noreply.github.com> * refactor(adminPanel): RN-1284: Update admin panel tables PART 2 (#5610) * WIP * Upgrade react router * WIP * Table styling and breadcrumbs * Breadcrumbs and links * surveys pages * user routes * WIP * Remove recursive function * Remove recursive func * Use new routes syntax * Use correct icons * Allow custom link generation * Update QrCodeButton.jsx * Stop filtering on button columns * Make filter cells sticky * Tidy ups * Update SecondaryNavbar.jsx * Make navbar work on re-render * Handle redirects * Error and no data handling * Fix react router type issue * Remove commented out redirect * Update handling of admin panel routes * Add back in permissions * Update packages/admin-panel/src/table/DataFetchingTable/Cells.jsx Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com> * refactor(lesmis): RN-1284: Rejig admin panel tables PART 3 (#5617) * WIP * Upgrade react router * WIP * Table styling and breadcrumbs * Breadcrumbs and links * surveys pages * user routes * WIP * Remove recursive function * Remove recursive func * Use new routes syntax * Use correct icons * Allow custom link generation * Update QrCodeButton.jsx * Stop filtering on button columns * Make filter cells sticky * Tidy ups * Update SecondaryNavbar.jsx * Make navbar work on re-render * Handle redirects * Error and no data handling * Fix react router type issue * WIP * Remove commented out redirect * working main app * exports * Update handling of admin panel routes * WIP * WIP * WIP * Add back in permissions * WIP * Move all routes to new format * re-arrange imports * Add back in redirects, and styling * Tidy ups * Remove comment * Tidy ups * remove spread * Fix build * Fix build * Fix imports * Updates from review * Fix export filename issue * Changes to UI * Fix home link * Fix header cell overflow * Update width handling * Fix prop type errors * LESMIS tidy ups --------- Co-authored-by: Jasper Lai <33956381+jaskfla@users.noreply.github.com> Co-authored-by: Rohan Port <59544282+rohan-bes@users.noreply.github.com> --- packages/admin-panel/package.json | 5 +- packages/admin-panel/src/App.jsx | 156 +++---- .../admin-panel/src/VizBuilderApp/App.jsx | 36 +- .../src/VizBuilderApp/views/CreateNew.jsx | 6 +- .../src/api/queries/useResourceDetails.js | 26 ++ .../src/authentication/PrivateRoute.jsx | 27 +- .../src/authentication/selectors.js | 2 +- packages/admin-panel/src/common.jsx | 51 +++ packages/admin-panel/src/editor/actions.js | 1 + .../src/importExport/ExportButton.jsx | 15 +- .../admin-panel/src/layout/AppPageLayout.jsx | 69 +++ .../admin-panel/src/layout/Breadcrumbs.jsx | 61 +++ packages/admin-panel/src/layout/Page.jsx | 5 +- .../admin-panel/src/layout/TabPageLayout.jsx | 46 ++ packages/admin-panel/src/layout/index.js | 3 + .../src/layout/navigation/NavPanel.jsx | 6 +- .../src/layout/navigation/SecondaryNavbar.jsx | 91 ++-- packages/admin-panel/src/library.js | 44 +- .../admin-panel/src/logsTable/LogsButton.jsx | 8 +- .../admin-panel/src/logsTable/LogsTable.jsx | 4 +- packages/admin-panel/src/main.jsx | 29 +- packages/admin-panel/src/pages/LoginPage.jsx | 13 +- packages/admin-panel/src/pages/LogoutPage.jsx | 4 +- .../src/pages/resources/CountriesPage.jsx | 48 -- .../pages/resources/DashboardItemsPage.jsx | 139 ------ .../src/pages/resources/DataSourcesPage.jsx | 149 ------ .../src/pages/resources/EntityTypesPage.jsx | 28 -- .../src/pages/resources/ResourcePage.jsx | 90 +++- .../admin-panel/src/pages/resources/index.js | 38 +- packages/admin-panel/src/profileRoutes.jsx | 16 +- packages/admin-panel/src/routes.jsx | 282 ------------ .../src/routes/entities/countries.js | 43 ++ .../entities/entities.js} | 76 ++-- .../src/routes/entities/entitiesTabRoutes.jsx | 17 + .../src/routes/entities/entityHierarchies.js | 12 + .../src/routes/entities/entityTypes.js | 23 + .../admin-panel/src/routes/entities/index.js | 7 + .../externalData/dhisInstances.js} | 22 +- .../externalData/externalDataTabRoutes.jsx | 17 + .../externalDatabaseConnections.js} | 28 +- .../src/routes/externalData/index.js | 7 + .../externalData/msupplySupersetInstances.js} | 26 +- packages/admin-panel/src/routes/index.js | 27 ++ .../projects/entityHierarchy.js} | 16 +- .../admin-panel/src/routes/projects/index.js | 6 + .../projects/landingPages.jsx} | 23 +- .../projects/projects.js} | 37 +- .../src/routes/projects/projectsTabRoutes.jsx | 17 + .../admin-panel/src/routes/projects/strive.js | 13 + packages/admin-panel/src/routes/routes.jsx | 20 + .../src/routes/surveys/dataElements.js | 37 ++ .../src/routes/surveys/dataGroups.js | 63 +++ .../surveys/dataMapping.js} | 28 +- .../admin-panel/src/routes/surveys/index.js | 11 + .../surveys/optionSets.js} | 37 +- .../surveys/questions.js} | 41 +- .../surveys/surveyResponses.js} | 46 +- .../surveys/surveys.js} | 31 +- .../src/routes/surveys/surveysTabRoutes.jsx | 32 ++ .../surveys/syncGroups.js} | 34 +- .../users/accessRequests.js} | 61 ++- .../admin-panel/src/routes/users/index.js | 8 + .../users/permissionGroups.jsx} | 28 +- .../routes/users/permissionGroupsViewer.js | 11 + .../users/permissions.js} | 34 +- .../UsersPage.jsx => routes/users/users.jsx} | 56 +-- .../src/routes/users/usersTabRoutes.jsx | 19 + .../routes/visualisations/dashboardItems.jsx | 123 +++++ .../visualisations/dashboardMailingLists.js} | 35 +- .../visualisations/dashboardRelations.js} | 31 +- .../visualisations/dashboards.js} | 39 +- .../visualisations/dataTables.js} | 29 +- .../src/routes/visualisations/index.js | 13 + .../visualisations/indicators.js} | 22 +- .../visualisations/legacyReports.js} | 15 +- .../mapOverlayGroupRelations.js} | 21 +- .../visualisations/mapOverlayGroups.js} | 40 +- .../visualisations/mapOverlays.jsx} | 170 ++++--- .../visualisations/socialFeed.jsx} | 35 +- .../visualisationsTabRoutes.jsx | 37 ++ packages/admin-panel/src/sync/SyncStatus.jsx | 28 +- .../src/table/DataFetchingTable.jsx | 306 ------------- .../src/table/DataFetchingTable/Cells.jsx | 186 ++++++++ .../DataFetchingTable/DataFetchingTable.jsx | 428 ++++++++++++++++++ .../table/DataFetchingTable/FilterCell.jsx | 87 ++++ .../table/DataFetchingTable/Pagination.jsx | 179 ++++++++ .../src/table/DataFetchingTable/index.js | 1 + .../src/table/StyledReactTable.jsx | 160 ------- packages/admin-panel/src/table/actions.js | 4 +- .../src/table/columnTypes/BulkEditButton.jsx | 13 +- .../table/columnTypes/ColumnActionButton.jsx | 13 + .../src/table/columnTypes/DeleteButton.jsx | 18 +- .../src/table/columnTypes/EditButton.jsx | 8 +- .../src/table/columnTypes/QrCodeButton.jsx | 40 +- .../ResubmitSurveyResponseButton.jsx | 20 +- .../TestDatabaseConnectionButton.jsx | 15 +- .../src/table/columnTypes/Tooltip.jsx | 6 +- .../src/table/columnTypes/columnFilters.jsx | 43 +- .../generateConfigForColumnType.jsx | 13 +- packages/admin-panel/src/table/index.js | 2 +- packages/admin-panel/src/theme/theme.js | 16 +- .../admin-panel/src/widgets/PageHeader.jsx | 10 +- .../src/apiV2/GETHandler/GETHandler.js | 3 +- .../datatrak-web/src/routes/PrivateRoute.tsx | 1 + packages/lesmis/package.json | 3 +- packages/lesmis/src/App.jsx | 12 +- packages/lesmis/src/api/mutations/useLogin.js | 7 +- .../src/api/queries/useValidatedQuery.js | 6 +- .../lesmis/src/components/FormBackButton.jsx | 7 +- packages/lesmis/src/components/LocaleMenu.jsx | 31 +- packages/lesmis/src/components/LoginLink.jsx | 10 +- packages/lesmis/src/components/SearchBar.jsx | 6 +- packages/lesmis/src/components/SignUpLink.jsx | 10 +- packages/lesmis/src/routes/AdminPanelApp.jsx | 346 +++++--------- .../lesmis/src/routes/LesmisAdminRedirect.jsx | 15 + .../lesmis/src/routes/LesmisAdminRoute.jsx | 16 - packages/lesmis/src/routes/PageRoutes.jsx | 162 ++++--- packages/lesmis/src/theme/theme.js | 2 +- .../src/utils/useDefaultDashboardTab.js | 11 +- packages/lesmis/src/utils/useHomeUrl.js | 8 +- packages/lesmis/src/utils/useUrlParams.js | 8 +- .../lesmis/src/utils/useUrlSearchParams.js | 15 +- .../views/AdminPanel/AdminPanelLoginPage.jsx | 5 +- .../views/AdminPanel/SurveyResponsesView.jsx | 146 ------ .../AdminPanel/components/ApproveButton.jsx | 25 +- .../AdminPanel/components/RejectButton.jsx | 12 +- .../src/views/AdminPanel/pages/LoginPage.jsx | 6 +- .../pages/resources/EntitiesPage.jsx | 149 ------ .../pages/resources/QuestionsPage.jsx | 27 -- .../pages/resources/SurveysPage.jsx | 29 -- .../views/AdminPanel/pages/resources/index.js | 18 - .../routes/entities/getEntitiesPageConfig.js | 91 ++++ .../routes/entities/getEntitiesTabRoutes.js | 12 + .../views/AdminPanel/routes/entities/index.js | 5 + .../src/views/AdminPanel/routes/getRoutes.js | 26 ++ .../helpers/getCreateConfigs.js | 0 .../helpers/getDeleteColumnConfigs.js | 7 +- .../helpers/getDeleteConfigs.js | 6 +- .../helpers/getEditorConfigs.js | 6 +- .../helpers/getImportConfigs.js | 6 +- .../{pages => routes}/helpers/index.js | 7 +- .../src/views/AdminPanel/routes/index.js | 6 + .../getSurveyResponsePageConfig.js} | 27 +- .../getSurveyResponsesTabRoutes.js | 104 +++++ .../routes/surveyResponses/index.js | 5 + .../surveys/getDataElementsPageConfig.js} | 58 ++- .../surveys/getQuestionPageConfig.js} | 29 +- .../surveys/getSurveysPageConfig.js} | 47 +- .../routes/surveys/getSurveysTabRoutes.js | 22 + .../surveys/getSyncGroupsPageConfig.js} | 43 +- .../views/AdminPanel/routes/surveys/index.js | 6 + .../users/getPermissionsPageConfig.jsx} | 88 +--- .../users/getUsersPageConfig.jsx} | 53 +-- .../routes/users/getUsersTabRoutes.js | 13 + .../views/AdminPanel/routes/users/index.js | 6 + .../getDashboardItemsPageConfig.jsx} | 89 ++-- .../getDashboardRelationsPageConfig.js} | 51 +-- .../getDashboardsPageConfig.js} | 61 ++- .../visualisations/getDataTablesPageConfig.js | 0 .../getMapOverlayGroupRelationsPageConfig.js} | 43 +- .../getMapOverlayGroupsPageConfig.js} | 49 +- .../getMapOverlaysPageConfig.jsx} | 92 ++-- .../getVisualisationsTabsRoutes.js | 28 ++ .../AdminPanel/routes/visualisations/index.js | 6 + packages/lesmis/src/views/EntityView.jsx | 22 +- packages/lesmis/src/views/LoginView.jsx | 36 +- .../lesmis/src/views/NotAuthorisedView.jsx | 10 +- packages/lesmis/src/views/VerifyEmailView.jsx | 4 +- .../src/components/Breadcrumbs.tsx | 2 +- yarn.lock | 43 +- 170 files changed, 3668 insertions(+), 3355 deletions(-) create mode 100644 packages/admin-panel/src/api/queries/useResourceDetails.js create mode 100644 packages/admin-panel/src/layout/AppPageLayout.jsx create mode 100644 packages/admin-panel/src/layout/Breadcrumbs.jsx create mode 100644 packages/admin-panel/src/layout/TabPageLayout.jsx delete mode 100644 packages/admin-panel/src/pages/resources/CountriesPage.jsx delete mode 100644 packages/admin-panel/src/pages/resources/DashboardItemsPage.jsx delete mode 100644 packages/admin-panel/src/pages/resources/DataSourcesPage.jsx delete mode 100644 packages/admin-panel/src/pages/resources/EntityTypesPage.jsx delete mode 100644 packages/admin-panel/src/routes.jsx create mode 100644 packages/admin-panel/src/routes/entities/countries.js rename packages/admin-panel/src/{pages/resources/EntitiesPage.jsx => routes/entities/entities.js} (62%) create mode 100644 packages/admin-panel/src/routes/entities/entitiesTabRoutes.jsx create mode 100644 packages/admin-panel/src/routes/entities/entityHierarchies.js create mode 100644 packages/admin-panel/src/routes/entities/entityTypes.js create mode 100644 packages/admin-panel/src/routes/entities/index.js rename packages/admin-panel/src/{pages/resources/DhisInstancesPage.jsx => routes/externalData/dhisInstances.js} (69%) create mode 100644 packages/admin-panel/src/routes/externalData/externalDataTabRoutes.jsx rename packages/admin-panel/src/{pages/resources/ExternalDatabaseConnectionsPage.jsx => routes/externalData/externalDatabaseConnections.js} (74%) create mode 100644 packages/admin-panel/src/routes/externalData/index.js rename packages/admin-panel/src/{pages/resources/SupersetInstancesPage.jsx => routes/externalData/msupplySupersetInstances.js} (63%) create mode 100644 packages/admin-panel/src/routes/index.js rename packages/admin-panel/src/{pages/resources/EntityHierarchyPage.jsx => routes/projects/entityHierarchy.js} (73%) create mode 100644 packages/admin-panel/src/routes/projects/index.js rename packages/admin-panel/src/{pages/resources/CustomLandingPagesPage.jsx => routes/projects/landingPages.jsx} (95%) rename packages/admin-panel/src/{pages/resources/ProjectsPage.jsx => routes/projects/projects.js} (83%) create mode 100644 packages/admin-panel/src/routes/projects/projectsTabRoutes.jsx create mode 100644 packages/admin-panel/src/routes/projects/strive.js create mode 100644 packages/admin-panel/src/routes/routes.jsx create mode 100644 packages/admin-panel/src/routes/surveys/dataElements.js create mode 100644 packages/admin-panel/src/routes/surveys/dataGroups.js rename packages/admin-panel/src/{pages/resources/DataElementDataServicesPage.jsx => routes/surveys/dataMapping.js} (73%) create mode 100644 packages/admin-panel/src/routes/surveys/index.js rename packages/admin-panel/src/{pages/resources/OptionSetsPage.jsx => routes/surveys/optionSets.js} (78%) rename packages/admin-panel/src/{pages/resources/QuestionsPage.jsx => routes/surveys/questions.js} (78%) rename packages/admin-panel/src/{pages/resources/SurveyResponsesPage.jsx => routes/surveys/surveyResponses.js} (85%) rename packages/admin-panel/src/{pages/resources/SurveysPage.jsx => routes/surveys/surveys.js} (97%) create mode 100644 packages/admin-panel/src/routes/surveys/surveysTabRoutes.jsx rename packages/admin-panel/src/{pages/resources/SyncGroupsPage.jsx => routes/surveys/syncGroups.js} (77%) rename packages/admin-panel/src/{pages/resources/AccessRequestsPage.jsx => routes/users/accessRequests.js} (81%) create mode 100644 packages/admin-panel/src/routes/users/index.js rename packages/admin-panel/src/{pages/resources/PermissionGroupsPage.jsx => routes/users/permissionGroups.jsx} (67%) create mode 100644 packages/admin-panel/src/routes/users/permissionGroupsViewer.js rename packages/admin-panel/src/{pages/resources/PermissionsPage.jsx => routes/users/permissions.js} (83%) rename packages/admin-panel/src/{pages/resources/UsersPage.jsx => routes/users/users.jsx} (84%) create mode 100644 packages/admin-panel/src/routes/users/usersTabRoutes.jsx create mode 100644 packages/admin-panel/src/routes/visualisations/dashboardItems.jsx rename packages/admin-panel/src/{pages/resources/DashboardMailingListsPage.jsx => routes/visualisations/dashboardMailingLists.js} (87%) rename packages/admin-panel/src/{pages/resources/DashboardRelationsPage.jsx => routes/visualisations/dashboardRelations.js} (86%) rename packages/admin-panel/src/{pages/resources/DashboardsPage.jsx => routes/visualisations/dashboards.js} (85%) rename packages/admin-panel/src/{pages/resources/DataTablesPage.jsx => routes/visualisations/dataTables.js} (80%) create mode 100644 packages/admin-panel/src/routes/visualisations/index.js rename packages/admin-panel/src/{pages/resources/IndicatorsPage.jsx => routes/visualisations/indicators.js} (73%) rename packages/admin-panel/src/{pages/resources/LegacyReportsPage.jsx => routes/visualisations/legacyReports.js} (71%) rename packages/admin-panel/src/{pages/resources/MapOverlayGroupRelationsPage.jsx => routes/visualisations/mapOverlayGroupRelations.js} (84%) rename packages/admin-panel/src/{pages/resources/MapOverlayGroupsPage.jsx => routes/visualisations/mapOverlayGroups.js} (80%) rename packages/admin-panel/src/{pages/resources/MapOverlaysPage.jsx => routes/visualisations/mapOverlays.jsx} (51%) rename packages/admin-panel/src/{pages/resources/SocialFeedPage.jsx => routes/visualisations/socialFeed.jsx} (82%) create mode 100644 packages/admin-panel/src/routes/visualisations/visualisationsTabRoutes.jsx delete mode 100644 packages/admin-panel/src/table/DataFetchingTable.jsx create mode 100644 packages/admin-panel/src/table/DataFetchingTable/Cells.jsx create mode 100644 packages/admin-panel/src/table/DataFetchingTable/DataFetchingTable.jsx create mode 100644 packages/admin-panel/src/table/DataFetchingTable/FilterCell.jsx create mode 100644 packages/admin-panel/src/table/DataFetchingTable/Pagination.jsx create mode 100644 packages/admin-panel/src/table/DataFetchingTable/index.js delete mode 100644 packages/admin-panel/src/table/StyledReactTable.jsx create mode 100644 packages/admin-panel/src/table/columnTypes/ColumnActionButton.jsx create mode 100644 packages/lesmis/src/routes/LesmisAdminRedirect.jsx delete mode 100644 packages/lesmis/src/routes/LesmisAdminRoute.jsx delete mode 100644 packages/lesmis/src/views/AdminPanel/SurveyResponsesView.jsx delete mode 100644 packages/lesmis/src/views/AdminPanel/pages/resources/EntitiesPage.jsx delete mode 100644 packages/lesmis/src/views/AdminPanel/pages/resources/QuestionsPage.jsx delete mode 100644 packages/lesmis/src/views/AdminPanel/pages/resources/SurveysPage.jsx delete mode 100644 packages/lesmis/src/views/AdminPanel/pages/resources/index.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/entities/getEntitiesPageConfig.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/entities/getEntitiesTabRoutes.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/entities/index.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/getRoutes.js rename packages/lesmis/src/views/AdminPanel/{pages => routes}/helpers/getCreateConfigs.js (100%) rename packages/lesmis/src/views/AdminPanel/{pages => routes}/helpers/getDeleteColumnConfigs.js (72%) rename packages/lesmis/src/views/AdminPanel/{pages => routes}/helpers/getDeleteConfigs.js (76%) rename packages/lesmis/src/views/AdminPanel/{pages => routes}/helpers/getEditorConfigs.js (90%) rename packages/lesmis/src/views/AdminPanel/{pages => routes}/helpers/getImportConfigs.js (84%) rename packages/lesmis/src/views/AdminPanel/{pages => routes}/helpers/index.js (59%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/index.js rename packages/lesmis/src/views/AdminPanel/{pages/helpers/getSurveyResponsePageConfigs.js => routes/surveyResponses/getSurveyResponsePageConfig.js} (85%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/surveyResponses/getSurveyResponsesTabRoutes.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/surveyResponses/index.js rename packages/lesmis/src/views/AdminPanel/{pages/resources/DataElementsPage.jsx => routes/surveys/getDataElementsPageConfig.js} (61%) rename packages/lesmis/src/views/AdminPanel/{pages/helpers/getQuestionPageConfigs.js => routes/surveys/getQuestionPageConfig.js} (82%) rename packages/lesmis/src/views/AdminPanel/{pages/helpers/getSurveysPageConfigs.js => routes/surveys/getSurveysPageConfig.js} (94%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/surveys/getSurveysTabRoutes.js rename packages/lesmis/src/views/AdminPanel/{pages/resources/SyncGroupsPage.jsx => routes/surveys/getSyncGroupsPageConfig.js} (69%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/surveys/index.js rename packages/lesmis/src/views/AdminPanel/{pages/resources/PermissionsPage.jsx => routes/users/getPermissionsPageConfig.jsx} (53%) rename packages/lesmis/src/views/AdminPanel/{pages/resources/UsersPage.jsx => routes/users/getUsersPageConfig.jsx} (82%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/users/getUsersTabRoutes.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/users/index.js rename packages/lesmis/src/views/AdminPanel/{pages/resources/DashboardItemsPage.jsx => routes/visualisations/getDashboardItemsPageConfig.jsx} (54%) rename packages/lesmis/src/views/AdminPanel/{pages/resources/DashboardRelationsPage.jsx => routes/visualisations/getDashboardRelationsPageConfig.js} (72%) rename packages/lesmis/src/views/AdminPanel/{pages/resources/DashboardsPage.jsx => routes/visualisations/getDashboardsPageConfig.js} (72%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/visualisations/getDataTablesPageConfig.js rename packages/lesmis/src/views/AdminPanel/{pages/resources/MapOverlayGroupRelationsPage.jsx => routes/visualisations/getMapOverlayGroupRelationsPageConfig.js} (68%) rename packages/lesmis/src/views/AdminPanel/{pages/resources/MapOverlayGroupsPage.jsx => routes/visualisations/getMapOverlayGroupsPageConfig.js} (73%) rename packages/lesmis/src/views/AdminPanel/{pages/resources/MapOverlaysPage.jsx => routes/visualisations/getMapOverlaysPageConfig.jsx} (69%) create mode 100644 packages/lesmis/src/views/AdminPanel/routes/visualisations/getVisualisationsTabsRoutes.js create mode 100644 packages/lesmis/src/views/AdminPanel/routes/visualisations/index.js diff --git a/packages/admin-panel/package.json b/packages/admin-panel/package.json index 3eb0e7ca22..263d09a98c 100644 --- a/packages/admin-panel/package.json +++ b/packages/admin-panel/package.json @@ -66,9 +66,10 @@ "react-password-strength-bar": "^0.3.2", "react-query": "^3.19.0", "react-redux": "^5.0.6", - "react-router-dom": "^5.2.0", + "react-router": "6.3.0", + "react-router-dom": "6.3.0", "react-select": "^1.2.1", - "react-table-v6": "npm:react-table@^6.7.6", + "react-table": "^7.8.0", "reactstrap": "^5.0.0", "redux": "^3.7.2", "redux-auth-wrapper": "^2.0.1", diff --git a/packages/admin-panel/src/App.jsx b/packages/admin-panel/src/App.jsx index 4fefd4f2b3..c406ef7282 100644 --- a/packages/admin-panel/src/App.jsx +++ b/packages/admin-panel/src/App.jsx @@ -1,18 +1,51 @@ /* * Tupaia - * Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd + * Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd */ import React from 'react'; import PropTypes from 'prop-types'; -import { Route, Switch, Redirect } from 'react-router-dom'; +import { Navigate, Route, Routes } from 'react-router-dom'; import { connect } from 'react-redux'; -import { Footer, Main, NavPanel, PageContentWrapper, PageWrapper, SecondaryNavbar } from './layout'; +import { AppPageLayout, Footer } from './layout'; import { ROUTES } from './routes'; import { PROFILE_ROUTES } from './profileRoutes'; -import { getHasBESAdminPanelAccess, getUser, PrivateRoute } from './authentication'; +import { getHasBESAdminAccess, getUser, PrivateRoute } from './authentication'; import { LoginPage } from './pages/LoginPage'; import { LogoutPage } from './pages/LogoutPage'; -import { labelToId } from './utilities'; +import { ResourcePage } from './pages/resources/ResourcePage'; +import { TabPageLayout } from './layout/TabPageLayout'; + +export const getFlattenedChildViews = (route, basePath = '') => { + return route.childViews.reduce((acc, childView) => { + const { nestedView } = childView; + + const childViewWithRoute = { + ...childView, + basePath, + path: `${route.path}${childView.path}`, + to: `${basePath}${route.path}${childView.path}`, // this is an absolute route so that the breadcrumbs work + }; + + if (!nestedView) return [...acc, childViewWithRoute]; + + const updatedNestedView = nestedView + ? { + ...nestedView, + path: `${route.path}${childView.path}${nestedView.path}`, + parent: childViewWithRoute, + } + : null; + + return [ + ...acc, + { + ...childViewWithRoute, + nestedView: updatedNestedView, + }, + updatedNestedView, + ]; + }, []); +}; export const App = ({ user, hasBESAdminAccess }) => { const userHasAccessToTab = tab => { @@ -27,87 +60,54 @@ export const App = ({ user, hasBESAdminAccess }) => { return ROUTES.map(route => { return { ...route, - tabs: route.tabs.filter(tab => userHasAccessToTab(tab)), + childViews: route.childViews.filter(childView => userHasAccessToTab(childView)), }; }).filter(route => { if (route.isBESAdminOnly) return !!hasBESAdminAccess; - return route.tabs.length > 0; + return route.childViews.length > 0; }); }; const accessibleRoutes = getAccessibleRoutes(); return ( - - - - - - + + } /> + } /> + }> + }> + } /> + } /> + {[...accessibleRoutes, ...PROFILE_ROUTES].map(route => ( + } + /> + } + > + {getFlattenedChildViews(route).map(childRoute => ( + + ) : ( + + ) + } + /> + ))} + } /> + + ))} + - - - ({ - ...route, - id: `app-tab-${labelToId(route.label)}`, - }))} - user={user} - userLinks={[ - { label: 'Profile', to: '/profile' }, - { label: 'Logout', to: '/logout' }, - ]} - /> -
- - - {[...accessibleRoutes, ...PROFILE_ROUTES].map(route => ( - { - return ( - <> - ({ - ...tab, - id: `app-subTab-${labelToId(tab.label)}`, - }))} - baseRoute={match.url} - /> - - {route.tabs.map(tab => ( - - - - ))} - - - - ); - }} - /> - ))} - - -
- -
-
-
- -
+ ); }; @@ -128,7 +128,7 @@ App.propTypes = { export default connect( state => ({ user: getUser(state), - hasBESAdminAccess: getHasBESAdminPanelAccess(state), + hasBESAdminAccess: getHasBESAdminAccess(state), }), null, )(App); diff --git a/packages/admin-panel/src/VizBuilderApp/App.jsx b/packages/admin-panel/src/VizBuilderApp/App.jsx index 2f1e3e16a7..5030c74932 100644 --- a/packages/admin-panel/src/VizBuilderApp/App.jsx +++ b/packages/admin-panel/src/VizBuilderApp/App.jsx @@ -5,7 +5,8 @@ import React from 'react'; import styled from 'styled-components'; import PropTypes from 'prop-types'; -import { Switch, Route } from 'react-router-dom'; +import { renderMatches, useLocation } from 'react-router'; +import { matchRoutes } from 'react-router-dom'; import { FullPageLoader } from '@tupaia/ui-components'; import { Main } from './views/Main'; import { CreateNew } from './views/CreateNew'; @@ -33,6 +34,27 @@ export const App = ({ Footer, homeLink, logo }) => { const { isLoading: isUserLoading } = useUser(); const basePath = useVizBuilderBasePath(); + const location = useLocation(); + + const matches = matchRoutes( + [ + { + path: `${basePath}/viz-builder/:dashboardItemOrMapOverlay/new`, + exact: true, + element: , + }, + { + path: `${basePath}/viz-builder/:dashboardItemOrMapOverlay/:visualisationId`, + element:
, + }, + // react router v6 does not support optional params, so we need to define two routes + { + path: `${basePath}/viz-builder/:dashboardItemOrMapOverlay`, + element:
, + }, + ], + location.pathname, + ); if (isUserLoading) { return ; @@ -44,14 +66,8 @@ export const App = ({ Footer, homeLink, logo }) => { - - - - - -
- - + {/** Workaround for handling issues with this nested app */} + {renderMatches(matches)} {Footer &&