From 1b1ddb4728e0ad290aef58da9c2acf1c706b9e78 Mon Sep 17 00:00:00 2001 From: Filip Hlavac Date: Thu, 8 Jun 2023 23:28:38 +0200 Subject: [PATCH] Fix cancel/submit routes for group/role management --- src/smart-components/group/edit-group-modal.js | 5 ++--- src/smart-components/group/group.js | 12 ++++++------ src/smart-components/group/groups.js | 2 +- src/smart-components/group/remove-group-modal.js | 4 ++-- src/smart-components/role/edit-role-modal.js | 7 +++---- src/smart-components/role/remove-role-modal.js | 5 ++--- src/smart-components/role/role.js | 10 +++++----- .../smart-components/group/edit-group-modal.test.js | 2 +- .../group/remove-group-modal.test.js | 2 +- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/smart-components/group/edit-group-modal.js b/src/smart-components/group/edit-group-modal.js index d2351eaa4..1b97b00b8 100644 --- a/src/smart-components/group/edit-group-modal.js +++ b/src/smart-components/group/edit-group-modal.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; import { useIntl } from 'react-intl'; -import { useParams } from 'react-router-dom'; +import { useParams, useNavigate } from 'react-router-dom'; import PropTypes from 'prop-types'; import { Skeleton } from '@patternfly/react-core'; import { addNotification } from '@redhat-cloud-services/frontend-components-notifications/'; @@ -10,7 +10,6 @@ import validatorTypes from '@data-driven-forms/react-form-renderer/validator-typ import componentMapper from '@data-driven-forms/pf4-component-mapper/component-mapper'; import ModalFormTemplate from '../common/ModalFormTemplate'; import FormRenderer from '../common/form-renderer'; -import useAppNavigate from '../../hooks/useAppNavigate'; import { fetchGroup, updateGroup } from '../../redux/actions/group-actions'; import { debouncedAsyncValidator } from './validators'; import messages from '../../Messages'; @@ -20,7 +19,7 @@ const EditGroupModal = ({ postMethod, pagination, filters, cancelRoute, submitRo const intl = useIntl(); const [selectedGroup, setSelectedGroup] = useState(undefined); - const navigate = useAppNavigate(); + const navigate = useNavigate(); const { groupId } = useParams(); const setGroupData = (groupData) => { diff --git a/src/smart-components/group/group.js b/src/smart-components/group/group.js index 82d73096f..76444f696 100644 --- a/src/smart-components/group/group.js +++ b/src/smart-components/group/group.js @@ -249,8 +249,8 @@ const Group = ({ onDelete }) => { element={ dispatch(fetchGroups({ ...pagination, offset: 0, filters, usesMetaInURL: true }))} - cancelRoute={pathnames['group-detail-roles'].link.replace(':groupId', groupId)} - submitRoute={getBackRoute(pathnames.groups.link, { ...pagination, offset: 0 }, filters)} + cancelRoute={mergeToBasename(pathnames['group-detail-roles'].link.replace(':groupId', groupId))} + submitRoute={getBackRoute(mergeToBasename(pathnames.groups.link), { ...pagination, offset: 0 }, filters)} isModalOpen groupsUuid={[group]} /> @@ -261,7 +261,7 @@ const Group = ({ onDelete }) => { element={ dispatch(fetchGroup(fetchId))} /> } @@ -273,8 +273,8 @@ const Group = ({ onDelete }) => { element={ dispatch(fetchGroups({ ...pagination, offset: 0, filters, usesMetaInURL: true }))} - cancelRoute={pathnames['group-detail-members'].link.replace(':groupId', groupId)} - submitRoute={getBackRoute(pathnames.groups.link, { ...pagination, offset: 0 }, filters)} + cancelRoute={mergeToBasename(pathnames['group-detail-members'].link.replace(':groupId', groupId))} + submitRoute={getBackRoute(mergeToBasename(pathnames.groups.link), { ...pagination, offset: 0 }, filters)} isModalOpen groupsUuid={[group]} /> @@ -285,7 +285,7 @@ const Group = ({ onDelete }) => { element={ dispatch(fetchGroup(fetchId))} /> } diff --git a/src/smart-components/group/groups.js b/src/smart-components/group/groups.js index cbc19ab2e..cb532bdc0 100644 --- a/src/smart-components/group/groups.js +++ b/src/smart-components/group/groups.js @@ -206,7 +206,7 @@ const Groups = () => { props: { isDisabled: !(selectedRows.length === 1), }, - onClick: () => navigate(mergeToBasename(pathnames['edit-group'].link)).replace(':groupId', selectedRows[0].uuid), + onClick: () => navigate(mergeToBasename(pathnames['edit-group'].link.replace(':groupId', selectedRows[0].uuid))), }, { label: intl.formatMessage(messages.delete), diff --git a/src/smart-components/group/remove-group-modal.js b/src/smart-components/group/remove-group-modal.js index 054b08f4e..92009b581 100644 --- a/src/smart-components/group/remove-group-modal.js +++ b/src/smart-components/group/remove-group-modal.js @@ -4,10 +4,10 @@ import { FormattedMessage, useIntl } from 'react-intl'; import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { Button, Checkbox, Modal, ModalVariant, Text, TextContent } from '@patternfly/react-core'; import { ExclamationTriangleIcon } from '@patternfly/react-icons'; +import { useNavigate } from 'react-router-dom'; import { fetchGroup, removeGroups } from '../../redux/actions/group-actions'; import { FormItemLoader } from '../../presentational-components/shared/loader-placeholders'; import pathnames from '../../utilities/pathnames'; -import useAppNavigate from '../../hooks/useAppNavigate'; import messages from '../../Messages'; import './remove-group-modal.scss'; @@ -27,7 +27,7 @@ const RemoveGroupModal = ({ groupsUuid, isModalOpen, postMethod, pagination, fil } }, []); - const navigate = useAppNavigate(); + const navigate = useNavigate(); const [checked, setChecked] = useState(false); diff --git a/src/smart-components/role/edit-role-modal.js b/src/smart-components/role/edit-role-modal.js index ef9e5488e..151b47291 100644 --- a/src/smart-components/role/edit-role-modal.js +++ b/src/smart-components/role/edit-role-modal.js @@ -4,12 +4,11 @@ import componentTypes from '@data-driven-forms/react-form-renderer/component-typ import validatorTypes from '@data-driven-forms/react-form-renderer/validator-types'; import { addNotification } from '@redhat-cloud-services/frontend-components-notifications/'; import { useIntl } from 'react-intl'; +import { useParams, useNavigate } from 'react-router-dom'; +import { useDispatch, useSelector } from 'react-redux'; import ModalFormTemplate from '../common/ModalFormTemplate'; import FormRenderer from '../common/form-renderer'; -import useAppNavigate from '../../hooks/useAppNavigate'; import useIsMounted from '../../hooks/useIsMounted'; -import { useParams } from 'react-router-dom'; -import { useDispatch, useSelector } from 'react-redux'; import { roleSelector } from './role-selectors'; import { fetchRole, fetchRoles } from '../../helpers/role/role-helper'; import asyncDebounce from '../../utilities/async-debounce'; @@ -19,7 +18,7 @@ import messages from '../../Messages'; const EditRoleModal = ({ cancelRoute, submitRoute = cancelRoute, afterSubmit }) => { const intl = useIntl(); const isMounted = useIsMounted(); - const navigate = useAppNavigate(); + const navigate = useNavigate(); const dispatch = useDispatch(); const { roleId } = useParams(); diff --git a/src/smart-components/role/remove-role-modal.js b/src/smart-components/role/remove-role-modal.js index 27666f047..a17b96f17 100644 --- a/src/smart-components/role/remove-role-modal.js +++ b/src/smart-components/role/remove-role-modal.js @@ -1,11 +1,10 @@ import React, { useEffect, useState } from 'react'; import PropTypes from 'prop-types'; import { useDispatch, useSelector } from 'react-redux'; -import { useParams } from 'react-router-dom'; +import { useParams, useNavigate } from 'react-router-dom'; import { ExclamationTriangleIcon } from '@patternfly/react-icons'; import { Button, Checkbox, Modal, Text, TextContent, TextVariants, Split, SplitItem } from '@patternfly/react-core'; import { addNotification } from '@redhat-cloud-services/frontend-components-notifications/redux'; -import useAppNavigate from '../../hooks/useAppNavigate'; import { removeRole } from '../../redux/actions/role-actions'; import { fetchRole } from '../../helpers/role/role-helper'; import { roleNameSelector } from './role-selectors'; @@ -26,7 +25,7 @@ const RemoveRoleModal = ({ cancelRoute, submitRoute = cancelRoute, afterSubmit } const [isDisabled, setIsDisabled] = useState(true); const [internalRoleName, setInternalRoleName] = useState(roleName); const dispatch = useDispatch(); - const navigate = useAppNavigate(); + const navigate = useNavigate(); useEffect(() => { if (roles && roleName) { diff --git a/src/smart-components/role/role.js b/src/smart-components/role/role.js index 42945c448..d66791ab9 100644 --- a/src/smart-components/role/role.js +++ b/src/smart-components/role/role.js @@ -10,9 +10,9 @@ import useAppNavigate from '../../hooks/useAppNavigate'; import { fetchRole, fetchRolesWithPolicies } from '../../redux/actions/role-actions'; import { TopToolbar } from '../../presentational-components/shared/top-toolbar'; import { ListLoader } from '../../presentational-components/shared/loader-placeholders'; -import Permissions from './role-permissions'; import { fetchGroup, fetchRolesForGroup, fetchSystemGroup } from '../../redux/actions/group-actions'; import { ToolbarTitlePlaceholder } from '../../presentational-components/shared/loader-placeholders'; +import Permissions from './role-permissions'; import RemoveRoleModal from './remove-role-modal'; import EditRoleModal from './edit-role-modal'; import EmptyWithAction from '../../presentational-components/shared/empty-state'; @@ -135,7 +135,7 @@ const Role = ({ onDelete }) => { />, + {intl.formatMessage(messages.delete)} } @@ -183,8 +183,8 @@ const Role = ({ onDelete }) => { afterSubmit={() => { dispatch(fetchRolesWithPolicies({ ...rolesPagination, offset: 0, filters: rolesFilters, usesMetaInURL: true })); }} - cancelRoute={pathnames['role-detail'].link.replace(':roleId', roleId)} - submitRoute={getBackRoute(pathnames.roles.link, { ...rolesPagination, offset: 0 }, rolesFilters)} + cancelRoute={pathnames['role-detail'].path.replace(':roleId', roleId)} + submitRoute={getBackRoute(mergeToBasename(pathnames['roles'].link), { ...rolesPagination, offset: 0 }, rolesFilters)} routeMatch={pathnames['role-detail-remove'].path} /> )} @@ -198,7 +198,7 @@ const Role = ({ onDelete }) => { {!isRecordLoading && ( )} diff --git a/src/test/smart-components/group/edit-group-modal.test.js b/src/test/smart-components/group/edit-group-modal.test.js index 6d798cdc0..f177802f1 100644 --- a/src/test/smart-components/group/edit-group-modal.test.js +++ b/src/test/smart-components/group/edit-group-modal.test.js @@ -95,6 +95,6 @@ describe('', () => { }); wrapper.update(); wrapper.find('button').first().simulate('click'); - expect(mockedNavigate).toHaveBeenCalledWith('/iam/user-access/groups', undefined); + expect(mockedNavigate).toHaveBeenCalledWith('/groups'); }); }); diff --git a/src/test/smart-components/group/remove-group-modal.test.js b/src/test/smart-components/group/remove-group-modal.test.js index 7bfb53a8a..5b900c7d3 100644 --- a/src/test/smart-components/group/remove-group-modal.test.js +++ b/src/test/smart-components/group/remove-group-modal.test.js @@ -90,7 +90,7 @@ describe('', () => { const wrapper = mount(); wrapper.find(Button).last().simulate('click'); - expect(mockedNavigate).toHaveBeenCalledWith('/iam/user-access/groups', undefined); + expect(mockedNavigate).toHaveBeenCalledWith('/groups'); }); it('should call the remove action', async () => {