Skip to content

Commit

Permalink
fix(connector): show service accounts (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
manojava-gk authored May 27, 2024
1 parent 30a9185 commit 5d37e3c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
- Api url typo fix
- App Access Management
- Fix carousel element issue
- Connectors
- Fetch all service accounts and show them in the auto complete list
- Admin Credential
- Change document download endpoint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,9 @@ any) => {
const [serviceAccountUsers, setServiceAccountUsers] = useState([])

useEffect(() => {
if (fetchServiceAccountUsers?.content)
if (fetchServiceAccountUsers)
setServiceAccountUsers(
fetchServiceAccountUsers.content?.filter(
(item: { name: string }) => item.name
)
fetchServiceAccountUsers?.filter((item: { name: string }) => item.name)
)
}, [fetchServiceAccountUsers])

Expand Down
20 changes: 17 additions & 3 deletions src/components/pages/EdcConnector/AddConnectorOverlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import {
} from 'features/connector/connectorApiSlice'
import Box from '@mui/material/Box'
import { useFetchOwnCompanyDetailsQuery } from 'features/admin/userApiSlice'
import { useFetchServiceAccountUsersQuery } from 'features/admin/serviceApiSlice'
import {
type ServiceAccountListEntry,
useFetchServiceAccountUsersQuery,
} from 'features/admin/serviceApiSlice'

interface AddCollectorOverlayProps {
openDialog?: boolean
Expand Down Expand Up @@ -97,8 +100,10 @@ const AddConnectorOverlay = ({
const { t } = useTranslation()
const { data } = useFetchOfferSubscriptionsQuery()
const { data: ownCompanyDetails } = useFetchOwnCompanyDetailsQuery()
const fetchServiceAccountUsers = useFetchServiceAccountUsersQuery().data
const [page, setPage] = useState<number>(0)
const { data: serviceAccounts } = useFetchServiceAccountUsersQuery(page)
const [newTechnicalUSer, setNewTechnicalUSer] = useState(false)
const [allAccounts, setAllAccounts] = useState<ServiceAccountListEntry[]>([])

const {
handleSubmit,
Expand All @@ -118,6 +123,15 @@ const AddConnectorOverlay = ({
if (openDialog) reset(formFields)
}, [openDialog, reset])

useEffect(() => {
if (serviceAccounts && serviceAccounts?.meta?.totalPages > page) {
setPage((pre) => pre + 1)
setAllAccounts((i: ServiceAccountListEntry[]) =>
i.concat(serviceAccounts?.content)
)
}
}, [serviceAccounts])

const onFormSubmit = async () => {
const validateFields =
newTechnicalUSer && !newUserSuccess
Expand Down Expand Up @@ -197,7 +211,7 @@ const AddConnectorOverlay = ({
<ConnectorInsertForm
subscriptions={data}
selectedService={selected}
fetchServiceAccountUsers={fetchServiceAccountUsers}
fetchServiceAccountUsers={allAccounts}
onFormSubmitt={onFormSubmit}
setNewTechnicalUSer={setNewTechnicalUSer}
newUserLoading={newUserLoading}
Expand Down
19 changes: 16 additions & 3 deletions src/features/admin/serviceApiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ export type AppRoleCreate = {
roles: string[]
}

export interface ServiceAccountsResponseType {
content: ServiceAccountListEntry[]
meta: {
contentSize: number
page: number
totalElements: number
totalPages: number
}
}

export enum ServiceAccountStatusFilter {
ACTIVE = 'ACTIVE',
INACTIVE = 'INACTIVE',
Expand Down Expand Up @@ -165,9 +175,12 @@ export const apiSlice = createApi({
method: 'POST',
}),
}),
fetchServiceAccountUsers: builder.query<ServiceAccountListEntry[], void>({
query: () =>
`/api/administration/serviceaccount/owncompany/serviceaccounts?page=0&size=${PAGE_SIZE}&filterForInactive=false`,
fetchServiceAccountUsers: builder.query<
ServiceAccountsResponseType,
number
>({
query: (page) =>
`/api/administration/serviceaccount/owncompany/serviceaccounts?page=${page}&size=${PAGE_SIZE}&filterForInactive=false`,
}),
}),
})
Expand Down

0 comments on commit 5d37e3c

Please sign in to comment.