1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { WithStyles } from '@mui/styles';
8 import withStyles from '@mui/styles/withStyles';
9 import { ArvadosTheme } from 'common/custom-theme';
10 import { 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 { API_CLIENT_AUTHORIZATION_PANEL_ID } from '../../store/api-client-authorizations/api-client-authorizations-actions';
15 import { DataExplorer } from 'views-components/data-explorer/data-explorer';
16 import { ResourcesState } from 'store/resources/resources';
18 CommonUuid, TokenApiToken, TokenCreatedByIpAddress, TokenExpiresAt,
19 TokenLastUsedAt, TokenLastUsedByIpAddress, TokenScopes, TokenUserId
20 } from 'views-components/data-explorer/renderers';
21 import { ApiClientAuthorization } from 'models/api-client-authorization';
23 type CssRules = 'root';
25 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 export enum ApiClientAuthorizationPanelColumnNames {
34 API_TOKEN = 'API Token',
35 CREATED_BY_IP_ADDRESS = 'Created by IP address',
36 EXPIRES_AT = 'Expires at',
37 LAST_USED_AT = 'Last used at',
38 LAST_USED_BY_IP_ADDRESS = 'Last used by IP address',
43 export const apiClientAuthorizationPanelColumns: DataColumns<string, ApiClientAuthorization> = [
45 name: ApiClientAuthorizationPanelColumnNames.UUID,
48 sort: {direction: SortDirection.NONE, field: "uuid"},
49 filters: createTree(),
50 render: uuid => <CommonUuid uuid={uuid} />
53 name: ApiClientAuthorizationPanelColumnNames.API_TOKEN,
56 filters: createTree(),
57 render: uuid => <TokenApiToken uuid={uuid} />
60 name: ApiClientAuthorizationPanelColumnNames.CREATED_BY_IP_ADDRESS,
63 filters: createTree(),
64 render: uuid => <TokenCreatedByIpAddress uuid={uuid} />
67 name: ApiClientAuthorizationPanelColumnNames.EXPIRES_AT,
70 filters: createTree(),
71 render: uuid => <TokenExpiresAt uuid={uuid} />
74 name: ApiClientAuthorizationPanelColumnNames.LAST_USED_AT,
77 filters: createTree(),
78 render: uuid => <TokenLastUsedAt uuid={uuid} />
81 name: ApiClientAuthorizationPanelColumnNames.LAST_USED_BY_IP_ADDRESS,
84 filters: createTree(),
85 render: uuid => <TokenLastUsedByIpAddress uuid={uuid} />
88 name: ApiClientAuthorizationPanelColumnNames.SCOPES,
91 filters: createTree(),
92 render: uuid => <TokenScopes uuid={uuid} />
95 name: ApiClientAuthorizationPanelColumnNames.USER_ID,
98 filters: createTree(),
99 render: uuid => <TokenUserId uuid={uuid} />
103 const DEFAULT_MESSAGE = 'Your api client authorization list is empty.';
105 export interface ApiClientAuthorizationPanelRootActionProps {
106 onItemClick: (item: string) => void;
107 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
108 onItemDoubleClick: (item: string) => void;
111 export interface ApiClientAuthorizationPanelRootDataProps {
112 resources: ResourcesState;
115 type ApiClientAuthorizationPanelRootProps = ApiClientAuthorizationPanelRootActionProps
116 & ApiClientAuthorizationPanelRootDataProps & WithStyles<CssRules>;
118 export const ApiClientAuthorizationPanelRoot = withStyles(styles)(
119 ({ classes, onItemDoubleClick, onItemClick, onContextMenu }: ApiClientAuthorizationPanelRootProps) =>
120 <div className={classes.root}><DataExplorer
121 id={API_CLIENT_AUTHORIZATION_PANEL_ID}
122 onRowClick={onItemClick}
123 onRowDoubleClick={onItemDoubleClick}
124 onContextMenu={onContextMenu}
125 contextMenuColumn={true}
128 defaultViewIcon={ShareMeIcon}
129 defaultViewMessages={[DEFAULT_MESSAGE]} />