* Remove mattermost-redux * Move mm-redux files into app/redux * Add @redux path to tsconfig.json * Fix imports * Install missing dependencies * Fix tsc errors * Fix i18n_utils test * Fix more imports * Remove redux websocket * Fix tests * Rename @redux * Apply changes from mattermost-redux PR 1103 * Remove mattermost-redux mention in template * Add missing imports * Rename app/redux/ to app/mm-redux/ * Remove test file * Fix fetching Sidebar GM profiles Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
92 lines
3.4 KiB
TypeScript
92 lines
3.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
import * as reselect from 'reselect';
|
|
import {GlobalState} from '@mm-redux/types/store';
|
|
const emptyList: any[] = [];
|
|
const emptySyncables = {
|
|
teams: [],
|
|
channels: [],
|
|
};
|
|
|
|
export function getAllGroups(state: GlobalState) {
|
|
return state.entities.groups.groups;
|
|
}
|
|
|
|
export function getGroup(state: GlobalState, id: string) {
|
|
return getAllGroups(state)[id];
|
|
}
|
|
|
|
export function getGroupMemberCount(state: GlobalState, id: string) {
|
|
const memberData = state.entities.groups.members;
|
|
const groupMemberData = memberData[id];
|
|
if (!groupMemberData) {
|
|
return 0;
|
|
}
|
|
return memberData[id].totalMemberCount;
|
|
}
|
|
|
|
function getGroupSyncables(state: GlobalState, id: string) {
|
|
return state.entities.groups.syncables[id] || emptySyncables;
|
|
}
|
|
|
|
export function getGroupTeams(state: GlobalState, id: string) {
|
|
return getGroupSyncables(state, id).teams;
|
|
}
|
|
|
|
export function getGroupChannels(state: GlobalState, id: string) {
|
|
return getGroupSyncables(state, id).channels;
|
|
}
|
|
|
|
export function getGroupMembers(state: GlobalState, id: string) {
|
|
const groupMemberData = state.entities.groups.members[id];
|
|
if (!groupMemberData) {
|
|
return emptyList;
|
|
}
|
|
return groupMemberData.members;
|
|
}
|
|
|
|
const teamGroupIDs = (state: GlobalState, teamID: string) => (state.entities.teams.groupsAssociatedToTeam[teamID] == null ? undefined : state.entities.teams.groupsAssociatedToTeam[teamID].ids == null ? undefined : state.entities.teams.groupsAssociatedToTeam[teamID].ids) || [];
|
|
|
|
const channelGroupIDs = (state: GlobalState, channelID: string) => (state.entities.channels.groupsAssociatedToChannel[channelID] == null ? undefined : state.entities.channels.groupsAssociatedToChannel[channelID].ids == null ? undefined : state.entities.channels.groupsAssociatedToChannel[channelID].ids) || [];
|
|
|
|
const getTeamGroupIDSet = reselect.createSelector(
|
|
teamGroupIDs,
|
|
(teamIDs) => new Set(teamIDs),
|
|
);
|
|
|
|
const getChannelGroupIDSet = reselect.createSelector(
|
|
channelGroupIDs,
|
|
(channelIDs) => new Set(channelIDs),
|
|
);
|
|
|
|
export const getGroupsNotAssociatedToTeam = reselect.createSelector(
|
|
getAllGroups,
|
|
(state: GlobalState, teamID: string) => getTeamGroupIDSet(state, teamID),
|
|
(allGroups, teamGroupIDSet) => {
|
|
return Object.entries(allGroups).filter(([groupID]) => !teamGroupIDSet.has(groupID)).map((entry) => entry[1]);
|
|
}
|
|
);
|
|
|
|
export const getGroupsAssociatedToTeam = reselect.createSelector(
|
|
getAllGroups,
|
|
(state: GlobalState, teamID: string) => getTeamGroupIDSet(state, teamID),
|
|
(allGroups, teamGroupIDSet) => {
|
|
return Object.entries(allGroups).filter(([groupID]) => teamGroupIDSet.has(groupID)).map((entry) => entry[1]);
|
|
}
|
|
);
|
|
|
|
export const getGroupsNotAssociatedToChannel = reselect.createSelector(
|
|
getAllGroups,
|
|
(state: GlobalState, channelID: string) => getChannelGroupIDSet(state, channelID),
|
|
(allGroups, channelGroupIDSet) => {
|
|
return Object.entries(allGroups).filter(([groupID]) => !channelGroupIDSet.has(groupID)).map((entry) => entry[1]);
|
|
}
|
|
);
|
|
|
|
export const getGroupsAssociatedToChannel = reselect.createSelector(
|
|
getAllGroups,
|
|
(state: GlobalState, channelID: string) => getChannelGroupIDSet(state, channelID),
|
|
(allGroups, channelGroupIDSet) => {
|
|
return Object.entries(allGroups).filter(([groupID]) => channelGroupIDSet.has(groupID)).map((entry) => entry[1]);
|
|
}
|
|
);
|