From 00056ffb7e4bb18ad4ce36b98d2671fd3902fad3 Mon Sep 17 00:00:00 2001 From: Pascal Mugnier Date: Mon, 28 May 2018 09:30:28 +0200 Subject: [PATCH] SONAR-10712 Add pagination to Quality Profile project list --- .../details/ProfileProjects.tsx | 57 ++++++++++++------- .../js/components/controls/ListFooter.tsx | 4 +- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx index 29a1c9617da..2d326240f6e 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileProjects.tsx @@ -24,6 +24,7 @@ import { Profile } from '../types'; import { getProfileProjects } from '../../../api/quality-profiles'; import QualifierIcon from '../../../components/icons-components/QualifierIcon'; import { Button } from '../../../components/ui/buttons'; +import ListFooter from '../../../components/controls/ListFooter'; import { translate } from '../../../helpers/l10n'; interface Props { @@ -35,8 +36,10 @@ interface Props { interface State { formOpen: boolean; loading: boolean; - more?: boolean; + page: number; projects: Array<{ key: string; name: string; uuid: string }> | null; + ready: boolean; + total: number; } export default class ProfileProjects extends React.PureComponent { @@ -45,7 +48,10 @@ export default class ProfileProjects extends React.PureComponent { state: State = { formOpen: false, loading: true, - projects: null + page: 1, + projects: null, + ready: true, + total: 0 }; componentDidMount() { @@ -69,21 +75,26 @@ export default class ProfileProjects extends React.PureComponent { return; } - const data = { key: this.props.profile.key }; + const data = { key: this.props.profile.key, page: this.state.page }; getProfileProjects(data).then( (r: any) => { if (this.mounted) { - this.setState({ - projects: r.results, - more: r.more, - loading: false - }); + this.setState(state => ({ + projects: state.projects ? [...state.projects, ...r.results] : r.results, + total: r.paging.total, + loading: false, + ready: true + })); } }, () => {} ); } + loadMore = () => { + this.setState(state => ({ ready: false, page: state.page + 1 }), this.loadProjects); + }; + handleChangeClick = () => { this.setState({ formOpen: true }); }; @@ -122,17 +133,25 @@ export default class ProfileProjects extends React.PureComponent { } return ( -
    - {projects.map(project => ( -
  • - - {project.name} - -
  • - ))} -
+ <> +
    + {projects.map(project => ( +
  • + + {project.name} + +
  • + ))} +
+ + ); } diff --git a/server/sonar-web/src/main/js/components/controls/ListFooter.tsx b/server/sonar-web/src/main/js/components/controls/ListFooter.tsx index d17a5a3385e..29113a8edbb 100644 --- a/server/sonar-web/src/main/js/components/controls/ListFooter.tsx +++ b/server/sonar-web/src/main/js/components/controls/ListFooter.tsx @@ -27,7 +27,7 @@ interface Props { className?: string; loadMore?: () => void; ready?: boolean; - total: number; + total?: number; } export default function ListFooter({ ready = true, ...props }: Props) { @@ -39,7 +39,7 @@ export default function ListFooter({ ready = true, ...props }: Props) { } }; - const hasMore = props.total > props.count; + const hasMore = props.total && props.total > props.count; const loadMoreLink = ( {translate('show_more')} -- 2.39.5