Skip to content

Commit

Permalink
Fix types of various fields in GlobalState (mattermost#26125)
Browse files Browse the repository at this point in the history
* Fix types of entities.admin.analytics and entities.admin.teamAnalytics

* Fix type of entities.channels.channelsInTeam

* Fix types of entities.users.stats and entities.users.filteredStats

* Fix types of various profilesInX fields in entities.users

* Fix incorrect field name last_password_update_at used when updating password

We never noticed this bug before because the settings modal reloads the current user after updating their password.

* MM-56760 Fix users not being removed from state.entities.users properly
  • Loading branch information
hmhealey authored Feb 15, 2024
1 parent 64b1409 commit 54507bb
Show file tree
Hide file tree
Showing 48 changed files with 316 additions and 217 deletions.
2 changes: 1 addition & 1 deletion webapp/channels/src/actions/channel_actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const initialState = {
}),
},
channelsInTeam: {
'team-id': ['current_channel_id'],
'team-id': new Set(['asdf']),
},
messageCounts: {
current_channel_id: {total: 10},
Expand Down
24 changes: 12 additions & 12 deletions webapp/channels/src/actions/global_actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ describe('actions/global_actions', () => {
},
},
channelsInTeam: {
team1: ['channel-in-team-1'],
team2: ['channel-in-team-2'],
team1: new Set(['channel-in-team-1']),
team2: new Set(['channel-in-team-2']),
},
},
users: {
Expand Down Expand Up @@ -185,8 +185,8 @@ describe('actions/global_actions', () => {
},
},
channelsInTeam: {
team1: ['channel-in-team-1'],
team2: ['channel-in-team-2'],
team1: new Set(['channel-in-team-1']),
team2: new Set(['channel-in-team-2']),
},
},
users: {
Expand Down Expand Up @@ -257,8 +257,8 @@ describe('actions/global_actions', () => {
},
},
channelsInTeam: {
team1: ['channel-in-team-1'],
team2: ['channel-in-team-2'],
team1: new Set(['channel-in-team-1']),
team2: new Set(['channel-in-team-2']),
},
},
users: {
Expand Down Expand Up @@ -382,8 +382,8 @@ describe('actions/global_actions', () => {
},
},
channelsInTeam: {
team1: ['channel-in-team-1', directChannelId],
team2: ['channel-in-team-2'],
team1: new Set(['channel-in-team-1', directChannelId]),
team2: new Set(['channel-in-team-2']),
},
},
users: {
Expand Down Expand Up @@ -479,8 +479,8 @@ describe('actions/global_actions', () => {
},
},
channelsInTeam: {
team1: ['channel-in-team-1', directChannelId, groupChannelId],
team2: ['channel-in-team-2'],
team1: new Set(['channel-in-team-1', directChannelId, groupChannelId]),
team2: new Set(['channel-in-team-2']),
},
},
users: {
Expand Down Expand Up @@ -554,8 +554,8 @@ describe('actions/global_actions', () => {
},
},
channelsInTeam: {
team1: ['channel-in-team-1'],
team2: ['channel-in-team-2'],
team1: new Set(['channel-in-team-1']),
team2: new Set(['channel-in-team-2']),
},
},
users: {
Expand Down
6 changes: 2 additions & 4 deletions webapp/channels/src/actions/status_actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import * as Actions from 'actions/status_actions';

import mockStore from 'tests/test_store';

import type {GlobalState} from 'types/store';

jest.mock('mattermost-redux/actions/users', () => ({
getStatusesByIds: jest.fn(() => {
return {type: ''};
Expand All @@ -38,7 +36,7 @@ describe('actions/status_actions', () => {
currentChannelId: 'channel_id1',
channels: {channel_id1: {id: 'channel_id1', name: 'channel1', team_id: 'team_id1'}, channel_id2: {id: 'channel_id2', name: 'channel2', team_id: 'team_id1'}},
myMembers: {channel_id1: {channel_id: 'channel_id1', user_id: 'current_user_id'}},
channelsInTeam: {team_id1: ['channel_id1']},
channelsInTeam: {team_id1: new Set(['channel_id1'])},
},
general: {
config: {
Expand Down Expand Up @@ -76,7 +74,7 @@ describe('actions/status_actions', () => {
},
},
},
} as unknown as GlobalState;
};

describe('loadStatusesForChannelAndSidebar', () => {
test('load statuses with posts in channel and user in sidebar', () => {
Expand Down
4 changes: 2 additions & 2 deletions webapp/channels/src/actions/user_actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Actions.User', () => {
} as Channel,
},
channelsInTeam: {
team_1: ['current_channel_id'],
team_1: new Set(['current_channel_id']),
},
messageCounts: {
current_channel_id: {total: 10} as ChannelMessageCount,
Expand Down Expand Up @@ -539,7 +539,7 @@ describe('Actions.User', () => {
};

const channelsInTeam = {
'': [gmChannel.id],
'': new Set([gmChannel.id]),
};

const myMembers = {
Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/actions/views/channel_sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('multiSelectChannelTo', () => {
}, {}),
},
channelsInTeam: {
team1: channelIds.map((id) => `category1_${id}`).concat(channelIds.map((id) => `category2_${id}`)),
team1: new Set(channelIds.map((id) => `category1_${id}`).concat(channelIds.map((id) => `category2_${id}`))),
},
},
teams: {
Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/actions/websocket_actions.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ let mockState = {
},
},
channelsInTeam: {
team: ['channel1', 'channel2'],
team: new Set(['channel1', 'channel2']),
},
membersInChannel: {
otherChannel: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';
import {FormattedMessage, useIntl} from 'react-intl';

import type {AnalyticsRow} from '@mattermost/types/admin';
import type {AnalyticsState} from '@mattermost/types/admin';
import type {CloudCustomer} from '@mattermost/types/cloud';
import type {ClientLicense} from '@mattermost/types/config';

Expand Down Expand Up @@ -46,7 +46,7 @@ type Props = {

prevTrialLicense: ClientLicense;

stats?: Record<string, number | AnalyticsRow[]>;
stats?: AnalyticsState;
actions: {
getPrevTrialLicense: () => void;
getCloudSubscription: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {bindActionCreators} from 'redux';
import type {Dispatch} from 'redux';

import type {ChannelStats} from '@mattermost/types/channels';
import type {UserProfile, UsersStats} from '@mattermost/types/users';
import type {UserProfile} from '@mattermost/types/users';

import {getChannelStats} from 'mattermost-redux/actions/channels';
import {getFilteredUsersStats} from 'mattermost-redux/actions/users';
Expand Down Expand Up @@ -69,10 +69,10 @@ function makeMapStateToProps() {
};
totalCount = stats.member_count;
} else {
const filteredUserStats: UsersStats = selectFilteredUsersStats(state) || {
const filteredUserStats = selectFilteredUsersStats(state) || {
total_users_count: 0,
};
totalCount = filteredUserStats.total_users_count;
totalCount = filteredUserStats.total_users_count ?? 0;
}

let users = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import type {Dispatch} from 'redux';

import type {UserProfile, UsersStats} from '@mattermost/types/users';
import type {UserProfile} from '@mattermost/types/users';

import {getTeamStats as loadTeamStats} from 'mattermost-redux/actions/teams';
import {getFilteredUsersStats} from 'mattermost-redux/actions/users';
Expand Down Expand Up @@ -49,10 +49,10 @@ function mapStateToProps(state: GlobalState, props: Props) {
const stats = getTeamStats(state)[teamId] || {active_member_count: 0};
totalCount = stats.active_member_count;
} else {
const filteredUserStats: UsersStats = selectFilteredUsersStats(state) || {
const filteredUserStats = selectFilteredUsersStats(state) || {
total_users_count: 0,
};
totalCount = filteredUserStats.total_users_count;
totalCount = filteredUserStats.total_users_count ?? 0;
}

let users = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const usesLDAP = async (
// // @see discussion here: https://github.com/mattermost/mattermost-webapp/pull/9822#discussion_r806879385
// const fetchGuestAccounts = async (
// config: Partial<AdminConfig>,
// analytics: Record<string, number | AnalyticsRow[]> | undefined,
// analytics: AnalyticsState | undefined,
// ) => {
// if (config.TeamSettings?.EnableOpenServer && config.GuestAccountsSettings?.Enable) {
// let usersArray = await fetch(`${Client4.getBaseRoute()}/users/invalid_emails`).then((result) => result.json());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import React from 'react';
import {FormattedMessage, defineMessages} from 'react-intl';

import type {AnalyticsRow, PluginAnalyticsRow, IndexedPluginAnalyticsRow} from '@mattermost/types/admin';
import type {AnalyticsRow, PluginAnalyticsRow, IndexedPluginAnalyticsRow, AnalyticsState} from '@mattermost/types/admin';
import type {ClientLicense} from '@mattermost/types/config';

import * as AdminActions from 'actions/admin_actions.jsx';
Expand Down Expand Up @@ -33,7 +33,7 @@ const StatTypes = Constants.StatTypes;

type Props = {
isLicensed: boolean;
stats?: Record<string, number | AnalyticsRow[]>;
stats?: AnalyticsState;
license: ClientLicense;
pluginStatHandlers: GlobalState['plugins']['siteStatsHandlers'];
}
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class SystemAnalytics extends React.PureComponent<Props, State> {
this.setState({pluginSiteStats: allStatsIndexed});
}

private getStatValue(stat: number | AnalyticsRow[]): number | undefined {
private getStatValue(stat: number | AnalyticsRow[] | undefined): number | undefined {
if (typeof stat === 'number') {
return stat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import type {MessageDescriptor} from 'react-intl';
import {FormattedDate, FormattedMessage, defineMessages} from 'react-intl';

import type {AnalyticsRow} from '@mattermost/types/admin';
import type {AnalyticsRow, AnalyticsState} from '@mattermost/types/admin';
import type {ClientLicense} from '@mattermost/types/config';
import type {Team} from '@mattermost/types/teams';
import type {UserProfile} from '@mattermost/types/users';
Expand Down Expand Up @@ -52,7 +52,7 @@ type Props = {

license: ClientLicense;

stats: RelationOneToOne<Team, Record<string, number | AnalyticsRow[]>>;
stats: RelationOneToOne<Team, AnalyticsState>;

actions: {

Expand Down Expand Up @@ -129,7 +129,7 @@ export default class TeamAnalytics extends React.PureComponent<Props, State> {
}
}

private getStatValue(stat: number | AnalyticsRow[]): number | undefined {
private getStatValue(stat: number | AnalyticsRow[] | undefined): number | undefined {
if (typeof stat === 'number') {
return stat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const initialState: DeepPartial<GlobalState> = {
},
},
channelsInTeam: {
'team-id': ['current_channel_id'],
'team-id': new Set(['current_channel_id']),
},
messageCounts: {
current_channel_id: {total: 10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const initialState: DeepPartial<GlobalState> = {
},
},
channelsInTeam: {
'team-id': ['current_channel_id'],
'team-id': new Set(['current_channel_id']),
},
messageCounts: {
current_channel_id: {total: 10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const initialState: DeepPartial<GlobalState> = {
},
},
channelsInTeam: {
'team-id': ['current_channel_id'],
'team-id': new Set(['current_channel_id']),
},
messageCounts: {
current_channel_id: {total: 10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Actions', () => {
currentChannelId: 'channel_id1',
channels: {channel_id1: channel1, channel_id2: channel2, channel_id3: channel3, channel_id4: channel4, channel_id5: channel5, channel_id6: channel6},
myMembers: {channel_id1: {channel_id: 'channel_id1', user_id: 'current_user_id'}, channel_id2: {channel_id: 'channel_id2', user_id: 'current_user_id'}},
channelsInTeam: {team_id1: ['channel_id1'], team_id2: ['channel_id2']},
channelsInTeam: {team_id1: new Set(['channel_id1']), team_id2: new Set(['channel_id2'])},
},
teams: {
currentTeamId: 'team_id1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const makeMapStateToProps = () => {
currentChannelMembers,
currentUserId,
restrictDirectMessage,
totalCount: stats.total_users_count,
totalCount: stats.total_users_count ?? 0,
};
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('makeGetOptions', () => {
[gmChannel3.id]: gmChannel3,
},
channelsInTeam: {
'': [gmChannel1.id, gmChannel2.id, gmChannel3.id],
'': new Set([gmChannel1.id, gmChannel2.id, gmChannel3.id]),
},
},
users: {
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('makeGetOptions', () => {
[gmChannel2.id]: gmChannel2,
},
channelsInTeam: {
'': [gmChannel1.id, gmChannel2.id],
'': new Set([gmChannel1.id, gmChannel2.id]),
},
},
users: {
Expand Down Expand Up @@ -378,7 +378,7 @@ describe('makeGetOptions', () => {
[gmChannel3.id]: gmChannel3,
},
channelsInTeam: {
'': [gmChannel1.id, gmChannel2.id, gmChannel3.id],
'': new Set([gmChannel1.id, gmChannel2.id, gmChannel3.id]),
},
},
users: {
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('makeGetOptions', () => {
[gmChannel2.id]: gmChannel2,
},
channelsInTeam: {
'': [gmChannel1.id, gmChannel2.id],
'': new Set([gmChannel1.id, gmChannel2.id]),
},
},
users: {
Expand Down Expand Up @@ -591,7 +591,7 @@ describe('makeGetOptions', () => {
[dm1.id]: dm1,
},
channelsInTeam: {
'': [dm1.id],
'': new Set([dm1.id]),
},
},
users: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('components/sidebar/invite_members_button', () => {
},
stats: {
total_users_count: 10,
} as any, // HARRISONTODO The defined type of entities.users.stats is incorrect
},
},
roles: {
roles: {
Expand Down
2 changes: 1 addition & 1 deletion webapp/channels/src/components/sidebar/sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('components/sidebar', () => {
channel2,
},
channelsInTeam: {
[currentTeamId]: [channel1.id, channel2.id],
[currentTeamId]: new Set([channel1.id, channel2.id]),
},
messageCounts: {
channel1: {total: 10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const reduxTestState = {
},
},
channelsInTeam: {
'team-id': ['current_channel_id'],
'team-id': new Set(['current_channel_id']),
},
messageCounts: {
current_channel_id: {total: 10},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ describe('components/SearchChannelWithPermissionsProvider', () => {
}),
},
channelsInTeam: {
someTeamId: [
someTeamId: new Set([
'somePublicMemberChannelId',
'somePrivateMemberChannelId',
'somePublicNonMemberChannelId',
'somePrivateNonMemberChannelId',
'someDirectConversation',
'someGroupConversation',
],
]),
},
},
roles: {
Expand Down
Loading

0 comments on commit 54507bb

Please sign in to comment.