1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
7 StyleRulesCallback, WithStyles, withStyles
8 } from '@material-ui/core';
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, TokenApiClientId, TokenApiToken, TokenCreatedByIpAddress, TokenDefaultOwnerUuid, 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: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 export enum ApiClientAuthorizationPanelColumnNames {
34 API_CLIENT_ID = 'API Client ID',
35 API_TOKEN = 'API Token',
36 CREATED_BY_IP_ADDRESS = 'Created by IP address',
37 DEFAULT_OWNER_UUID = 'Default owner',
38 EXPIRES_AT = 'Expires at',
39 LAST_USED_AT = 'Last used at',
40 LAST_USED_BY_IP_ADDRESS = 'Last used by IP address',
45 export const apiClientAuthorizationPanelColumns: DataColumns<string, ApiClientAuthorization> = [
47 name: ApiClientAuthorizationPanelColumnNames.UUID,
50 sort: {direction: SortDirection.NONE, field: "uuid"},
51 filters: createTree(),
52 render: uuid => <CommonUuid uuid={uuid} />
55 name: ApiClientAuthorizationPanelColumnNames.API_CLIENT_ID,
58 filters: createTree(),
59 render: uuid => <TokenApiClientId uuid={uuid} />
62 name: ApiClientAuthorizationPanelColumnNames.API_TOKEN,
65 filters: createTree(),
66 render: uuid => <TokenApiToken uuid={uuid} />
69 name: ApiClientAuthorizationPanelColumnNames.CREATED_BY_IP_ADDRESS,
72 filters: createTree(),
73 render: uuid => <TokenCreatedByIpAddress uuid={uuid} />
76 name: ApiClientAuthorizationPanelColumnNames.DEFAULT_OWNER_UUID,
79 filters: createTree(),
80 render: uuid => <TokenDefaultOwnerUuid uuid={uuid} />
83 name: ApiClientAuthorizationPanelColumnNames.EXPIRES_AT,
86 filters: createTree(),
87 render: uuid => <TokenExpiresAt uuid={uuid} />
90 name: ApiClientAuthorizationPanelColumnNames.LAST_USED_AT,
93 filters: createTree(),
94 render: uuid => <TokenLastUsedAt uuid={uuid} />
97 name: ApiClientAuthorizationPanelColumnNames.LAST_USED_BY_IP_ADDRESS,
100 filters: createTree(),
101 render: uuid => <TokenLastUsedByIpAddress uuid={uuid} />
104 name: ApiClientAuthorizationPanelColumnNames.SCOPES,
107 filters: createTree(),
108 render: uuid => <TokenScopes uuid={uuid} />
111 name: ApiClientAuthorizationPanelColumnNames.USER_ID,
114 filters: createTree(),
115 render: uuid => <TokenUserId uuid={uuid} />
119 const DEFAULT_MESSAGE = 'Your api client authorization list is empty.';
121 export interface ApiClientAuthorizationPanelRootActionProps {
122 onItemClick: (item: string) => void;
123 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
124 onItemDoubleClick: (item: string) => void;
127 export interface ApiClientAuthorizationPanelRootDataProps {
128 resources: ResourcesState;
131 type ApiClientAuthorizationPanelRootProps = ApiClientAuthorizationPanelRootActionProps
132 & ApiClientAuthorizationPanelRootDataProps & WithStyles<CssRules>;
134 export const ApiClientAuthorizationPanelRoot = withStyles(styles)(
135 ({ classes, onItemDoubleClick, onItemClick, onContextMenu }: ApiClientAuthorizationPanelRootProps) =>
136 <div className={classes.root}><DataExplorer
137 id={API_CLIENT_AUTHORIZATION_PANEL_ID}
138 onRowClick={onItemClick}
139 onRowDoubleClick={onItemDoubleClick}
140 onContextMenu={onContextMenu}
141 contextMenuColumn={true}
144 defaultViewIcon={ShareMeIcon}
145 defaultViewMessages={[DEFAULT_MESSAGE]} />