Skip to content
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

Upgrade console and my account to React Router v6 #6397

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"country-language": "^0.1.7",
"deep-equal": "^2.2.2",
"file-saver": "^2.0.5",
"history": "^4.9.0",
"html-react-parser": "^2.0.0",
"i18next": "^21.9.1",
"i18next-browser-languagedetector": "^6.1.5",
Expand All @@ -86,7 +85,6 @@
"react-joyride": "^2.3.0",
"react-notification-system": "^0.4.0",
"react-redux": "^7.2.9",
"react-router-dom": "^4.3.1",
"reactflow": "11.7.2",
"recharts": "^2.6.2",
"reduce-reducers": "^1.0.4",
Expand Down Expand Up @@ -114,12 +112,8 @@
"@types/lodash-es": "^4.17.4",
"@types/node": "^13.9.2",
"@types/node-forge": "^0.9.3",
"@types/react": "^18.0.18",
"@types/react-dom": "^18.0.6",
"@types/react-notification-system": "0.2.39",
"@types/react-redux": "^7.1.25",
"@types/react-router": "^5.1.18",
"@types/react-router-dom": "^5.1.3",
"@types/reactour": "^1.18.1",
"@types/redux-mock-store": "^1.0.2",
"@types/testing-library__jest-dom": "^5.14.3",
Expand Down
381 changes: 189 additions & 192 deletions apps/console/src/app.tsx

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions apps/myaccount/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"react-i18next": "^11.18.5",
"react-notification-system": "^0.4.0",
"react-redux": "^7.2.9",
"react-router-dom": "^4.3.1",
"react-top-loading-bar": "^1.2.0",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0",
Expand All @@ -83,12 +82,8 @@
"@types/jest": "^29.5.12",
"@types/lodash-es": "^4.17.4",
"@types/node": "^13.9.2",
"@types/react": "^18.0.18",
"@types/react-dom": "^18.0.6",
"@types/react-notification-system": "0.2.39",
"@types/react-redux": "^7.1.25",
"@types/react-router": "^5.1.18",
"@types/react-router-dom": "^5.1.3",
"@types/redux-mock-store": "^1.0.2",
"@types/uuid": "^9.0.1",
"@types/webpack-env": "^1.16.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/myaccount/src/api/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import { PatchOperationRequest, ProfileInfoInterface, ProfileSchemaInterface } f
import { CommonUtils } from "@wso2is/core/utils";
import axios, { AxiosError } from "axios";
import isEmpty from "lodash-es/isEmpty";
import { globalNavigate } from "../components/shared/global-history";
import { Config } from "../configs";
import { AppConstants } from "../constants";
import { history } from "../helpers";
import { BasicProfileInterface, HttpMethods, ReadOnlyUserStatus } from "../models";
import { store } from "../store";
import { toggleSCIMEnabled } from "../store/actions";
Expand Down Expand Up @@ -173,7 +173,7 @@ export const getProfileInfo = (): Promise<BasicProfileInterface> => {
store.dispatch(toggleSCIMEnabled(false));

// Navigate to login error page.
history.push(AppConstants.getPaths().get("LOGIN_ERROR"));
globalNavigate(AppConstants.getPaths().get("LOGIN_ERROR"));
}

return Promise.reject(error);
Expand Down
318 changes: 166 additions & 152 deletions apps/myaccount/src/app.tsx

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/myaccount/src/components/authentication/sign-out.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import React, { FunctionComponent, ReactElement, useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Dispatch } from "redux";
import { history } from "../../helpers";

Check warning on line 26 in apps/myaccount/src/components/authentication/sign-out.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

'history' is defined but never used. Allowed unused vars must match /^_/u
import useOrganizations from "../../hooks/use-organizations";
import { AppState } from "../../store";
import { globalNavigate } from "../shared/global-history";
import { PreLoader } from "../shared/pre-loader/pre-loader";

/**
Expand Down Expand Up @@ -59,7 +60,7 @@

signOut()
.catch(() => {
history.push(window[ "AppUtils" ].getConfig().routes.home);
globalNavigate(window[ "AppUtils" ].getConfig().routes.home);
});
}
}, [ logoutInit ]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
* under the License.
*/

import { IdentifiableComponentInterface, TestableComponentInterface } from "@wso2is/core/models";

Check warning on line 19 in apps/myaccount/src/components/overview/widgets/account-security-widget.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

incorrect header
import React, { FunctionComponent } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { getWidgetIcons } from "../../../configs";
import { AppConstants, CommonConstants } from "../../../constants";
import { history } from "../../../helpers";

Check warning on line 25 in apps/myaccount/src/components/overview/widgets/account-security-widget.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

'history' is defined but never used. Allowed unused vars must match /^_/u
import { SettingsSection } from "../../shared";

type AccountSecurityWidgetPropsInterface = TestableComponentInterface & IdentifiableComponentInterface;
Expand All @@ -39,10 +40,7 @@

const { ["data-testid"]: testId } = props;
const { t } = useTranslation();

const navigate = () => {
history.push(AppConstants.getPaths().get("SECURITY") + "#" + CommonConstants.ACCOUNT_SECURITY);
};
const navigate = useNavigate();

Check warning on line 43 in apps/myaccount/src/components/overview/widgets/account-security-widget.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

Expected navigate to have a type annotation

return (
<div className="widget account-security" data-testid={ testId }>
Expand All @@ -52,7 +50,9 @@
header={ t("myAccount:components.overview.widgets.accountSecurity.header") }
description={ t("myAccount:components.overview.widgets.accountSecurity.description") }
primaryAction={ t("myAccount:components.overview.widgets.accountSecurity.actionTitles.update") }
onPrimaryActionClick={ navigate }
onPrimaryActionClick={ () => {
navigate(AppConstants.getPaths().get("SECURITY") + "#" + CommonConstants.ACCOUNT_SECURITY)

Check warning on line 54 in apps/myaccount/src/components/overview/widgets/account-security-widget.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

Missing semicolon
} }
icon={ getWidgetIcons().accountSecurity }
iconMini={ getWidgetIcons().accountSecurity }
iconSize="x60"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* under the License.
*/

import { IdentifiableComponentInterface, TestableComponentInterface } from "@wso2is/core/models";

Check warning on line 19 in apps/myaccount/src/components/overview/widgets/consent-management-widget.tsx

View workflow job for this annotation

GitHub Actions / ⬣ ESLint (STATIC ANALYSIS) (lts/*, 8.7.4)

incorrect header
import React, { FunctionComponent, ReactElement } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { getWidgetIcons } from "../../../configs";
import { AppConstants, CommonConstants } from "../../../constants";
import { history } from "../../../helpers";
Expand All @@ -38,10 +39,7 @@

const { ["data-testid"]: testId } = props;
const { t } = useTranslation();

const navigate = () => {
history.push(AppConstants.getPaths().get("SECURITY") + "#" + CommonConstants.CONSENTS_CONTROL);
};
const navigate = useNavigate()

return (
<div className="widget consent-management" data-testid={ testId }>
Expand All @@ -51,7 +49,9 @@
header={ t("myAccount:components.overview.widgets.consentManagement.header") }
description={ t("myAccount:components.overview.widgets.consentManagement.description") }
primaryAction={ t("myAccount:components.overview.widgets.consentManagement.actionTitles.manage") }
onPrimaryActionClick={ navigate }
onPrimaryActionClick={ () => {
navigate(AppConstants.getPaths().get("SECURITY") + "#" + CommonConstants.CONSENTS_CONTROL)
} }
icon={ getWidgetIcons().consents }
iconMini={ getWidgetIcons().consents }
iconSize="x60"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import isEmpty from "lodash-es/isEmpty";
import React, { FunctionComponent, ReactElement } from "react";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import { Progress } from "semantic-ui-react";
import { getWidgetIcons } from "../../../configs";
import { AppConstants, CommonConstants, UIConstants } from "../../../constants";
Expand Down Expand Up @@ -58,13 +59,10 @@ export const ProfileWidget: FunctionComponent<ProfileWidgetPropsInterface> = (

const { t } = useTranslation();
const { organizationDetails } = useThemeProvider();
const navigate = useNavigate();

const config: ConfigReducerStateInterface = useSelector((state: AppState) => state.config);

const navigate = () => {
history.push(AppConstants.getPaths().get("PERSONAL_INFO") + "#" + CommonConstants.PERSONAL_INFO);
};

const profileCompletion: ProfileCompletion = useSelector((state: AppState) => state.profile.completion);
const isReadOnlyUser: string = useSelector((state: AppState) => {
return state.authenticationInformation.profileInfo.isReadOnly;
Expand Down Expand Up @@ -163,7 +161,9 @@ export const ProfileWidget: FunctionComponent<ProfileWidgetPropsInterface> = (
? t("myAccount:components.overview.widgets.profileStatus.description")
: t("myAccount:components.overview.widgets.profileStatus.readOnlyDescription")
}
onPrimaryActionClick={ navigate }
onPrimaryActionClick={ () => {
navigate(AppConstants.getPaths().get("PERSONAL_INFO") + "#" + CommonConstants.PERSONAL_INFO);
} }
icon={ getWidgetIcons().profile }
iconMini={ getWidgetIcons().profile }
iconSize="x60"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import sortBy from "lodash-es/sortBy";
import React, { FunctionComponent, ReactElement, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";
import { Dispatch } from "redux";
import { Placeholder } from "semantic-ui-react";
import { fetchUserSessions } from "../../../api";
Expand All @@ -50,6 +51,7 @@ export const UserSessionsWidget: FunctionComponent<TestableComponentInterface> =
): ReactElement => {
const { ["data-testid"]: testId } = props;
const { t } = useTranslation();
const navigate = useNavigate();

const dispatch: Dispatch = useDispatch();

Expand Down Expand Up @@ -115,13 +117,6 @@ export const UserSessionsWidget: FunctionComponent<TestableComponentInterface> =
getUserSessions();
}, []);

/**
* Navigates to the Security page.
*/
const navigate = () => {
history.push(AppConstants.getPaths().get("SECURITY") + "#" + CommonConstants.ACCOUNT_ACTIVITY);
};

return (
<div className="widget account-status" data-testid={ testId }>
<SettingsSection
Expand All @@ -136,7 +131,9 @@ export const UserSessionsWidget: FunctionComponent<TestableComponentInterface> =
: null
}
primaryAction={ t("myAccount:components.overview.widgets.accountActivity.actionTitles.update") }
onPrimaryActionClick={ navigate }
onPrimaryActionClick={ () => {
navigate(AppConstants.getPaths().get("SECURITY") + "#" + CommonConstants.ACCOUNT_ACTIVITY);
} }
>
{ !isSessionDetailsLoading ? (
<UserSessionsList
Expand Down
27 changes: 27 additions & 0 deletions apps/myaccount/src/components/shared/global-history.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { NavigateFunction, useNavigate } from "react-router-dom";

export let globalNavigate: NavigateFunction;

export const GlobalHistory = () => {
globalNavigate = useNavigate();

return null;
};
13 changes: 8 additions & 5 deletions apps/myaccount/src/components/shared/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
handleAccountSwitching
} from "../../store/actions";
import { CommonUtils, refreshPage } from "../../utils";
import { useNavigate } from "react-router-dom";

/**
* Dashboard layout Prop types.
Expand Down Expand Up @@ -104,6 +105,7 @@ export const Header: FunctionComponent<HeaderPropsInterface> = (
>(null);

const { t } = useTranslation();
const navigate = useNavigate();

// TODO: Get this from profile reducer and cast `ProfileInfoInterface`.
const profileInfo: any = useSelector(
Expand Down Expand Up @@ -295,9 +297,6 @@ export const Header: FunctionComponent<HeaderPropsInterface> = (
!(CommonUtils?.isProfileReadOnly(isReadOnlyUser)) &&
consoleAppURL && consoleAppURL != "" ? (
<MenuItem
key={
t("myAccount:components.header.appSwitch.console.name")
}
onClick={ () => window.open(consoleAppURL, "_blank", "noopener") }>
<ListItemIcon>
<RectangleLineIcon fill="black" />
Expand Down Expand Up @@ -391,7 +390,7 @@ export const Header: FunctionComponent<HeaderPropsInterface> = (
)
},
onClick: () => {
history.push(AppConstants.getPaths().get("DASHBOARD"));
navigate(AppConstants.getPaths().get("DASHBOARD"));
},
title: theme?.images?.myAccountLogo?.title ?? config.ui.appName
} }
Expand Down Expand Up @@ -469,7 +468,11 @@ export const Header: FunctionComponent<HeaderPropsInterface> = (
))
],
onActionClick: () =>
history.push(AppConstants.getAppLogoutPath()),
{

navigate(AppConstants.getAppLogoutPath())
}
,
triggerOptions: {
"data-componentid": "app-header-user-avatar",
"data-testid": "app-header-user-avatar"
Expand Down
3 changes: 1 addition & 2 deletions apps/myaccount/src/components/shared/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2019, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* Copyright (c) 2019-2024, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand Down Expand Up @@ -28,7 +28,6 @@ export * from "./global-loader";
export * from "./icon";
export * from "./page-header";
export * from "./pre-loader";
export * from "./protected-route";
export * from "./settings-section";
export * from "./user-avatar";
export * from "./modal";
Loading
Loading