Skip to content

Commit

Permalink
fix: init
Browse files Browse the repository at this point in the history
  • Loading branch information
fhlavac committed Dec 16, 2024
1 parent 999361a commit 78b8e42
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 54 deletions.
8 changes: 6 additions & 2 deletions locales/translation-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -1739,8 +1739,8 @@
"description": "Add label"
},
"usersAndUserGroupsAddToGroup": {
"defaultMessage": "Remove from user group",
"description": "Remove from user group label"
"defaultMessage": "Add to user group",
"description": "Add to user group label"
},
"usersAndUserGroupsAddUserDescription": {
"defaultMessage": "Select a user group to add <b>{numUsers} {plural}</b> to. These are all the user groups in your account. To manage user groups, go to user groups.",
Expand Down Expand Up @@ -1774,6 +1774,10 @@
"defaultMessage": "No description",
"description": "No description label"
},
"usersAndUserGroupsRemoveFromGroup": {
"defaultMessage": "Remove from user group",
"description": "Remove from user group label"
},
"usersAndUserGroupsYes": {
"defaultMessage": "Yes",
"description": "Yes is Org Admin label"
Expand Down
2 changes: 1 addition & 1 deletion src/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ export default defineMessages({
defaultMessage: 'Delete user group',
},
usersAndUserGroupsRemoveFromGroup: {
id: 'usersAndUserGroupsAddToGroup',
id: 'usersAndUserGroupsRemoveFromGroup',
description: 'Remove from user group label',
defaultMessage: 'Remove from user group',
},
Expand Down
22 changes: 19 additions & 3 deletions src/Routing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,25 @@ const getRoutes = ({ enableServiceAccounts, isITLess, isWorkspacesFlag, isCommon
path: pathnames['users-and-user-groups'].path,
element: UsersAndUserGroups,
childRoutes: [
isCommonAuthModel && {
path: pathnames['invite-group-users'].path,
element: InviteUsersModalCommonAuth,
{
path: pathnames['users-new'].path,
element: AddGroupWizard,
childRoutes: [
isCommonAuthModel && {
path: pathnames['invite-group-users'].path,
element: InviteUsersModalCommonAuth,
},
],
},
{
path: pathnames['user-groups'].path,
element: AddGroupWizard,
childRoutes: [
{
path: pathnames['create-user-group'].path,
element: AddGroupWizard,
},
],
},
],
},
Expand Down
3 changes: 2 additions & 1 deletion src/locales/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
"usersAndUserGroups": "Users and User Groups",
"usersAndUserGroupsActive": "Active",
"usersAndUserGroupsAdd": "Add",
"usersAndUserGroupsAddToGroup": "Remove from user group",
"usersAndUserGroupsAddToGroup": "Add to user group",
"usersAndUserGroupsAddUserDescription": "Select a user group to add <b>{numUsers} {plural}</b> to. These are all the user groups in your account. To manage user groups, go to user groups.",
"usersAndUserGroupsCancel": "Cancel",
"usersAndUserGroupsDeleteUserGroup": "Delete user group",
Expand All @@ -444,6 +444,7 @@
"usersAndUserGroupsInactive": "Inactive",
"usersAndUserGroupsNo": "No",
"usersAndUserGroupsNoDescription": "No description",
"usersAndUserGroupsRemoveFromGroup": "Remove from user group",
"usersAndUserGroupsYes": "Yes",
"usersDescription": "These are all of the users in your Red Hat organization.",
"usersEmptyStateSubtitle": "This filter criteria matches no users.{br}Try changing your filter input.",
Expand Down
6 changes: 5 additions & 1 deletion src/locales/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@
"createRoleErrorTitle": "Failed adding role",
"createRoleFromScratch": "Create a role from scratch",
"createUserGroup": "Create user group",
<<<<<<< Updated upstream
"createWorkspace": "Create workspace",
"createWorkspaceErrorDescription": "The workspace was not created successfuly.",
"createWorkspaceErrorTitle": "Failed creating {name} workspace",
"createWorkspaceSuccessTitle": "New {name} workspace have been successfully created",
=======
>>>>>>> Stashed changes
"creatingGroup": "Creating a group",
"creatingRoleCanceled": "Creating role was canceled by the user",
"deactivateUsersButton": "Deactivate users",
Expand Down Expand Up @@ -434,7 +437,7 @@
"usersAndUserGroups": "Users and User Groups",
"usersAndUserGroupsActive": "Active",
"usersAndUserGroupsAdd": "Add",
"usersAndUserGroupsAddToGroup": "Remove from user group",
"usersAndUserGroupsAddToGroup": "Add to user group",
"usersAndUserGroupsAddUserDescription": "Select a user group to add <b>{numUsers} {plural}</b> to. These are all the user groups in your account. To manage user groups, go to user groups.",
"usersAndUserGroupsCancel": "Cancel",
"usersAndUserGroupsDeleteUserGroup": "Delete user group",
Expand All @@ -443,6 +446,7 @@
"usersAndUserGroupsInactive": "Inactive",
"usersAndUserGroupsNo": "No",
"usersAndUserGroupsNoDescription": "No description",
"usersAndUserGroupsRemoveFromGroup": "Remove from user group",
"usersAndUserGroupsYes": "Yes",
"usersDescription": "These are all of the users in your Red Hat organization.",
"usersEmptyStateSubtitle": "This filter criteria matches no users.{br}Try changing your filter input.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { addMembersToGroup } from '../../redux/actions/group-actions';
import { FormattedMessage, useIntl } from 'react-intl';
import messages from '../../Messages';

interface AddUserGroupModalProps {
interface AddUserToGroupModalProps {
isOpen: boolean;
setIsOpen: (isOpen: boolean) => void;
selectedUsers: any[];
}

export const AddUserGroupModal: React.FunctionComponent<AddUserGroupModalProps> = ({ isOpen, setIsOpen, selectedUsers }) => {
export const AddUserToGroupModal: React.FunctionComponent<AddUserToGroupModalProps> = ({ isOpen, setIsOpen, selectedUsers }) => {
const [selectedGroups, setSelectedGroups] = React.useState<any[]>([]);
const handleUserGroupsChange = (groups: any[]) => setSelectedGroups(groups);
const dispatch = useDispatch();
Expand Down Expand Up @@ -62,4 +62,4 @@ export const AddUserGroupModal: React.FunctionComponent<AddUserGroupModalProps>
);
};

export default AddUserGroupModal;
export default AddUserToGroupModal;
38 changes: 28 additions & 10 deletions src/smart-components/access-management/UserGroupsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useCallback, useMemo, useState, Fragment } from 'react';
import React, { useEffect, useCallback, useMemo, useState, Fragment, Suspense } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useDataViewSelection, useDataViewPagination } from '@patternfly/react-data-view/dist/dynamic/Hooks';
import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
Expand All @@ -9,7 +9,7 @@ import { ButtonVariant, EmptyState, EmptyStateBody, EmptyStateHeader, EmptyState
import { ActionsColumn } from '@patternfly/react-table';
import { mappedProps } from '../../helpers/shared/helpers';
import { RBACStore } from '../../redux/store';
import { useSearchParams } from 'react-router-dom';
import { Outlet, useSearchParams } from 'react-router-dom';
import { fetchGroups, removeGroups } from '../../redux/actions/group-actions';
import { formatDistanceToNow } from 'date-fns';
import { FormattedMessage, useIntl } from 'react-intl';
Expand All @@ -18,7 +18,8 @@ import { Group } from '../../redux/reducers/group-reducer';
import { DataViewTrObject, DataViewState, EventTypes, useDataViewEventsContext } from '@patternfly/react-data-view';
import { SearchIcon } from '@patternfly/react-icons';
import { ResponsiveAction, ResponsiveActions, SkeletonTableBody, WarningModal } from '@patternfly/react-component-groups';
import AddGroupWizard from '../group/add-group/add-group-wizard';
import pathnames from '../../utilities/pathnames';
import useAppNavigate from '../../hooks/useAppNavigate';

const COLUMNS: string[] = ['User group name', 'Description', 'Users', 'Service accounts', 'Roles', 'Workspaces', 'Last modified'];

Expand Down Expand Up @@ -48,11 +49,11 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({
focusedGroup,
}) => {
const [isDeleteModalOpen, setIsDeleteModalOpen] = React.useState(false);
const [isAddGroupWizardOpen, setIsAddGroupWizardOpen] = React.useState(false);
const [currentGroups, setCurrentGroups] = React.useState<Group[]>([]);
const dispatch = useDispatch();
const [activeState, setActiveState] = useState<DataViewState | undefined>(DataViewState.loading);
const intl = useIntl();
const navigate = useAppNavigate();
const { trigger } = useDataViewEventsContext();

const handleDeleteModalToggle = (groups: Group[]) => {
Expand Down Expand Up @@ -229,11 +230,6 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({

return (
<Fragment>
{isAddGroupWizardOpen && (
<div data-ouia-component-id="add-group-wizard">
<AddGroupWizard pagination={{ limit: 20 }} filters={{}} enableRoles={false} setIsWizardOpen={setIsAddGroupWizardOpen} />
</div>
)}
{isDeleteModalOpen && (
<WarningModal
ouiaId={`${ouiaId}-remove-user-modal`}
Expand Down Expand Up @@ -275,7 +271,7 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({
}
actions={
<ResponsiveActions breakpoint="lg" ouiaId={`${ouiaId}-actions-dropdown`}>
<ResponsiveAction isPinned isPersistent onClick={() => setIsAddGroupWizardOpen(true)}>
<ResponsiveAction isPinned isPersistent onClick={() => navigate(pathnames['create-user-group'].link)}>
{intl.formatMessage(messages.createUserGroup)}
</ResponsiveAction>
<ResponsiveAction
Expand Down Expand Up @@ -306,6 +302,28 @@ const UserGroupsTable: React.FunctionComponent<UserGroupsTableProps> = ({
/>
<DataViewToolbar ouiaId={`${ouiaId}-footer-toolbar`} pagination={paginationComponent} />
</DataView>
<Suspense>
<Outlet
context={{
[pathnames['create-user-group'].path]: {
afterSubmit: () => {
navigate({
pathname: pathnames['users-and-user-groups'].link,
search: '?activeTab=user-groups',
});
},
onCancel: () =>
navigate({
pathname: pathnames['users-and-user-groups'].link,
search: '?activeTab=user-groups',
}),
enableRoles: false,
pagination: { limit: 20 },
filters: {},
},
}}
/>
</Suspense>
</Fragment>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/smart-components/access-management/UsersTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ const UsersTable: React.FunctionComponent<UsersTableProps> = ({ onAddUserClick,
<Suspense>
<Outlet
context={{
bar: 'foo',
fetchData: () => {
appNavigate(paths['users-and-user-groups'].link);
},
Expand Down
47 changes: 24 additions & 23 deletions src/smart-components/access-management/users-and-user-groups.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import React, { useEffect } from 'react';
import { useIntl } from 'react-intl';
import { PageSection, PageSectionVariants, Tab, TabContent, Tabs } from '@patternfly/react-core';
import { PageSection, PageSectionVariants, Tab, Tabs } from '@patternfly/react-core';
import ContentHeader from '@patternfly/react-component-groups/dist/dynamic/ContentHeader';
import Messages from '../../Messages';
import UsersTable from './UsersTable';
import UserGroupsTable from './UserGroupsTable';
import { useLocation, useNavigate } from 'react-router-dom';
import AddUserGroupModal from './AddUserGroupModal';
// import UsersTable from './UsersTable';
// import UserGroupsTable from './UserGroupsTable';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { User } from '../../redux/reducers/user-reducer';
import { Group } from '../../redux/reducers/group-reducer';
import GroupDetailsDrawer from './GroupDetailsDrawer';
import { DataViewEventsProvider } from '@patternfly/react-data-view';
import UserDetailsDrawer from './UserDetailsDrawer';
// import { Group } from '../../redux/reducers/group-reducer';
// import GroupDetailsDrawer from './GroupDetailsDrawer';
// import { DataViewEventsProvider } from '@patternfly/react-data-view';
// import UserDetailsDrawer from './UserDetailsDrawer';
import AddUserToGroupModal from './AddUserToGroupModal';

const TAB_NAMES = ['users', 'user-groups'];

const UsersAndUserGroups: React.FunctionComponent = () => {
const intl = useIntl();
const [activeTabKey, setActiveTabKey] = React.useState<number>(0);
const [isAddUserGroupModalOpen, setIsAddUserGroupModalOpen] = React.useState<boolean>(false);
const [selectedUsers, setSelectedUsers] = React.useState<User[]>([]);
const [focusedUser, setFocusedUser] = React.useState<User | undefined>(undefined);
const [focusedGroup, setFocusedGroup] = React.useState<Group | undefined>(undefined);
const [isAddUserToGroupModalOpen, setIsAddUserToGroupModalOpen] = React.useState<boolean>(false);
const [selectedUsers] = React.useState<User[]>([]);
// const [focusedUser, setFocusedUser] = React.useState<User | undefined>(undefined);
// const [focusedGroup, setFocusedGroup] = React.useState<Group | undefined>(undefined);
const usersRef = React.createRef<HTMLElement>();
const groupsRef = React.createRef<HTMLElement>();

Expand All @@ -40,12 +40,12 @@ const UsersAndUserGroups: React.FunctionComponent = () => {
updateURL(TAB_NAMES[activeTab]);
};

const handleOpenAddUserModal = (selected: User[]) => {
if (selected.length > 0) {
setSelectedUsers(selected);
setIsAddUserGroupModalOpen(true);
}
};
// const handleOpenAddUserToGroupModal = (selected: User[]) => {
// if (selected.length > 0) {
// setSelectedUsers(selected);
// setIsAddUserToGroupModalOpen(true);
// }
// };

useEffect(() => {
const params = new URLSearchParams(location.search);
Expand All @@ -55,7 +55,7 @@ const UsersAndUserGroups: React.FunctionComponent = () => {

return (
<React.Fragment>
<AddUserGroupModal isOpen={isAddUserGroupModalOpen} setIsOpen={setIsAddUserGroupModalOpen} selectedUsers={selectedUsers} />
<AddUserToGroupModal isOpen={isAddUserToGroupModalOpen} setIsOpen={setIsAddUserToGroupModalOpen} selectedUsers={selectedUsers} />
<ContentHeader title={intl.formatMessage(Messages.usersAndUserGroups)} subtitle={intl.formatMessage(Messages.usersAndUserGroupsDescription)} />
<PageSection type="tabs" variant={PageSectionVariants.light} isWidthLimited>
<Tabs
Expand All @@ -80,11 +80,11 @@ const UsersAndUserGroups: React.FunctionComponent = () => {
</Tabs>
</PageSection>
<PageSection padding={{ default: 'noPadding' }}>
{activeTabKey === 0 && (
{/* {activeTabKey === 0 && (
<DataViewEventsProvider>
<UserDetailsDrawer ouiaId="user-details-drawer" setFocusedUser={setFocusedUser} focusedUser={focusedUser}>
<TabContent eventKey={0} id="usersTab" ref={usersRef} aria-label="Users tab">
<UsersTable onAddUserClick={handleOpenAddUserModal} focusedUser={focusedUser} />
<UsersTable onAddUserClick={handleOpenAddUserToGroupModal} focusedUser={focusedUser} />
</TabContent>
</UserDetailsDrawer>
</DataViewEventsProvider>
Expand All @@ -97,7 +97,8 @@ const UsersAndUserGroups: React.FunctionComponent = () => {
</TabContent>
</GroupDetailsDrawer>
</DataViewEventsProvider>
)}
)} */}
<Outlet />
</PageSection>
</React.Fragment>
);
Expand Down
3 changes: 2 additions & 1 deletion src/smart-components/group/add-group/add-group-wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const onCancel = (emptyCallback, nonEmptyCallback, setGroupData) => (form
}
};

const AddGroupWizard = ({ postMethod, pagination, filters, orderBy, enableRoles = true, setIsWizardOpen }) => {
const AddGroupWizard = ({ postMethod, pagination, filters, orderBy, enableRoles = true, setIsWizardOpen, ...rest }) => {
const dispatch = useDispatch();
const intl = useIntl();
const container = useRef(document.createElement('div'));
Expand All @@ -74,6 +74,7 @@ const AddGroupWizard = ({ postMethod, pagination, filters, orderBy, enableRoles
error: undefined,
hideForm: false,
});
console.log('pagination', pagination, enableRoles, rest);

const redirectToGroups = () => {
dispatch(
Expand Down
2 changes: 2 additions & 0 deletions src/smart-components/group/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ const Group = () => {
const [showDefaultGroupChangedInfo, setShowDefaultGroupChangedInfo] = useState(false);

useEffect(() => {
console.log('AAA2');
dispatch(fetchSystemGroup({ chrome }));
const currId = !isPlatformDefault ? groupId : systemGroupUuid;
if (currId) {
console.log('BBB2', isPlatformDefault, currId, groupId, systemGroupUuid);
dispatch(fetchGroup(currId));
chrome.appObjectId(currId);
}
Expand Down
12 changes: 7 additions & 5 deletions src/smart-components/group/role/add-group-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ const AddGroupRoles = ({

const onSubmit = () => {
const rolesList = selectedRoles.map((role) => role.uuid);
if (isDefault && !isChanged) {
onDefaultGroupChanged(true);
dispatch(invalidateSystemGroup());
}
addRolesToGroup(groupId, rolesList).then(afterSubmit);
addRolesToGroup(groupId, rolesList).then(() => {
if (isDefault && !isChanged) {
onDefaultGroupChanged(true);
dispatch(invalidateSystemGroup());
}
afterSubmit();
});
setSelectedRoles([]);
return navigate(closeUrl);
};
Expand Down
Loading

0 comments on commit 78b8e42

Please sign in to comment.