Merge branch 'main' into 21842-improve-sharing
[arvados.git] / services / workbench2 / src / views / api-client-authorization-panel / api-client-authorization-panel-root.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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';
17 import {
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';
22
23 type CssRules = 'root';
24
25 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26     root: {
27         width: '100%',
28     }
29 });
30
31
32 export enum ApiClientAuthorizationPanelColumnNames {
33     UUID = 'UUID',
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',
39     SCOPES = 'Scopes',
40     USER_ID = 'User ID'
41 }
42
43 export const apiClientAuthorizationPanelColumns: DataColumns<string, ApiClientAuthorization> = [
44     {
45         name: ApiClientAuthorizationPanelColumnNames.UUID,
46         selected: true,
47         configurable: true,
48         sort: {direction: SortDirection.NONE, field: "uuid"},
49         filters: createTree(),
50         render: uuid => <CommonUuid uuid={uuid} />
51     },
52     {
53         name: ApiClientAuthorizationPanelColumnNames.API_TOKEN,
54         selected: true,
55         configurable: true,
56         filters: createTree(),
57         render: uuid => <TokenApiToken uuid={uuid} />
58     },
59     {
60         name: ApiClientAuthorizationPanelColumnNames.CREATED_BY_IP_ADDRESS,
61         selected: true,
62         configurable: true,
63         filters: createTree(),
64         render: uuid => <TokenCreatedByIpAddress uuid={uuid} />
65     },
66     {
67         name: ApiClientAuthorizationPanelColumnNames.EXPIRES_AT,
68         selected: true,
69         configurable: true,
70         filters: createTree(),
71         render: uuid => <TokenExpiresAt uuid={uuid} />
72     },
73     {
74         name: ApiClientAuthorizationPanelColumnNames.LAST_USED_AT,
75         selected: true,
76         configurable: true,
77         filters: createTree(),
78         render: uuid => <TokenLastUsedAt uuid={uuid} />
79     },
80     {
81         name: ApiClientAuthorizationPanelColumnNames.LAST_USED_BY_IP_ADDRESS,
82         selected: true,
83         configurable: true,
84         filters: createTree(),
85         render: uuid => <TokenLastUsedByIpAddress uuid={uuid} />
86     },
87     {
88         name: ApiClientAuthorizationPanelColumnNames.SCOPES,
89         selected: true,
90         configurable: true,
91         filters: createTree(),
92         render: uuid => <TokenScopes uuid={uuid} />
93     },
94     {
95         name: ApiClientAuthorizationPanelColumnNames.USER_ID,
96         selected: true,
97         configurable: true,
98         filters: createTree(),
99         render: uuid => <TokenUserId uuid={uuid} />
100     }
101 ];
102
103 const DEFAULT_MESSAGE = 'Your api client authorization list is empty.';
104
105 export interface ApiClientAuthorizationPanelRootActionProps {
106     onItemClick: (item: string) => void;
107     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
108     onItemDoubleClick: (item: string) => void;
109 }
110
111 export interface ApiClientAuthorizationPanelRootDataProps {
112     resources: ResourcesState;
113 }
114
115 type ApiClientAuthorizationPanelRootProps = ApiClientAuthorizationPanelRootActionProps
116     & ApiClientAuthorizationPanelRootDataProps & WithStyles<CssRules>;
117
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}
126             hideColumnSelector
127             hideSearchInput
128             defaultViewIcon={ShareMeIcon}
129             defaultViewMessages={[DEFAULT_MESSAGE]} />
130         </div>
131 );