Merge pull request #860 from mlorb/ml-sci-1730

Fix team table does not retain the number of teams per page bug [SCI-1730]
This commit is contained in:
mlorb 2017-11-09 17:53:19 +01:00 committed by GitHub
commit dfb2689fbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 14 deletions

View file

@ -24,8 +24,9 @@ import SettingsTeam from "./scenes/team";
import SettingsNewTeam from "./scenes/teams/new"; import SettingsNewTeam from "./scenes/teams/new";
type State = { type State = {
active: string active: string,
} teamsTableSizePerPage: number
};
let componentMounted = false; let componentMounted = false;
@ -34,10 +35,12 @@ export default class SettingsPage extends Component<*, State> {
super(props); super(props);
this.state = { this.state = {
active: "1" active: "1",
teamsTableSizePerPage: 10
}; };
(this: any).handleSelect = this.handleSelect.bind(this); (this: any).handleSelect = this.handleSelect.bind(this);
(this: any).setTabState = this.setTabState.bind(this); (this: any).setTabState = this.setTabState.bind(this);
(this: any).teamsTableOnSizePerPageList = this.teamsTableOnSizePerPageList.bind(this);
} }
componentDidMount(): void { componentDidMount(): void {
@ -54,6 +57,10 @@ export default class SettingsPage extends Component<*, State> {
} }
} }
teamsTableOnSizePerPageList(teamsTableSizePerPage: number): void {
(this: any).setState({ teamsTableSizePerPage });
}
handleSelect(eventKey: string): void { handleSelect(eventKey: string): void {
event.preventDefault(); event.preventDefault();
(this: any).setState({ active: eventKey }); (this: any).setState({ active: eventKey });
@ -108,7 +115,12 @@ export default class SettingsPage extends Component<*, State> {
<Route <Route
path={SETTINGS_TEAMS_ROUTE} path={SETTINGS_TEAMS_ROUTE}
component={props => ( component={props => (
<SettingsTeams {...props} tabState={this.setTabState} /> <SettingsTeams
{...props}
tabState={this.setTabState}
sizePerPage={this.state.teamsTableSizePerPage}
onSizePerPageList={this.teamsTableOnSizePerPageList}
/>
)} )}
/> />
<Route <Route

View file

@ -20,15 +20,21 @@ const DefaultTeam = {
type Props = { type Props = {
updateTeamsState: Function, updateTeamsState: Function,
teams: Array<Teams$Team> teams: Array<Teams$Team>,
} sizePerPage: number,
onSizePerPageList: Function
};
type State = { type State = {
leaveTeamModalShow: boolean, leaveTeamModalShow: boolean,
team: Teams$Team team: Teams$Team
} };
class TeamsDataTable extends Component<Props, State> { class TeamsDataTable extends Component<Props, State> {
static linkToTeam(name: string, team: Teams$Team): Node {
return <Link to={`${SETTINGS_TEAMS_ROUTE}/${team.id}`}>{name}</Link>;
}
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { this.state = {
@ -37,7 +43,6 @@ class TeamsDataTable extends Component<Props, State> {
}; };
(this: any).leaveTeamModal = this.leaveTeamModal.bind(this); (this: any).leaveTeamModal = this.leaveTeamModal.bind(this);
(this: any).leaveTeamButton = this.leaveTeamButton.bind(this); (this: any).leaveTeamButton = this.leaveTeamButton.bind(this);
(this: any).linkToTeam = this.linkToTeam.bind(this);
(this: any).hideLeaveTeamModal = this.hideLeaveTeamModal.bind(this); (this: any).hideLeaveTeamModal = this.hideLeaveTeamModal.bind(this);
} }
@ -49,10 +54,6 @@ class TeamsDataTable extends Component<Props, State> {
(this: any).setState({ leaveTeamModalShow: false, team: DefaultTeam }); (this: any).setState({ leaveTeamModalShow: false, team: DefaultTeam });
} }
linkToTeam(name: string, team: Teams$Team): Node {
return <Link to={`${SETTINGS_TEAMS_ROUTE}/${team.id}`}>{name}</Link>;
}
leaveTeamButton(id: string, team: Teams$Team): Node { leaveTeamButton(id: string, team: Teams$Team): Node {
if (team.can_be_left) { if (team.can_be_left) {
return ( return (
@ -73,6 +74,8 @@ class TeamsDataTable extends Component<Props, State> {
defaultSortName: "name", defaultSortName: "name",
defaultSortOrder: "desc", defaultSortOrder: "desc",
sizePerPageList: [10, 25, 50, 100], sizePerPageList: [10, 25, 50, 100],
sizePerPage: this.props.sizePerPage,
onSizePerPageList: this.props.onSizePerPageList,
prePage: "Prev", // Previous page button text prePage: "Prev", // Previous page button text
nextPage: "Next", // Next page button textu nextPage: "Next", // Next page button textu
paginationShowsTotal: DataTable.renderShowsTotal, paginationShowsTotal: DataTable.renderShowsTotal,
@ -84,7 +87,7 @@ class TeamsDataTable extends Component<Props, State> {
name: "Team", name: "Team",
isKey: false, isKey: false,
textId: "name", textId: "name",
dataFormat: this.linkToTeam, dataFormat: TeamsDataTable.linkToTeam,
position: 0, position: 0,
dataSort: true, dataSort: true,
width: "50%" width: "50%"

View file

@ -20,7 +20,9 @@ const Wrapper = styled.div`
`; `;
type Props = { type Props = {
tabState: Function tabState: Function,
sizePerPage: number,
onSizePerPageList: Function
}; };
type State = { type State = {
@ -70,6 +72,8 @@ class SettingsTeams extends Component<Props, State> {
<TeamsDataTable <TeamsDataTable
teams={this.state.teams} teams={this.state.teams}
updateTeamsState={this.updateTeamsState} updateTeamsState={this.updateTeamsState}
sizePerPage={this.props.sizePerPage}
onSizePerPageList={this.props.onSizePerPageList}
/> />
</Wrapper> </Wrapper>
</PageTitle> </PageTitle>