Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/user-settings/AuthEntryItem.tsx
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { useState } from "react";
8
import { ContextMenuEntry } from "../components/ContextMenu";
9
import { Item, ItemFieldIcon, ItemField, ItemFieldContextMenu } from "../components/ItemsList";
10
import { AuthProviderDescription } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
11
import { toAuthProviderLabel } from "../provider-utils";
12
import { getScopeNameForScope } from "@gitpod/public-api-common/lib/auth-providers";
13
14
interface AuthEntryItemParams {
15
ap: AuthProviderDescription;
16
isConnected: (authProviderId: string) => boolean;
17
getUsername: (authProviderId: string) => string | undefined;
18
getPermissions: (authProviderId: string) => string[] | undefined;
19
gitProviderMenu: (provider: AuthProviderDescription) => ContextMenuEntry[];
20
}
21
22
export const AuthEntryItem = (props: AuthEntryItemParams) => {
23
const [menuVisible, setMenuVisible] = useState<boolean>(false);
24
25
const changeMenuState = (state: boolean) => {
26
setMenuVisible(state);
27
};
28
29
return (
30
<Item key={"ap-" + props.ap.id} className="h-16" solid={menuVisible}>
31
<ItemFieldIcon>
32
<div
33
className={
34
"rounded-full w-3 h-3 text-sm align-middle m-auto " +
35
(props.isConnected(props.ap.id) ? "bg-green-500" : "bg-gray-400")
36
}
37
>
38
&nbsp;
39
</div>
40
</ItemFieldIcon>
41
<ItemField className="w-4/12 xl:w-3/12 flex flex-col my-auto">
42
<span className="my-auto font-medium truncate overflow-ellipsis">
43
{toAuthProviderLabel(props.ap.type)}
44
</span>
45
<span className="text-sm my-auto text-gray-400 truncate overflow-ellipsis dark:text-gray-500">
46
{props.ap.host}
47
</span>
48
</ItemField>
49
<ItemField className="w-6/12 xl:w-3/12 flex flex-col my-auto">
50
<span className="my-auto truncate text-gray-500 overflow-ellipsis dark:text-gray-400">
51
{props.getUsername(props.ap.id) || "–"}
52
</span>
53
<span className="text-sm my-auto text-gray-400 dark:text-gray-500">Username</span>
54
</ItemField>
55
<ItemField className="hidden xl:w-1/3 xl:flex xl:flex-col my-auto">
56
<span className="my-auto truncate text-gray-500 overflow-ellipsis dark:text-gray-400">
57
{props.getPermissions(props.ap.id)?.map(getScopeNameForScope)?.join(", ") || "–"}
58
</span>
59
<span className="text-sm my-auto text-gray-400 dark:text-gray-500">Permissions</span>
60
</ItemField>
61
<ItemFieldContextMenu changeMenuState={changeMenuState} menuEntries={props.gitProviderMenu(props.ap)} />
62
</Item>
63
);
64
};
65
66