From 1bb29ec5f78bba609a97183cfb74e5592d5935c5 Mon Sep 17 00:00:00 2001 From: Keith Grant Date: Thu, 21 May 2020 16:24:11 -0700 Subject: [PATCH] add user teams list --- awx/ui_next/src/api/models/Users.js | 6 ++ .../UserOrganizationListItem.jsx | 14 ++-- .../src/screens/User/UserTeams/UserTeams.jsx | 12 ++-- .../screens/User/UserTeams/UserTeamsList.jsx | 70 +++++++++++++++++++ .../User/UserTeams/UserTeamsListItem.jsx | 43 ++++++++++++ 5 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 awx/ui_next/src/screens/User/UserTeams/UserTeamsList.jsx create mode 100644 awx/ui_next/src/screens/User/UserTeams/UserTeamsListItem.jsx diff --git a/awx/ui_next/src/api/models/Users.js b/awx/ui_next/src/api/models/Users.js index b98cf45cae..3f5a177390 100644 --- a/awx/ui_next/src/api/models/Users.js +++ b/awx/ui_next/src/api/models/Users.js @@ -34,6 +34,12 @@ class Users extends Base { readRoleOptions(userId) { return this.http.options(`${this.baseUrl}${userId}/roles/`); } + + readTeams(userId, params) { + return this.http.get(`${this.baseUrl}${userId}/teams/`, { + params, + }); + } } export default Users; diff --git a/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.jsx b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.jsx index f45c9a5b93..bc01af942d 100644 --- a/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.jsx +++ b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.jsx @@ -1,7 +1,5 @@ import React from 'react'; import { Link } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; -import { t } from '@lingui/macro'; import { DataListItemCells, DataListItemRow, @@ -9,14 +7,18 @@ import { } from '@patternfly/react-core'; import DataListCell from '../../../components/DataListCell'; -function UserOrganizationListItem({ organization, i18n }) { +export default function UserOrganizationListItem({ organization }) { + const labelId = `organization-${organization.id}`; return ( - + - + {organization.name} , @@ -29,5 +31,3 @@ function UserOrganizationListItem({ organization, i18n }) { ); } - -export default withI18n()(UserOrganizationListItem); diff --git a/awx/ui_next/src/screens/User/UserTeams/UserTeams.jsx b/awx/ui_next/src/screens/User/UserTeams/UserTeams.jsx index 5d342e00f2..1cfc018236 100644 --- a/awx/ui_next/src/screens/User/UserTeams/UserTeams.jsx +++ b/awx/ui_next/src/screens/User/UserTeams/UserTeams.jsx @@ -1,10 +1,6 @@ -import React, { Component } from 'react'; -import { CardBody } from '../../../components/Card'; +import React from 'react'; +import UserTeamsList from './UserTeamsList'; -class UserAdd extends Component { - render() { - return Coming soon :); - } +export default function UserTeams() { + return ; } - -export default UserAdd; diff --git a/awx/ui_next/src/screens/User/UserTeams/UserTeamsList.jsx b/awx/ui_next/src/screens/User/UserTeams/UserTeamsList.jsx new file mode 100644 index 0000000000..6bc06dba3e --- /dev/null +++ b/awx/ui_next/src/screens/User/UserTeams/UserTeamsList.jsx @@ -0,0 +1,70 @@ +import React, { useCallback, useEffect } from 'react'; +import { withI18n } from '@lingui/react'; +import { useLocation, useParams } from 'react-router-dom'; +import { t } from '@lingui/macro'; + +import PaginatedDataList from '../../../components/PaginatedDataList'; +import useRequest from '../../../util/useRequest'; +import { UsersAPI } from '../../../api'; +import { getQSConfig, parseQueryString } from '../../../util/qs'; +import UserTeamListItem from './UserTeamsListItem'; + +const QS_CONFIG = getQSConfig('teams', { + page: 1, + page_size: 20, + order_by: 'name', +}); + +function UserTeamsList({ i18n }) { + const location = useLocation(); + const { id: userId } = useParams(); + + const { + result: { teams, count }, + error: contentError, + isLoading, + request: fetchOrgs, + } = useRequest( + useCallback(async () => { + const params = parseQueryString(QS_CONFIG, location.search); + const { + data: { results, count: teamCount }, + } = await UsersAPI.readTeams(userId, params); + return { + teams: results, + count: teamCount, + }; + }, [userId, location.search]), + { + teams: [], + count: 0, + } + ); + + useEffect(() => { + fetchOrgs(); + }, [fetchOrgs]); + + return ( + ( + {}} + isSelected={false} + /> + )} + /> + ); +} + +export default withI18n()(UserTeamsList); diff --git a/awx/ui_next/src/screens/User/UserTeams/UserTeamsListItem.jsx b/awx/ui_next/src/screens/User/UserTeams/UserTeamsListItem.jsx new file mode 100644 index 0000000000..44995f004c --- /dev/null +++ b/awx/ui_next/src/screens/User/UserTeams/UserTeamsListItem.jsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { withI18n } from '@lingui/react'; +import { t } from '@lingui/macro'; +import { + DataListItemCells, + DataListItemRow, + DataListItem, +} from '@patternfly/react-core'; +import DataListCell from '../../../components/DataListCell'; + +function UserTeamsListItem({ team, i18n }) { + return ( + + + + + {team.name} + + , + + {team.summary_fields.organization && ( + <> + {i18n._(t`Organization`)} + + {team.summary_fields.organization.name} + + + )} + , + {team.description}, + ]} + /> + + + ); +} + +export default withI18n()(UserTeamsListItem);