Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

[Web Portal] Redesign batch edit behavior #3172

Merged
merged 1 commit into from
Jul 11, 2019
Merged
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
33 changes: 20 additions & 13 deletions src/webportal/src/app/user/fabric/userView/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import React, {useContext, useMemo} from 'react';

import {ShimmeredDetailsList, Selection, FontClassNames, ColumnActionsMode, DefaultButton, mergeStyles} from 'office-ui-fabric-react';
import {ShimmeredDetailsList, Selection, FontClassNames, ColumnActionsMode, DefaultButton, mergeStyles, TooltipHost} from 'office-ui-fabric-react';

import c from 'classnames';
import t from '../../../components/tachyons.scss';
Expand All @@ -28,7 +28,7 @@ import Context from './Context';
import Ordering from './Ordering';

export default function Table() {
const {allUsers, filteredUsers, filter, ordering, setOrdering, pagination, setSelectedUsers, setAllSelected, editUser} = useContext(Context);
const {allUsers, filteredUsers, filter, ordering, setOrdering, pagination, setSelectedUsers, setAllSelected, editUser, getSelectedUsers} = useContext(Context);
/**
* @type {import('office-ui-fabric-react').Selection}
*/
Expand Down Expand Up @@ -136,19 +136,26 @@ export default function Table() {
event.stopPropagation();
editUser(user);
}

const disabled = getSelectedUsers().length > 1;
const disabledTip = disabled ? 'Multi-user simultaneous editing is not supported' : '';

return (
<div className={c([t.itemsCenter, t.flex])} data-selection-disabled>
<DefaultButton
onClick={onClick}
styles={{
root: {backgroundColor: '#e5e5e5'},
rootFocused: {backgroundColor: '#e5e5e5'},
rootDisabled: {backgroundColor: '#eeeeee'},
rootCheckedDisabled: {backgroundColor: '#eeeeee'},
}}
>
Edit
</DefaultButton>
<TooltipHost content={disabledTip}>
<DefaultButton
disabled={disabled}
onClick={onClick}
styles={{
root: {backgroundColor: '#e5e5e5'},
rootFocused: {backgroundColor: '#e5e5e5'},
rootDisabled: {backgroundColor: '#eeeeee'},
rootCheckedDisabled: {backgroundColor: '#eeeeee'},
}}
>
Edit
</DefaultButton>
</TooltipHost>
</div>
);
},
Expand Down
50 changes: 41 additions & 9 deletions src/webportal/src/app/user/fabric/userView/TopBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import React, {useContext, useState} from 'react';

import {CommandBarButton, SearchBox, CommandBar, ContextualMenuItemType, ColorClassNames, getTheme} from 'office-ui-fabric-react';
import {CommandBarButton, SearchBox, CommandBar, ContextualMenuItemType, ColorClassNames, getTheme, TooltipHost} from 'office-ui-fabric-react';
import {PropTypes} from 'prop-types';
import {findIndex} from 'lodash';

Expand Down Expand Up @@ -103,6 +103,21 @@ function TopBar() {
iconName: 'UserRemove',
},
onClick: removeUsers,
onRender(item) {
return (
<TooltipHost content={item.disabledTip} styles={{root: {display: 'inherit'}}}>
<CommandBarButton
onClick={item.onClick}
iconProps={item.iconProps}
menuIconProps={item.menuIconProps}
styles={transparentStyles}
disabled={item.disabled}
>
{item.name}
</CommandBarButton>
</TooltipHost>
);
},
};

/**
Expand Down Expand Up @@ -144,6 +159,21 @@ function TopBar() {
iconName: 'FullWidthEdit',
},
onClick: showBatchVirtualClustersEditor,
onRender(item) {
return (
<TooltipHost content={item.disabledTip} styles={{root: {display: 'inherit'}}}>
<CommandBarButton
onClick={item.onClick}
iconProps={item.iconProps}
menuIconProps={item.menuIconProps}
styles={transparentStyles}
disabled={item.disabled}
>
{item.name}
</CommandBarButton>
</TooltipHost>
);
},
};

/**
Expand Down Expand Up @@ -350,20 +380,22 @@ function TopBar() {
const selectedAdmin = findIndex(selectedUsers, (user) => user.admin) != -1;
if (selected) {
if (selectedMulti) {
topBarItems.push(btnBatchEditPassword);
if (selectedAdmin) {
topBarItems.push(Object.assign(btnBatchEditPassword, {disabled: true}));
topBarItems.push(Object.assign(btnBatchEditVirtualClusters, {disabled: true}));
const disabledTip = 'Unable to do this for administrators, please make sure the multi-option does not include an administrator';
topBarItems.push(Object.assign(btnBatchEditVirtualClusters, {disabled: true, disabledTip}));
topBarItems.push(Object.assign(btnRemove, {disabled: true, disabledTip}));
} else {
topBarItems.push(btnBatchEditPassword);
topBarItems.push(btnBatchEditVirtualClusters);
topBarItems.push(btnRemove);
}
} else {
topBarItems.push(btnEdit);
}
if (selectedAdmin) {
topBarItems.push(Object.assign(btnRemove, {disabled: true}));
} else {
topBarItems.push(btnRemove);
if (selectedAdmin) {
topBarItems.push(Object.assign(btnRemove, {disabled: true, disabledTip: 'The administrator could not be removed'}));
} else {
topBarItems.push(btnRemove);
}
}
} else {
topBarItems.push(btnAddUser);
Expand Down