forked from line/centraldogma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
108 lines (103 loc) · 4.32 KB
/
index.tsx
File metadata and controls
108 lines (103 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Badge, Box, Flex, Spacer, Text, Wrap } from '@chakra-ui/react';
import { createColumnHelper } from '@tanstack/react-table';
import { DateWithTooltip } from 'dogma/common/components/DateWithTooltip';
import { CertificateWrapper } from 'dogma/features/app-identity/CertificateWrapper';
import { NewAppIdentity } from 'dogma/features/app-identity/NewAppIdentity';
import { SecretWrapper } from 'dogma/features/app-identity/SecretWrapper';
import { UserRole } from 'dogma/common/components/UserRole';
import { DataTableClientPagination } from 'dogma/common/components/table/DataTableClientPagination';
import { useGetAppIdentitiesQuery } from 'dogma/features/api/apiSlice';
import { AppIdentityDto, isToken, isCertificate } from 'dogma/features/app-identity/AppIdentity';
import { useMemo } from 'react';
import { DeactivateAppIdentity } from 'dogma/features/app-identity/DeactivateAppIdentity';
import { ActivateAppIdentity } from 'dogma/features/app-identity/ActivateAppIdentity';
import { DeleteAppIdentity } from 'dogma/features/app-identity/DeleteAppIdentity';
import { Deferred } from 'dogma/common/components/Deferred';
import SettingView from 'dogma/features/settings/SettingView';
import { useAppSelector } from 'dogma/hooks';
const AppIdentityPage = () => {
const systemAdmin = useAppSelector((state) => state.auth.user?.systemAdmin ?? false);
const columnHelper = createColumnHelper<AppIdentityDto>();
const columns = useMemo(
() => [
columnHelper.accessor((row: AppIdentityDto) => row.appId, {
cell: (info) => {
const identity = info.row.original;
if (isToken(identity)) {
return identity.secret ? (
<SecretWrapper appId={info.getValue()} secret={identity.secret} />
) : (
<Text>{info.getValue()}</Text>
);
}
if (isCertificate(identity)) {
return <CertificateWrapper appId={info.getValue()} certificateId={identity.certificateId} />;
}
return <Text>{info.getValue()}</Text>;
},
header: 'Application ID',
}),
columnHelper.accessor((row: AppIdentityDto) => row.type, {
cell: (info) => (
<Badge colorScheme={info.getValue() === 'TOKEN' ? 'purple' : 'green'}>
{info.getValue() === 'TOKEN' ? 'Token' : 'Certificate'}
</Badge>
),
header: 'Type',
}),
...(systemAdmin
? [
columnHelper.accessor((row: AppIdentityDto) => row.systemAdmin, {
cell: (info) => <UserRole role={info.getValue() ? 'System Admin' : 'User'} />,
header: 'Level',
}),
]
: []),
columnHelper.accessor((row: AppIdentityDto) => row.creation.user, {
cell: (info) => <Text>{info.getValue()}</Text>,
header: 'Created By',
}),
columnHelper.accessor((row: AppIdentityDto) => row.creation.timestamp, {
cell: (info) => <DateWithTooltip date={info.getValue()} />,
header: 'Created At',
}),
columnHelper.accessor((row: AppIdentityDto) => row.deactivation, {
cell: (info) => (
<Badge colorScheme={info.getValue() ? 'gray' : 'blue'}>
{info.getValue() ? 'Inactive' : 'Active'}
</Badge>
),
header: 'Status',
}),
columnHelper.accessor((row: AppIdentityDto) => row.deactivation, {
cell: (info) => (
<Wrap>
<ActivateAppIdentity appId={info.row.original.appId} hidden={info.getValue() === undefined} />
<DeactivateAppIdentity appId={info.row.original.appId} hidden={info.getValue() !== undefined} />
<DeleteAppIdentity appId={info.row.original.appId} hidden={info.getValue() === undefined} />
</Wrap>
),
header: 'Actions',
enableSorting: false,
}),
],
[columnHelper, systemAdmin],
);
const { data, error, isLoading } = useGetAppIdentitiesQuery();
return (
<SettingView currentTab={'Application Identities'}>
<Deferred isLoading={isLoading} error={error}>
{() => (
<Box p="2">
<Flex>
<Spacer />
<NewAppIdentity />
</Flex>
<DataTableClientPagination columns={columns} data={data || []} />
</Box>
)}
</Deferred>
</SettingView>
);
};
export default AppIdentityPage;