Unverified Commit f243c6a5 authored by Jesús Espino's avatar Jesús Espino Committed by GitHub

Removing implicit anys from team selectors and reducers (#970)

parent e09899fd
......@@ -3,8 +3,12 @@
import {combineReducers} from 'redux';
import {ChannelTypes, TeamTypes, UserTypes, SchemeTypes, GroupTypes} from 'action_types';
import {teamListToMap} from 'utils/team_utils';
import {Team, TeamMembership} from 'types/teams';
import {UserProfile} from 'types/users';
import {RelationOneToOne, IDMappedObjects} from 'types/utilities';
import {GenericAction} from 'types/actions';
function currentTeamId(state = '', action) {
function currentTeamId(state = '', action: GenericAction) {
switch (action.type) {
case TeamTypes.SELECT_TEAM:
return action.data;
......@@ -16,7 +20,7 @@ function currentTeamId(state = '', action) {
}
}
function teams(state = {}, action) {
function teams(state: IDMappedObjects<Team> = {}, action: GenericAction) {
switch (action.type) {
case TeamTypes.RECEIVED_TEAMS_LIST:
case SchemeTypes.RECEIVED_SCHEME_TEAMS:
......@@ -63,8 +67,8 @@ function teams(state = {}, action) {
}
}
function myMembers(state = {}, action) {
function updateState(receivedTeams = {}, currentState = {}) {
function myMembers(state: RelationOneToOne<Team, TeamMembership> = {}, action: GenericAction) {
function updateState(receivedTeams: IDMappedObjects<Team> = {}, currentState: RelationOneToOne<Team, TeamMembership> = {}) {
return Object.keys(receivedTeams).forEach((teamId) => {
if (receivedTeams[teamId].delete_at > 0 && currentState[teamId]) {
Reflect.deleteProperty(currentState, teamId);
......@@ -82,7 +86,7 @@ function myMembers(state = {}, action) {
return nextState;
}
case TeamTypes.RECEIVED_MY_TEAM_MEMBERS: {
const nextState = {};
const nextState: RelationOneToOne<Team, TeamMembership> = {};
const members = action.data;
for (const m of members) {
if (m.delete_at == null || m.delete_at === 0) {
......@@ -204,7 +208,7 @@ function myMembers(state = {}, action) {
return nextState;
}
case TeamTypes.UPDATED_TEAM_MEMBER_SCHEME_ROLES: {
return updateTeamMemberSchemeRoles(state, action);
return updateMyTeamMemberSchemeRoles(state, action);
}
case UserTypes.LOGOUT_SUCCESS:
return {};
......@@ -213,7 +217,7 @@ function myMembers(state = {}, action) {
}
}
function membersInTeam(state = {}, action) {
function membersInTeam(state: RelationOneToOne<Team, RelationOneToOne<UserProfile, TeamMembership>> = {}, action: GenericAction) {
switch (action.type) {
case TeamTypes.RECEIVED_MEMBER_IN_TEAM: {
const data = action.data;
......@@ -293,7 +297,7 @@ function membersInTeam(state = {}, action) {
}
}
function stats(state = {}, action) {
function stats(state = {}, action: GenericAction) {
switch (action.type) {
case TeamTypes.RECEIVED_TEAM_STATS: {
const stat = action.data;
......@@ -319,7 +323,7 @@ function stats(state = {}, action) {
}
}
function groupsAssociatedToTeam(state = {}, action) {
function groupsAssociatedToTeam(state: RelationOneToOne<Team, {ids: string[]; totalCount: number}> = {}, action: GenericAction) {
switch (action.type) {
case GroupTypes.RECEIVED_GROUPS_ASSOCIATED_TO_TEAM: {
const {teamID, groups, totalGroupCount} = action.data;
......@@ -349,7 +353,7 @@ function groupsAssociatedToTeam(state = {}, action) {
for (const group of groups) {
associatedGroupIDs.delete(group.id);
}
nextState[teamID] = Array.from(associatedGroupIDs);
nextState[teamID] = {ids: Array.from(associatedGroupIDs), totalCount: associatedGroupIDs.size};
return nextState;
}
default:
......@@ -357,7 +361,7 @@ function groupsAssociatedToTeam(state = {}, action) {
}
}
function updateTeamMemberSchemeRoles(state, action) {
function updateTeamMemberSchemeRoles(state: RelationOneToOne<Team, RelationOneToOne<UserProfile, TeamMembership>>, action: GenericAction) {
const {teamId, userId, isSchemeUser, isSchemeAdmin} = action.data;
const team = state[teamId];
if (team) {
......@@ -379,7 +383,23 @@ function updateTeamMemberSchemeRoles(state, action) {
return state;
}
function totalCount(state = 0, action) {
function updateMyTeamMemberSchemeRoles(state: RelationOneToOne<Team, TeamMembership>, action: GenericAction) {
const {teamId, userId, isSchemeUser, isSchemeAdmin} = action.data;
const member = state[teamId];
if (member) {
return {
...state,
[teamId]: {
...state[teamId],
scheme_user: isSchemeUser,
scheme_admin: isSchemeAdmin,
},
};
}
return state;
}
function totalCount(state = 0, action: GenericAction) {
switch (action.type) {
case TeamTypes.RECEIVED_TOTAL_TEAM_COUNT: {
return action.data;
......
......@@ -8,16 +8,17 @@ import {createIdsSelector} from 'utils/helpers';
import {isTeamAdmin} from 'utils/user_utils';
import {sortTeamsWithLocale} from 'utils/team_utils';
import {Team, TeamMembership} from 'types/teams';
import {IDMappedObjects} from 'types/utilities';
import {GlobalState} from 'types/store';
export function getCurrentTeamId(state: GlobalState) {
return state.entities.teams.currentTeamId;
}
export const getTeamByName = reselect.createSelector(getTeams, (state, name) => name, (teams, name) => {
export const getTeamByName = reselect.createSelector(getTeams, (state: GlobalState, name: string) => name, (teams: IDMappedObjects<Team>, name: string): Team|undefined => {
return Object.values(teams).find((team: Team) => team.name === name);
});
export function getTeams(state: GlobalState) {
export function getTeams(state: GlobalState): IDMappedObjects<Team> {
return state.entities.teams.teams;
}
......@@ -48,7 +49,7 @@ export const getCurrentTeam = reselect.createSelector(
}
);
export function getTeam(state, id) {
export function getTeam(state: GlobalState, id: string): Team {
const teams = getTeams(state);
return teams[id];
}
......@@ -56,7 +57,7 @@ export function getTeam(state, id) {
export const getCurrentTeamMembership = reselect.createSelector(
getCurrentTeamId,
getTeamMemberships,
(currentTeamId, teamMemberships) => {
(currentTeamId: string, teamMemberships: {[x: string]: TeamMembership}): TeamMembership => {
return teamMemberships[currentTeamId];
}
);
......@@ -114,7 +115,7 @@ export const getMyTeams = reselect.createSelector(
export const getMyTeamMember = reselect.createSelector(
getTeamMemberships,
(state, teamId) => teamId,
(state: GlobalState, teamId: string) => teamId,
(teamMemberships, teamId) => {
return teamMemberships[teamId] || {};
}
......@@ -128,7 +129,7 @@ export const getMembersInCurrentTeam = reselect.createSelector(
}
);
export function getTeamMember(state, teamId, userId) {
export function getTeamMember(state: GlobalState, teamId: string, userId: string) {
const members = getMembersInTeams(state)[teamId];
if (members) {
return members[userId];
......@@ -167,9 +168,9 @@ export const getListableTeams = reselect.createSelector(
export const getSortedListableTeams = reselect.createSelector(
getTeams,
getListableTeamIds,
(state, locale) => locale,
(state: GlobalState, locale: string) => locale,
(teams, listableTeamIds, locale) => {
const listableTeams = {};
const listableTeams: {[x: string]: Team} = {};
for (const id of listableTeamIds) {
listableTeams[id] = teams[id];
......@@ -182,8 +183,8 @@ export const getSortedListableTeams = reselect.createSelector(
export const getJoinableTeamIds = createIdsSelector(
getTeams,
getTeamMemberships,
(state) => haveISystemPermission(state, {permission: Permissions.JOIN_PUBLIC_TEAMS}),
(state) => haveISystemPermission(state, {permission: Permissions.JOIN_PRIVATE_TEAMS}),
(state: GlobalState) => haveISystemPermission(state, {permission: Permissions.JOIN_PUBLIC_TEAMS}),
(state: GlobalState) => haveISystemPermission(state, {permission: Permissions.JOIN_PRIVATE_TEAMS}),
isCompatibleWithJoinViewTeamPermissions,
(teams, myMembers, canJoinPublicTeams, canJoinPrivateTeams, compatibleWithJoinViewTeamPermissions) => {
return Object.keys(teams).filter((id) => {
......@@ -209,9 +210,9 @@ export const getJoinableTeams = reselect.createSelector(
export const getSortedJoinableTeams = reselect.createSelector(
getTeams,
getJoinableTeamIds,
(state, locale) => locale,
(state: GlobalState, locale: string) => locale,
(teams, joinableTeamIds, locale) => {
const joinableTeams = {};
const joinableTeams: {[x: string]: Team} = {};
for (const id of joinableTeamIds) {
joinableTeams[id] = teams[id];
......@@ -223,7 +224,7 @@ export const getSortedJoinableTeams = reselect.createSelector(
export const getMySortedTeamIds = createIdsSelector(
getMyTeams,
(state, locale) => locale,
(state: GlobalState, locale: string) => locale,
(teams, locale) => {
return teams.sort(sortTeamsWithLocale(locale)).map((t) => t.id);
}
......@@ -271,7 +272,7 @@ export const getChannelDrawerBadgeCount = reselect.createSelector(
export function makeGetBadgeCountForTeamId() {
return reselect.createSelector(
getTeamMemberships,
(state, id) => id,
(state: GlobalState, id: string) => id,
(members, teamId) => {
const member = members[teamId];
let badgeCount = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment