[MM-48184] Disallow edit/remove server if it is imported from GPO (#2353)

* Disallow edit/remove server if it is imported from GPO

* Fix width issue of team dropdown
This commit is contained in:
Tasos Boulis
2022-11-04 17:58:21 +02:00
committed by GitHub
parent 935cf3a0cc
commit c319038704
5 changed files with 92 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ import {FormattedMessage} from 'react-intl';
import classNames from 'classnames';
import {DragDropContext, Draggable, DraggingStyle, Droppable, DropResult, NotDraggingStyle} from 'react-beautiful-dnd';
import {Team, TeamWithTabs} from 'types/config';
import {Team, TeamWithTabs, TeamWithTabsAndGpo} from 'types/config';
import {
CLOSE_TEAMS_DROPDOWN,
@@ -27,8 +27,8 @@ import './css/dropdown.scss';
import IntlProvider from './intl_provider';
type State = {
teams?: TeamWithTabs[];
orderedTeams?: TeamWithTabs[];
teams?: TeamWithTabsAndGpo[];
orderedTeams?: TeamWithTabsAndGpo[];
activeTeam?: string;
darkMode?: boolean;
enableServerManagement?: boolean;
@@ -212,22 +212,32 @@ class TeamDropdown extends React.PureComponent<Record<string, never>, State> {
}
}
editServer = (team: string) => {
editServer = (teamName: string) => {
if (this.teamIsGpo(teamName)) {
return () => {};
}
return (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
window.postMessage({type: SHOW_EDIT_SERVER_MODAL, data: {name: team}}, window.location.href);
window.postMessage({type: SHOW_EDIT_SERVER_MODAL, data: {name: teamName}}, window.location.href);
this.closeMenu();
};
}
removeServer = (team: string) => {
removeServer = (teamName: string) => {
if (this.teamIsGpo(teamName)) {
return () => {};
}
return (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
window.postMessage({type: SHOW_REMOVE_SERVER_MODAL, data: {name: team}}, window.location.href);
window.postMessage({type: SHOW_REMOVE_SERVER_MODAL, data: {name: teamName}}, window.location.href);
this.closeMenu();
};
}
teamIsGpo = (teamName: string) => {
return this.state.orderedTeams?.some((team) => team.name === teamName && team.isGpo);
}
render() {
return (
<IntlProvider>
@@ -326,7 +336,7 @@ class TeamDropdown extends React.PureComponent<Record<string, never>, State> {
{this.isActiveTeam(team) ? <i className='icon-check'/> : <i className='icon-server-variant'/>}
<span>{team.name}</span>
</div>
<div className='TeamDropdown__indicators'>
{!team.isGpo && <div className='TeamDropdown__indicators'>
<button
className='TeamDropdown__button-edit'
onClick={this.editServer(team.name)}
@@ -342,7 +352,7 @@ class TeamDropdown extends React.PureComponent<Record<string, never>, State> {
{badgeDiv && <div className='TeamDropdown__badge'>
{badgeDiv}
</div>}
</div>
</div>}
</button>
)}
</Draggable>