diff --git a/src/components/FormattedTableColumn.tsx b/src/components/FormattedTableColumn.tsx
index a987b608..9beb1a38 100644
--- a/src/components/FormattedTableColumn.tsx
+++ b/src/components/FormattedTableColumn.tsx
@@ -1,9 +1,9 @@
import { Text, Link } from '@statisticsnorway/ssb-component-library'
interface FormattedTableColumnProps {
- href: string
- linkText: string
- text: string
+ href?: string
+ linkText?: string
+ text?: string
}
const FormattedTableColumn = (props: FormattedTableColumnProps) => {
@@ -12,11 +12,13 @@ const FormattedTableColumn = (props: FormattedTableColumnProps) => {
return (
<>
-
- {linkText}
-
+ {href && linkText && (
+
+ {linkText}
+
+ )}
- {text}
+ {text && {text}}
>
)
}
diff --git a/src/pages/TeamDetail/TeamDetail.tsx b/src/pages/TeamDetail/TeamDetail.tsx
index 49b18749..37f83280 100644
--- a/src/pages/TeamDetail/TeamDetail.tsx
+++ b/src/pages/TeamDetail/TeamDetail.tsx
@@ -17,19 +17,24 @@ import PageSkeleton from '../../components/PageSkeleton/PageSkeleton'
import { Skeleton } from '@mui/material'
import FormattedTableColumn from '../../components/FormattedTableColumn'
-const TeamDetail = () => {
- const defaultActiveTab = {
- title: 'Teammedlemmer',
- path: 'team',
- }
+const TEAM_USERS_TAB = {
+ title: 'Teammedlemmer',
+ path: 'team',
+}
- const [activeTab, setActiveTab] = useState(defaultActiveTab)
+const SHARED_BUCKETS_TAB = {
+ title: 'Delte data',
+ path: 'sharedBuckets',
+}
+
+const TeamDetail = () => {
+ const [activeTab, setActiveTab] = useState(TEAM_USERS_TAB)
const { setBreadcrumbTeamDetailDisplayName } = useContext(DaplaCtrlContext)
const [error, setError] = useState()
const [loadingTeamData, setLoadingTeamData] = useState(true)
const [teamDetailData, setTeamDetailData] = useState()
- const [teamDetailTableTitle, setTeamDetailTableTitle] = useState(defaultActiveTab.title)
+ const [teamDetailTableTitle, setTeamDetailTableTitle] = useState(TEAM_USERS_TAB.title)
const [teamDetailTableData, setTeamDetailTableData] = useState()
const { teamId } = useParams<{ teamId: string }>()
@@ -37,8 +42,9 @@ const TeamDetail = () => {
const prepTeamData = useCallback(
(response: TeamDetailData): TableData['data'] => {
const teamDetailTab = (activeTab as TabProps)?.path ?? activeTab
- if (teamDetailTab === 'sharedBuckets') {
- const sharedBuckets = (response['sharedBuckets'] as SharedBuckets).items
+ const sharedBucketsTab = SHARED_BUCKETS_TAB.path
+ if (teamDetailTab === sharedBucketsTab) {
+ const sharedBuckets = (response[sharedBucketsTab] as SharedBuckets).items
if (!sharedBuckets) return []
return sharedBuckets.map(({ short_name, bucket_name, metrics }) => {
@@ -52,25 +58,25 @@ const TeamDetail = () => {
}
})
} else {
- const teamUsers = (response['team'] as Team).users
+ const teamUsers = (response[TEAM_USERS_TAB.path] as Team).users
if (!teamUsers) return []
- return teamUsers.map((user) => {
+ return teamUsers.map(({ display_name, principal_name, section_name, groups }) => {
return {
- id: formatDisplayName(user.display_name),
+ id: formatDisplayName(display_name),
navn: (
),
- seksjon: user.section_name, // Makes section name searchable and sortable in table by including the field
- gruppe: user.groups
+ seksjon: section_name, // Makes section name searchable and sortable in table by including the field
+ gruppe: groups
?.filter((group) => group.uniform_name.startsWith((response.team as Team).uniform_name))
.map((group) => getGroupType(group.uniform_name))
.join(', '),
- epost: user?.principal_name,
+ epost: principal_name,
}
})
}
@@ -101,10 +107,10 @@ const TeamDetail = () => {
const handleTabClick = (tab: string) => {
setActiveTab(tab)
- if (tab === defaultActiveTab.path) {
- setTeamDetailTableTitle(defaultActiveTab.title)
+ if (tab === TEAM_USERS_TAB.path) {
+ setTeamDetailTableTitle(TEAM_USERS_TAB.title)
} else {
- setTeamDetailTableTitle('Delte data')
+ setTeamDetailTableTitle(SHARED_BUCKETS_TAB.title)
}
}
@@ -120,9 +126,9 @@ const TeamDetail = () => {
if (error) return renderErrorAlert()
if (loadingTeamData) return
- if (teamDetailTableData) {
+ if (teamDetailData && teamDetailTableData) {
const teamOverviewTableHeaderColumns =
- activeTab === 'sharedBuckets'
+ activeTab === SHARED_BUCKETS_TAB.path
? [
{
id: 'navn',
@@ -154,24 +160,22 @@ const TeamDetail = () => {
<>
- {teamDetailData ? (teamDetailData.team as Team).uniform_name : ''}
-
-
- {teamDetailData ? formatDisplayName((teamDetailData.team as Team).manager?.display_name ?? '') : ''}
+ {(teamDetailData.team as Team).uniform_name ?? ''}
- {teamDetailData ? (teamDetailData.team as Team).section_name : ''}
+ {formatDisplayName((teamDetailData.team as Team).manager?.display_name ?? '')}
+ {(teamDetailData.team as Team).section_name ?? ''}
diff --git a/src/pages/TeamMembers/TeamMembers.tsx b/src/pages/TeamMembers/TeamMembers.tsx
index 78408f09..76483dea 100644
--- a/src/pages/TeamMembers/TeamMembers.tsx
+++ b/src/pages/TeamMembers/TeamMembers.tsx
@@ -1,26 +1,32 @@
/* eslint-disable react-hooks/exhaustive-deps */
import { useCallback, useEffect, useState } from 'react'
-import { Dialog, Text, Link, Tabs, Divider } from '@statisticsnorway/ssb-component-library'
+import { Dialog, Tabs, Divider } from '@statisticsnorway/ssb-component-library'
import { TabProps } from '../../@types/pageTypes'
import PageLayout from '../../components/PageLayout/PageLayout'
import Table, { TableData } from '../../components/Table/Table'
import PageSkeleton from '../../components/PageSkeleton/PageSkeleton'
-import { fetchAllTeamMembersData, TeamMembersData, User } from '../../services/teamMembers'
+import { fetchAllTeamMembersData, TeamMembersData } from '../../services/teamMembers'
import { formatDisplayName } from '../../utils/utils'
import { ApiError, fetchUserInformationFromAuthToken } from '../../utils/services'
+import FormattedTableColumn from '../../components/FormattedTableColumn'
-const TeamMembers = () => {
- const defaultActiveTab = {
- title: 'Mine teammedlemmer',
- path: 'myUsers',
- }
+const MY_USERS_TAB = {
+ title: 'Mine teammedlemmer',
+ path: 'myUsers',
+}
- const [activeTab, setActiveTab] = useState(defaultActiveTab)
+const ALL_USERS_TAB = {
+ title: 'Alle teammedlemmer',
+ path: 'allUsers',
+}
+
+const TeamMembers = () => {
+ const [activeTab, setActiveTab] = useState(MY_USERS_TAB)
const [teamMembersData, setTeamMembersData] = useState()
const [teamMembersTableData, setTeamMembersTableData] = useState()
- const [teamMembersTableTitle, setTeamMembersTableTitle] = useState(defaultActiveTab.title)
+ const [teamMembersTableTitle, setTeamMembersTableTitle] = useState(MY_USERS_TAB.title)
const [error, setError] = useState()
const [loading, setLoading] = useState(true)
@@ -28,19 +34,27 @@ const TeamMembers = () => {
(response: TeamMembersData): TableData['data'] => {
const teamMember = (activeTab as TabProps)?.path ?? activeTab
- return response[teamMember].users.map((teamMember) => ({
- id: formatDisplayName(teamMember.display_name),
- navn: renderUserNameColumn(teamMember),
- team: teamMember.teams.length,
- epost: teamMember.principal_name,
- data_admin_roller: teamMember.groups.filter((group) => group.uniform_name.endsWith('data-admins')).length,
- seksjon: teamMember.section_name, // Makes section name searchable and sortable in table by including the field
- seksjonsleder: formatDisplayName(
- teamMember.section_manager && teamMember.section_manager.length > 0
- ? teamMember.section_manager[0].display_name
- : 'Seksjonsleder ikke funnet'
- ),
- }))
+ return response[teamMember].users.map(
+ ({ display_name, principal_name, section_name, section_manager, teams, groups }) => ({
+ id: formatDisplayName(display_name),
+ navn: (
+
+ ),
+ team: teams.length,
+ epost: principal_name,
+ data_admin_roller: groups.filter((group) => group.uniform_name.endsWith('data-admins')).length,
+ seksjon: section_name, // Makes section name searchable and sortable in table by including the field
+ seksjonsleder: formatDisplayName(
+ section_manager && section_manager.length > 0
+ ? section_manager[0].display_name
+ : 'Seksjonsleder ikke funnet' // TODO: Should be handled in services
+ ),
+ })
+ )
},
[activeTab]
)
@@ -72,26 +86,13 @@ const TeamMembers = () => {
const handleTabClick = (tab: string) => {
setActiveTab(tab)
- if (tab === defaultActiveTab.path) {
- setTeamMembersTableTitle(defaultActiveTab.title)
+ if (tab === MY_USERS_TAB.path) {
+ setTeamMembersTableTitle(MY_USERS_TAB.title)
} else {
- setTeamMembersTableTitle('Alle teammedlemmer')
+ setTeamMembersTableTitle(ALL_USERS_TAB.title)
}
}
- const renderUserNameColumn = (user: User) => {
- return (
- <>
-
-
- {user.display_name}
-
-
- {user.section_name && {user.section_name}}
- >
- )
- }
-
const renderErrorAlert = () => {
return (