1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
7 StyleRulesCallback, WithStyles, withStyles, Card, CardContent, Grid, Tooltip, IconButton
8 } from '@material-ui/core';
9 import { ArvadosTheme } from '~/common/custom-theme';
10 import { HelpIcon, ShareMeIcon } from '~/components/icon/icon';
11 import { createTree } from '~/models/tree';
12 import { DataColumns } from '~/components/data-table/data-table';
13 import { SortDirection } from '~/components/data-table/data-column';
14 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
15 import { API_CLIENT_AUTHORIZATION_PANEL_ID } from '../../store/api-client-authorizations/api-client-authorizations-actions';
16 import { DataExplorer } from '~/views-components/data-explorer/data-explorer';
17 import { ResourcesState } from '~/store/resources/resources';
19 CommonUuid, TokenApiClientId, TokenApiToken, TokenCreatedByIpAddress, TokenDefaultOwnerUuid, TokenExpiresAt,
20 TokenLastUsedAt, TokenLastUsedByIpAddress, TokenScopes, TokenUserId
21 } from '~/views-components/data-explorer/renderers';
23 type CssRules = 'card' | 'cardContent' | 'helpIconGrid';
25 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 export enum ApiClientAuthorizationPanelColumnNames {
44 API_CLIENT_ID = 'API Client ID',
45 API_TOKEN = 'API Token',
46 CREATED_BY_IP_ADDRESS = 'Created by IP address',
47 DEFAULT_OWNER_UUID = 'Default owner',
48 EXPIRES_AT = 'Expires at',
49 LAST_USED_AT = 'Last used at',
50 LAST_USED_BY_IP_ADDRESS = 'Last used by IP address',
55 export const apiClientAuthorizationPanelColumns: DataColumns<string> = [
57 name: ApiClientAuthorizationPanelColumnNames.UUID,
60 sortDirection: SortDirection.NONE,
61 filters: createTree(),
62 render: uuid => <CommonUuid uuid={uuid} />
65 name: ApiClientAuthorizationPanelColumnNames.API_CLIENT_ID,
68 filters: createTree(),
69 render: uuid => <TokenApiClientId uuid={uuid} />
72 name: ApiClientAuthorizationPanelColumnNames.API_TOKEN,
75 filters: createTree(),
76 render: uuid => <TokenApiToken uuid={uuid} />
79 name: ApiClientAuthorizationPanelColumnNames.CREATED_BY_IP_ADDRESS,
82 filters: createTree(),
83 render: uuid => <TokenCreatedByIpAddress uuid={uuid} />
86 name: ApiClientAuthorizationPanelColumnNames.DEFAULT_OWNER_UUID,
89 filters: createTree(),
90 render: uuid => <TokenDefaultOwnerUuid uuid={uuid} />
93 name: ApiClientAuthorizationPanelColumnNames.EXPIRES_AT,
96 filters: createTree(),
97 render: uuid => <TokenExpiresAt uuid={uuid} />
100 name: ApiClientAuthorizationPanelColumnNames.LAST_USED_AT,
103 filters: createTree(),
104 render: uuid => <TokenLastUsedAt uuid={uuid} />
107 name: ApiClientAuthorizationPanelColumnNames.LAST_USED_BY_IP_ADDRESS,
110 filters: createTree(),
111 render: uuid => <TokenLastUsedByIpAddress uuid={uuid} />
114 name: ApiClientAuthorizationPanelColumnNames.SCOPES,
117 filters: createTree(),
118 render: uuid => <TokenScopes uuid={uuid} />
121 name: ApiClientAuthorizationPanelColumnNames.USER_ID,
124 filters: createTree(),
125 render: uuid => <TokenUserId uuid={uuid} />
129 const DEFAULT_MESSAGE = 'Your api client authorization list is empty.';
131 export interface ApiClientAuthorizationPanelRootActionProps {
132 onItemClick: (item: string) => void;
133 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
134 onItemDoubleClick: (item: string) => void;
135 openHelpDialog: () => void;
138 export interface ApiClientAuthorizationPanelRootDataProps {
139 resources: ResourcesState;
142 type ApiClientAuthorizationPanelRootProps = ApiClientAuthorizationPanelRootActionProps
143 & ApiClientAuthorizationPanelRootDataProps & WithStyles<CssRules>;
145 export const ApiClientAuthorizationPanelRoot = withStyles(styles)(
146 ({ classes, onItemDoubleClick, onItemClick, onContextMenu, openHelpDialog }: ApiClientAuthorizationPanelRootProps) =>
147 <Card className={classes.card}>
148 <CardContent className={classes.cardContent}>
149 <Grid container direction="row" justify="flex-end">
150 <Grid item xs={12} className={classes.helpIconGrid}>
151 <Tooltip title="Api token - help">
152 <IconButton onClick={openHelpDialog}>
159 id={API_CLIENT_AUTHORIZATION_PANEL_ID}
160 onRowClick={onItemClick}
161 onRowDoubleClick={onItemDoubleClick}
162 onContextMenu={onContextMenu}
163 contextMenuColumn={true}
166 dataTableDefaultView={
167 <DataTableDefaultView
169 messages={[DEFAULT_MESSAGE]} />