Commit 53322a51 by Hugo Häggmark Committed by Leonard Gram

fix: refactored so members are loaded by TeamPages and use hideFromTabs instead…

fix: refactored so members are loaded by TeamPages and use hideFromTabs instead of filtering out children in navModel
parent 978c20a6
...@@ -12,7 +12,6 @@ const setup = (propOverrides?: object) => { ...@@ -12,7 +12,6 @@ const setup = (propOverrides?: object) => {
members: [] as TeamMember[], members: [] as TeamMember[],
searchMemberQuery: '', searchMemberQuery: '',
setSearchMemberQuery: jest.fn(), setSearchMemberQuery: jest.fn(),
loadTeamMembers: jest.fn(),
addTeamMember: jest.fn(), addTeamMember: jest.fn(),
syncEnabled: false, syncEnabled: false,
editorsCanAdmin: false, editorsCanAdmin: false,
......
...@@ -4,8 +4,8 @@ import SlideDown from 'app/core/components/Animations/SlideDown'; ...@@ -4,8 +4,8 @@ import SlideDown from 'app/core/components/Animations/SlideDown';
import { UserPicker } from 'app/core/components/Select/UserPicker'; import { UserPicker } from 'app/core/components/Select/UserPicker';
import { TagBadge } from 'app/core/components/TagFilter/TagBadge'; import { TagBadge } from 'app/core/components/TagFilter/TagBadge';
import { TeamMember, User } from 'app/types'; import { TeamMember, User } from 'app/types';
import { loadTeamMembers, addTeamMember, setSearchMemberQuery } from './state/actions'; import { addTeamMember, setSearchMemberQuery } from './state/actions';
import { getSearchMemberQuery, getTeamMembers, isSignedInUserTeamAdmin } from './state/selectors'; import { getSearchMemberQuery, isSignedInUserTeamAdmin } from './state/selectors';
import { FilterInput } from 'app/core/components/FilterInput/FilterInput'; import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
import { WithFeatureToggle } from 'app/core/components/WithFeatureToggle'; import { WithFeatureToggle } from 'app/core/components/WithFeatureToggle';
import { config } from 'app/core/config'; import { config } from 'app/core/config';
...@@ -15,7 +15,6 @@ import TeamMemberRow from './TeamMemberRow'; ...@@ -15,7 +15,6 @@ import TeamMemberRow from './TeamMemberRow';
export interface Props { export interface Props {
members: TeamMember[]; members: TeamMember[];
searchMemberQuery: string; searchMemberQuery: string;
loadTeamMembers: typeof loadTeamMembers;
addTeamMember: typeof addTeamMember; addTeamMember: typeof addTeamMember;
setSearchMemberQuery: typeof setSearchMemberQuery; setSearchMemberQuery: typeof setSearchMemberQuery;
syncEnabled: boolean; syncEnabled: boolean;
...@@ -34,10 +33,6 @@ export class TeamMembers extends PureComponent<Props, State> { ...@@ -34,10 +33,6 @@ export class TeamMembers extends PureComponent<Props, State> {
this.state = { isAdding: false, newTeamMember: null }; this.state = { isAdding: false, newTeamMember: null };
} }
componentDidMount() {
this.props.loadTeamMembers();
}
onSearchQueryChange = (value: string) => { onSearchQueryChange = (value: string) => {
this.props.setSearchMemberQuery(value); this.props.setSearchMemberQuery(value);
}; };
...@@ -150,7 +145,6 @@ export class TeamMembers extends PureComponent<Props, State> { ...@@ -150,7 +145,6 @@ export class TeamMembers extends PureComponent<Props, State> {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
members: getTeamMembers(state.team),
searchMemberQuery: getSearchMemberQuery(state.team), searchMemberQuery: getSearchMemberQuery(state.team),
editorsCanAdmin: config.editorsCanAdmin, // this makes the feature toggle mockable/controllable from tests, editorsCanAdmin: config.editorsCanAdmin, // this makes the feature toggle mockable/controllable from tests,
signedInUser: contextSrv.user, // this makes the feature toggle mockable/controllable from tests, signedInUser: contextSrv.user, // this makes the feature toggle mockable/controllable from tests,
...@@ -158,7 +152,6 @@ function mapStateToProps(state) { ...@@ -158,7 +152,6 @@ function mapStateToProps(state) {
} }
const mapDispatchToProps = { const mapDispatchToProps = {
loadTeamMembers,
addTeamMember, addTeamMember,
setSearchMemberQuery, setSearchMemberQuery,
}; };
......
...@@ -14,6 +14,7 @@ const setup = (propOverrides?: object) => { ...@@ -14,6 +14,7 @@ const setup = (propOverrides?: object) => {
navModel: {} as NavModel, navModel: {} as NavModel,
teamId: 1, teamId: 1,
loadTeam: jest.fn(), loadTeam: jest.fn(),
loadTeamMembers: jest.fn(),
pageName: 'members', pageName: 'members',
team: {} as Team, team: {} as Team,
members: [] as TeamMember[], members: [] as TeamMember[],
......
...@@ -8,7 +8,7 @@ import TeamMembers from './TeamMembers'; ...@@ -8,7 +8,7 @@ import TeamMembers from './TeamMembers';
import TeamSettings from './TeamSettings'; import TeamSettings from './TeamSettings';
import TeamGroupSync from './TeamGroupSync'; import TeamGroupSync from './TeamGroupSync';
import { NavModel, Team, TeamMember } from 'app/types'; import { NavModel, Team, TeamMember } from 'app/types';
import { loadTeam } from './state/actions'; import { loadTeam, loadTeamMembers } from './state/actions';
import { getTeam, getTeamMembers, isSignedInUserTeamAdmin } from './state/selectors'; import { getTeam, getTeamMembers, isSignedInUserTeamAdmin } from './state/selectors';
import { getTeamLoadingNav } from './state/navModel'; import { getTeamLoadingNav } from './state/navModel';
import { getNavModel } from 'app/core/selectors/navModel'; import { getNavModel } from 'app/core/selectors/navModel';
...@@ -18,6 +18,7 @@ import { contextSrv, User } from 'app/core/services/context_srv'; ...@@ -18,6 +18,7 @@ import { contextSrv, User } from 'app/core/services/context_srv';
export interface Props { export interface Props {
team: Team; team: Team;
loadTeam: typeof loadTeam; loadTeam: typeof loadTeam;
loadTeamMembers: typeof loadTeamMembers;
teamId: number; teamId: number;
pageName: string; pageName: string;
navModel: NavModel; navModel: NavModel;
...@@ -55,6 +56,7 @@ export class TeamPages extends PureComponent<Props, State> { ...@@ -55,6 +56,7 @@ export class TeamPages extends PureComponent<Props, State> {
const { loadTeam, teamId } = this.props; const { loadTeam, teamId } = this.props;
this.setState({ isLoading: true }); this.setState({ isLoading: true });
const team = await loadTeam(teamId); const team = await loadTeam(teamId);
await this.props.loadTeamMembers();
this.setState({ isLoading: false }); this.setState({ isLoading: false });
return team; return team;
} }
...@@ -65,9 +67,25 @@ export class TeamPages extends PureComponent<Props, State> { ...@@ -65,9 +67,25 @@ export class TeamPages extends PureComponent<Props, State> {
return _.includes(pages, currentPage) ? currentPage : pages[0]; return _.includes(pages, currentPage) ? currentPage : pages[0];
} }
textsAreEqual = (text1: string, text2: string) => {
if (!text1 && !text2) {
return true;
}
if (!text1 || !text2) {
return false;
}
return text1.toLocaleLowerCase() === text2.toLocaleLowerCase();
};
hideTabsFromNonTeamAdmin = (navModel: NavModel, isSignedInUserTeamAdmin: boolean) => { hideTabsFromNonTeamAdmin = (navModel: NavModel, isSignedInUserTeamAdmin: boolean) => {
if (!isSignedInUserTeamAdmin && navModel.main && navModel.main.children) { if (!isSignedInUserTeamAdmin && navModel.main && navModel.main.children) {
navModel.main.children = navModel.main.children.filter(navItem => navItem.text === 'Members'); navModel.main.children
.filter(navItem => !this.textsAreEqual(navItem.text, PageTypes.Members))
.map(navItem => {
navItem.hideFromTabs = true;
});
} }
return navModel; return navModel;
...@@ -75,11 +93,12 @@ export class TeamPages extends PureComponent<Props, State> { ...@@ -75,11 +93,12 @@ export class TeamPages extends PureComponent<Props, State> {
renderPage(isSignedInUserTeamAdmin: boolean) { renderPage(isSignedInUserTeamAdmin: boolean) {
const { isSyncEnabled } = this.state; const { isSyncEnabled } = this.state;
const { members } = this.props;
const currentPage = this.getCurrentPage(); const currentPage = this.getCurrentPage();
switch (currentPage) { switch (currentPage) {
case PageTypes.Members: case PageTypes.Members:
return <TeamMembers syncEnabled={isSyncEnabled} />; return <TeamMembers syncEnabled={isSyncEnabled} members={members} />;
case PageTypes.Settings: case PageTypes.Settings:
return isSignedInUserTeamAdmin && <TeamSettings />; return isSignedInUserTeamAdmin && <TeamSettings />;
...@@ -108,13 +127,16 @@ function mapStateToProps(state) { ...@@ -108,13 +127,16 @@ function mapStateToProps(state) {
const teamId = getRouteParamsId(state.location); const teamId = getRouteParamsId(state.location);
const pageName = getRouteParamsPage(state.location) || 'members'; const pageName = getRouteParamsPage(state.location) || 'members';
const teamLoadingNav = getTeamLoadingNav(pageName); const teamLoadingNav = getTeamLoadingNav(pageName);
const navModel = getNavModel(state.navIndex, `team-${pageName}-${teamId}`, teamLoadingNav);
const team = getTeam(state.team, teamId);
const members = getTeamMembers(state.team);
return { return {
navModel: getNavModel(state.navIndex, `team-${pageName}-${teamId}`, teamLoadingNav), navModel,
teamId: teamId, teamId: teamId,
pageName: pageName, pageName: pageName,
team: getTeam(state.team, teamId), team,
members: getTeamMembers(state.team), members,
editorsCanAdmin: config.editorsCanAdmin, // this makes the feature toggle mockable/controllable from tests, editorsCanAdmin: config.editorsCanAdmin, // this makes the feature toggle mockable/controllable from tests,
signedInUser: contextSrv.user, // this makes the feature toggle mockable/controllable from tests, signedInUser: contextSrv.user, // this makes the feature toggle mockable/controllable from tests,
}; };
...@@ -122,6 +144,7 @@ function mapStateToProps(state) { ...@@ -122,6 +144,7 @@ function mapStateToProps(state) {
const mapDispatchToProps = { const mapDispatchToProps = {
loadTeam, loadTeam,
loadTeamMembers,
}; };
export default hot(module)( export default hot(module)(
......
...@@ -30,6 +30,7 @@ exports[`Render should render member page if team not empty 1`] = ` ...@@ -30,6 +30,7 @@ exports[`Render should render member page if team not empty 1`] = `
isLoading={true} isLoading={true}
> >
<Connect(TeamMembers) <Connect(TeamMembers)
members={Array []}
syncEnabled={true} syncEnabled={true}
/> />
</PageContents> </PageContents>
......
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