Fix types so the store can return undefined teams (#26386)
* Fix types so the store can return undefined teams * Fix post test * fix snapshots * Address feedback
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7b90b7c2e0
Коммит
d0a67cd84a
@@ -50,7 +50,21 @@ exports[`admin_console/team_channel_settings/channel/ChannelDetails should match
|
||||
onToggleArchive={[Function]}
|
||||
team={
|
||||
Object {
|
||||
"allow_open_invite": false,
|
||||
"allowed_domains": "",
|
||||
"company_name": "",
|
||||
"create_at": 0,
|
||||
"delete_at": 0,
|
||||
"description": "",
|
||||
"display_name": "test",
|
||||
"email": "",
|
||||
"group_constrained": false,
|
||||
"id": "team_id",
|
||||
"invite_id": "",
|
||||
"name": "DN",
|
||||
"scheme_id": "id",
|
||||
"type": "O",
|
||||
"update_at": 0,
|
||||
}
|
||||
}
|
||||
/>
|
||||
@@ -235,7 +249,6 @@ exports[`admin_console/team_channel_settings/channel/ChannelDetails should match
|
||||
isArchived={false}
|
||||
isDisabled={false}
|
||||
onToggleArchive={[Function]}
|
||||
team={Object {}}
|
||||
/>
|
||||
<ConfirmModal
|
||||
confirmButtonClass="btn btn-primary"
|
||||
@@ -420,7 +433,21 @@ exports[`admin_console/team_channel_settings/channel/ChannelDetails should match
|
||||
onToggleArchive={[Function]}
|
||||
team={
|
||||
Object {
|
||||
"allow_open_invite": false,
|
||||
"allowed_domains": "",
|
||||
"company_name": "",
|
||||
"create_at": 0,
|
||||
"delete_at": 0,
|
||||
"description": "",
|
||||
"display_name": "test",
|
||||
"email": "",
|
||||
"group_constrained": false,
|
||||
"id": "team_id",
|
||||
"invite_id": "",
|
||||
"name": "DN",
|
||||
"scheme_id": "id",
|
||||
"type": "O",
|
||||
"update_at": 0,
|
||||
}
|
||||
}
|
||||
/>
|
||||
@@ -557,7 +584,6 @@ exports[`admin_console/team_channel_settings/channel/ChannelDetails should match
|
||||
isArchived={false}
|
||||
isDisabled={false}
|
||||
onToggleArchive={[Function]}
|
||||
team={Object {}}
|
||||
/>
|
||||
<ConfirmModal
|
||||
confirmButtonClass="btn btn-primary"
|
||||
@@ -694,7 +720,21 @@ exports[`admin_console/team_channel_settings/channel/ChannelDetails should match
|
||||
onToggleArchive={[Function]}
|
||||
team={
|
||||
Object {
|
||||
"allow_open_invite": false,
|
||||
"allowed_domains": "",
|
||||
"company_name": "",
|
||||
"create_at": 0,
|
||||
"delete_at": 0,
|
||||
"description": "",
|
||||
"display_name": "test",
|
||||
"email": "",
|
||||
"group_constrained": false,
|
||||
"id": "team_id",
|
||||
"invite_id": "",
|
||||
"name": "DN",
|
||||
"scheme_id": "id",
|
||||
"type": "O",
|
||||
"update_at": 0,
|
||||
}
|
||||
}
|
||||
/>
|
||||
@@ -831,7 +871,6 @@ exports[`admin_console/team_channel_settings/channel/ChannelDetails should match
|
||||
isArchived={false}
|
||||
isDisabled={false}
|
||||
onToggleArchive={[Function]}
|
||||
team={Object {}}
|
||||
/>
|
||||
<ConfirmModal
|
||||
confirmButtonClass="btn btn-primary"
|
||||
|
||||
@@ -7,7 +7,8 @@ import React from 'react';
|
||||
import type {Channel} from '@mattermost/types/channels';
|
||||
import type {Group} from '@mattermost/types/groups';
|
||||
import type {Scheme} from '@mattermost/types/schemes';
|
||||
import type {Team} from '@mattermost/types/teams';
|
||||
|
||||
import {TestHelper} from 'utils/test_helper';
|
||||
|
||||
import ChannelDetails from './channel_details';
|
||||
|
||||
@@ -49,9 +50,9 @@ describe('admin_console/team_channel_settings/channel/ChannelDetails', () => {
|
||||
scheme_id: 'id',
|
||||
group_constrained: false,
|
||||
};
|
||||
const team: Partial<Team> = {
|
||||
const team = TestHelper.getTeamMock({
|
||||
display_name: 'test',
|
||||
};
|
||||
});
|
||||
const teamScheme: Scheme = {
|
||||
id: 'asdf',
|
||||
name: 'asdf',
|
||||
@@ -125,7 +126,7 @@ describe('admin_console/team_channel_settings/channel/ChannelDetails', () => {
|
||||
<ChannelDetails
|
||||
teamScheme={teamScheme}
|
||||
groups={groups}
|
||||
team={{}}
|
||||
team={undefined}
|
||||
totalGroups={groups.length}
|
||||
actions={actions}
|
||||
channel={testChannel}
|
||||
@@ -173,9 +174,9 @@ describe('admin_console/team_channel_settings/channel/ChannelDetails', () => {
|
||||
scheme_id: 'id',
|
||||
group_constrained: false,
|
||||
};
|
||||
const team: Partial<Team> = {
|
||||
const team = TestHelper.getTeamMock({
|
||||
display_name: 'test',
|
||||
};
|
||||
});
|
||||
const teamScheme: Scheme = {
|
||||
id: 'asdf',
|
||||
name: 'asdf',
|
||||
@@ -249,7 +250,7 @@ describe('admin_console/team_channel_settings/channel/ChannelDetails', () => {
|
||||
<ChannelDetails
|
||||
teamScheme={teamScheme}
|
||||
groups={groups}
|
||||
team={{}}
|
||||
team={undefined}
|
||||
totalGroups={groups.length}
|
||||
actions={actions}
|
||||
channel={testChannel}
|
||||
@@ -298,9 +299,9 @@ describe('admin_console/team_channel_settings/channel/ChannelDetails', () => {
|
||||
scheme_id: 'id',
|
||||
group_constrained: false,
|
||||
};
|
||||
const team: Partial<Team> = {
|
||||
const team = TestHelper.getTeamMock({
|
||||
display_name: 'test',
|
||||
};
|
||||
});
|
||||
const teamScheme: Scheme = {
|
||||
id: 'asdf',
|
||||
name: 'asdf',
|
||||
@@ -374,7 +375,7 @@ describe('admin_console/team_channel_settings/channel/ChannelDetails', () => {
|
||||
<ChannelDetails
|
||||
teamScheme={teamScheme}
|
||||
groups={groups}
|
||||
team={{}}
|
||||
team={undefined}
|
||||
totalGroups={groups.length}
|
||||
actions={actions}
|
||||
channel={testChannel}
|
||||
|
||||
@@ -41,7 +41,7 @@ import SaveChangesPanel from '../../save_changes_panel';
|
||||
export interface ChannelDetailsProps {
|
||||
channelID: string;
|
||||
channel: Channel;
|
||||
team: Partial<Team>;
|
||||
team?: Team;
|
||||
groups: Group[];
|
||||
totalGroups: number;
|
||||
allGroups: Record<string, Group>;
|
||||
@@ -145,7 +145,7 @@ export default class ChannelDetails extends React.PureComponent<ChannelDetailsPr
|
||||
}
|
||||
|
||||
// If we don't have the team and channel on mount, we need to request the team after we load the channel
|
||||
if (!prevProps.team.id && !prevProps.channel.team_id && channel.team_id) {
|
||||
if (!prevProps.team?.id && !prevProps.channel.team_id && channel.team_id) {
|
||||
actions.getTeam(channel.team_id).
|
||||
then(async (data: any) => {
|
||||
if (data.data && data.data.scheme_id) {
|
||||
|
||||
@@ -5,13 +5,14 @@ import {shallow} from 'enzyme';
|
||||
import React from 'react';
|
||||
|
||||
import type {Channel} from '@mattermost/types/channels';
|
||||
import type {Team} from '@mattermost/types/teams';
|
||||
|
||||
import {TestHelper} from 'utils/test_helper';
|
||||
|
||||
import {ChannelProfile} from './channel_profile';
|
||||
|
||||
describe('admin_console/team_channel_settings/channel/ChannelProfile', () => {
|
||||
test('should match snapshot', () => {
|
||||
const testTeam: Partial<Team> = {display_name: 'test'};
|
||||
const testTeam = TestHelper.getTeamMock({display_name: 'test'});
|
||||
const testChannel: Partial<Channel> = {display_name: 'test'};
|
||||
const wrapper = shallow(
|
||||
<ChannelProfile
|
||||
@@ -24,7 +25,7 @@ describe('admin_console/team_channel_settings/channel/ChannelProfile', () => {
|
||||
});
|
||||
|
||||
test('should match snapshot for a shared channel', () => {
|
||||
const testTeam: Partial<Team> = {display_name: 'test'};
|
||||
const testTeam = TestHelper.getTeamMock({display_name: 'test'});
|
||||
const testChannel: Partial<Channel> = {
|
||||
display_name: 'test',
|
||||
type: 'O',
|
||||
|
||||
@@ -15,7 +15,7 @@ import AdminPanel from 'components/widgets/admin_console/admin_panel';
|
||||
import './channel_profile.scss';
|
||||
interface ChannelProfileProps {
|
||||
channel: Partial<Channel>;
|
||||
team: Partial<Team>;
|
||||
team?: Team;
|
||||
onToggleArchive?: () => void;
|
||||
isArchived: boolean;
|
||||
isDisabled?: boolean;
|
||||
@@ -71,7 +71,7 @@ export const ChannelProfile = (props: ChannelProfileProps): JSX.Element => {
|
||||
defaultMessage='**Team**'
|
||||
/>
|
||||
<br/>
|
||||
{team.display_name}
|
||||
{team?.display_name}
|
||||
</div>
|
||||
{sharedBlock}
|
||||
<div className='AdminChannelDetails_archiveContainer'>
|
||||
|
||||
@@ -63,12 +63,12 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) {
|
||||
const guestAccountsEnabled = config.EnableGuestAccounts === 'true';
|
||||
const channelID = ownProps.match.params.channel_id;
|
||||
const channel = getChannel(state, channelID) || {};
|
||||
const team = getTeam(state, channel.team_id) || {};
|
||||
const team = getTeam(state, channel.team_id);
|
||||
const groups = getGroupsAssociatedToChannel(state, channelID);
|
||||
const totalGroups = groups.length;
|
||||
const allGroups = getAllGroups(state);
|
||||
const channelPermissions = getChannelModerations(state, channelID);
|
||||
const teamScheme = getScheme(state, team.scheme_id);
|
||||
const teamScheme = team ? getScheme(state, team.scheme_id) : undefined;
|
||||
return {
|
||||
channelID,
|
||||
channel,
|
||||
|
||||
@@ -32,7 +32,7 @@ import SaveChangesPanel from '../../save_changes_panel';
|
||||
|
||||
export type Props = {
|
||||
teamID: string;
|
||||
team: Team;
|
||||
team?: Team;
|
||||
totalGroups: number;
|
||||
groups: Group[];
|
||||
allGroups: Record<string, Group>;
|
||||
@@ -90,10 +90,10 @@ export default class TeamDetails extends React.PureComponent<Props, State> {
|
||||
const team = props.team;
|
||||
this.state = {
|
||||
groups: props.groups,
|
||||
syncChecked: Boolean(team.group_constrained),
|
||||
allAllowedChecked: team.allow_open_invite,
|
||||
allowedDomainsChecked: Boolean(team.allowed_domains && team.allowed_domains !== ''),
|
||||
allowedDomains: team.allowed_domains || '',
|
||||
syncChecked: Boolean(team?.group_constrained),
|
||||
allAllowedChecked: Boolean(team?.allow_open_invite),
|
||||
allowedDomainsChecked: Boolean(team?.allowed_domains),
|
||||
allowedDomains: team?.allowed_domains || '',
|
||||
saving: false,
|
||||
showRemoveConfirmation: false,
|
||||
usersToRemoveCount: 0,
|
||||
@@ -104,21 +104,21 @@ export default class TeamDetails extends React.PureComponent<Props, State> {
|
||||
saveNeeded: false,
|
||||
serverError: undefined,
|
||||
previousServerError: undefined,
|
||||
isLocalArchived: team.delete_at > 0,
|
||||
isLocalArchived: team ? team.delete_at > 0 : true,
|
||||
showArchiveConfirmModal: false,
|
||||
};
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Props) {
|
||||
const {totalGroups, team} = this.props;
|
||||
if (prevProps.team.id !== team.id || totalGroups !== prevProps.totalGroups) {
|
||||
if (prevProps.team?.id !== team?.id || totalGroups !== prevProps.totalGroups) {
|
||||
this.setState({
|
||||
totalGroups,
|
||||
syncChecked: Boolean(team.group_constrained),
|
||||
allAllowedChecked: team.allow_open_invite,
|
||||
allowedDomainsChecked: Boolean(team.allowed_domains && team.allowed_domains !== ''),
|
||||
allowedDomains: team.allowed_domains || '',
|
||||
isLocalArchived: team.delete_at > 0,
|
||||
syncChecked: Boolean(team?.group_constrained),
|
||||
allAllowedChecked: Boolean(team?.allow_open_invite),
|
||||
allowedDomainsChecked: Boolean(team?.allowed_domains),
|
||||
allowedDomains: team?.allowed_domains || '',
|
||||
isLocalArchived: team ? team.delete_at > 0 : true,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -141,12 +141,16 @@ export default class TeamDetails extends React.PureComponent<Props, State> {
|
||||
};
|
||||
|
||||
handleSubmit = async () => {
|
||||
const {team, groups: origGroups, teamID, actions} = this.props;
|
||||
if (!team) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({showRemoveConfirmation: false, saving: true});
|
||||
const {groups, allAllowedChecked, allowedDomainsChecked, allowedDomains, syncChecked, usersToAdd, usersToRemove, rolesToUpdate} = this.state;
|
||||
|
||||
let serverError: JSX.Element | undefined;
|
||||
|
||||
const {team, groups: origGroups, teamID, actions} = this.props;
|
||||
if (this.teamToBeArchived()) {
|
||||
let saveNeeded = false;
|
||||
const result = await actions.deleteTeam(team.id);
|
||||
@@ -402,13 +406,13 @@ export default class TeamDetails extends React.PureComponent<Props, State> {
|
||||
|
||||
teamToBeArchived = () => {
|
||||
const {isLocalArchived} = this.state;
|
||||
const isServerArchived = this.props.team.delete_at !== 0;
|
||||
const isServerArchived = this.props.team?.delete_at !== 0;
|
||||
return isLocalArchived && !isServerArchived;
|
||||
};
|
||||
|
||||
teamToBeRestored = () => {
|
||||
const {isLocalArchived} = this.state;
|
||||
const isServerArchived = this.props.team.delete_at !== 0;
|
||||
const isServerArchived = this.props.team?.delete_at !== 0;
|
||||
return !isLocalArchived && isServerArchived;
|
||||
};
|
||||
|
||||
@@ -444,6 +448,11 @@ export default class TeamDetails extends React.PureComponent<Props, State> {
|
||||
|
||||
render = () => {
|
||||
const {team, isLicensedForLDAPGroups} = this.props;
|
||||
|
||||
if (!team) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {totalGroups, saving, saveNeeded, serverError, groups, allAllowedChecked, allowedDomainsChecked, allowedDomains, syncChecked, showRemoveConfirmation, usersToRemoveCount, isLocalArchived, showArchiveConfirmModal} = this.state;
|
||||
const missingGroup = (og: {id: string}) => !groups.find((g) => g.id === og.id);
|
||||
const removedGroups = this.props.groups.filter(missingGroup);
|
||||
|
||||
@@ -39,7 +39,7 @@ function mapStateToProps(state: GlobalState, props: Props) {
|
||||
let {usersToAdd} = props;
|
||||
|
||||
const teamMembers = getMembersInTeams(state)[teamId] || {};
|
||||
const team = getTeam(state, teamId) || {};
|
||||
const team = getTeam(state, teamId);
|
||||
const config = getConfig(state);
|
||||
const searchTerm = state.views.search.userGridSearch?.term || '';
|
||||
const filters = state.views.search.userGridSearch?.filters || {};
|
||||
|
||||
@@ -23,7 +23,7 @@ import Constants, {ModalIdentifiers} from 'utils/constants';
|
||||
|
||||
type Props = {
|
||||
teamId: string;
|
||||
team: Team;
|
||||
team?: Team;
|
||||
filters: GetFilteredUsersStatsOpts;
|
||||
|
||||
users: UserProfile[];
|
||||
|
||||
Ссылка в новой задаче
Block a user