Skip to content

Commit 934a0b2

Browse files
committed
feat: add permissions view for connections
fixes #2246 fix: fix incorrect reference to permissions instead of connection
1 parent cde233b commit 934a0b2

File tree

6 files changed

+104
-21
lines changed

6 files changed

+104
-21
lines changed

src/api/services/permissions.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type FetchPermissionsInput = {
1111
checkId?: string;
1212
canaryId?: string;
1313
playbookId?: string;
14+
connectionId?: string;
1415
};
1516

1617
function composeQueryParamForFetchPermissions({
@@ -20,7 +21,8 @@ function composeQueryParamForFetchPermissions({
2021
configId,
2122
checkId,
2223
canaryId,
23-
playbookId
24+
playbookId,
25+
connectionId
2426
}: FetchPermissionsInput) {
2527
if (componentId) {
2628
return `component_id=eq.${componentId}`;
@@ -43,6 +45,9 @@ function composeQueryParamForFetchPermissions({
4345
if (playbookId) {
4446
return `playbook_id=eq.${playbookId}`;
4547
}
48+
if (connectionId) {
49+
return `connection_id=eq.${connectionId}`;
50+
}
4651
return undefined;
4752
}
4853

@@ -56,14 +61,15 @@ export function fetchPermissions(
5661
const queryParam = composeQueryParamForFetchPermissions(input);
5762
const selectFields = [
5863
"*",
59-
"checks:check_id(id, name, status, type)",
64+
// "checks:check_id(id, name, status, type)",
6065
"catalog:config_id(id, name, type, config_class)",
6166
"component:component_id(id, name, icon)",
62-
"canary:canary_id(id, name, icon)",
67+
"canary:canary_id(id, name)",
6368
"playbook:playbook_id(id, title, name, icon)",
6469
"team:team_id(id, name, icon)",
6570
`person:person_id(${AVATAR_INFO})`,
66-
`createdBy:created_by(${AVATAR_INFO})`
71+
`createdBy:created_by(${AVATAR_INFO})`,
72+
`connection:connection_id(id,name,type)`
6773
];
6874

6975
const { pageSize, pageIndex } = pagination;

src/api/types/permissions.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { Connection } from "@flanksource-ui/components/Connections/ConnectionFormModal";
12
import { ConfigItem } from "./configs";
2-
import { HealthCheck } from "./health";
33
import { PlaybookSpec } from "./playbooks";
44
import { Topology } from "./topology";
55
import { Team, User } from "./users";
@@ -23,12 +23,16 @@ export type PermissionTable = {
2323
};
2424

2525
export type PermissionAPIResponse = PermissionTable & {
26-
checks: Pick<HealthCheck, "id" | "name" | "type" | "status">;
26+
// checks: Pick<HealthCheck, "id" | "name" | "type" | "status">;
2727
catalog: Pick<ConfigItem, "id" | "name" | "type" | "config_class">;
2828
component: Pick<Topology, "id" | "name" | "icon">;
29-
canary: Pick<Topology, "id" | "name" | "icon">;
29+
canary: {
30+
id: string;
31+
name: string;
32+
};
3033
playbook: Pick<PlaybookSpec, "id" | "name" | "icon" | "title">;
3134
team: Pick<Team, "id" | "name" | "icon">;
35+
connection: Pick<Connection, "id" | "name" | "type">;
3236
person: User;
3337
createdBy: User;
3438
};

src/components/Connections/ConnectionFormModal.tsx

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { Tab, Tabs } from "@flanksource-ui/ui/Tabs/Tabs";
12
import React, { useEffect, useState } from "react";
23
import { Icon } from "../../ui/Icons/Icon";
34
import { Modal } from "../../ui/Modal";
5+
import PermissionsView from "../Permissions/PermissionsView";
46
import ConnectionForm from "./ConnectionForm";
57
import ConnectionListView from "./ConnectionListView";
68
import ConnectionSpecEditor from "./ConnectionSpecEditor";
@@ -81,6 +83,8 @@ export default function ConnectionFormModal({
8183
ConnectionType | undefined
8284
>(() => connectionTypes.find((item) => item.title === formValue?.type));
8385

86+
const [activeTab, setActiveTab] = useState<"form" | "permissions">("form");
87+
8488
useEffect(() => {
8589
let connection = connectionTypes.find(
8690
(item) => item.value === formValue?.type
@@ -122,16 +126,53 @@ export default function ConnectionFormModal({
122126
helpLink="reference/connections/"
123127
>
124128
{type ? (
125-
<ConnectionForm
126-
handleBack={() => setConnectionType(undefined)}
127-
connectionType={type}
128-
onConnectionSubmit={onConnectionSubmit}
129-
onConnectionDelete={onConnectionDelete}
130-
formValue={formValue}
131-
className={className}
132-
isSubmitting={isSubmitting}
133-
isDeleting={isDeleting}
134-
/>
129+
formValue?.id ? (
130+
<Tabs
131+
activeTab={activeTab}
132+
onSelectTab={(label) => setActiveTab(label)}
133+
className="flex-1"
134+
>
135+
<Tab
136+
label="Edit Connection"
137+
value={"form"}
138+
className="flex flex-col"
139+
>
140+
<ConnectionForm
141+
handleBack={() => setConnectionType(undefined)}
142+
connectionType={type}
143+
onConnectionSubmit={onConnectionSubmit}
144+
onConnectionDelete={onConnectionDelete}
145+
formValue={formValue}
146+
className={className}
147+
isSubmitting={isSubmitting}
148+
isDeleting={isDeleting}
149+
/>
150+
</Tab>
151+
152+
<Tab
153+
label="Permissions"
154+
value={"connections"}
155+
className="flex flex-col"
156+
>
157+
<PermissionsView
158+
permissionRequest={{
159+
connectionId: formValue.id
160+
}}
161+
/>
162+
</Tab>
163+
</Tabs>
164+
) : (
165+
<ConnectionForm
166+
handleBack={() => setConnectionType(undefined)}
167+
connectionType={type}
168+
onConnectionSubmit={onConnectionSubmit}
169+
onConnectionDelete={onConnectionDelete}
170+
formValue={formValue}
171+
className={className}
172+
isSubmitting={isSubmitting}
173+
isDeleting={isDeleting}
174+
/>
175+
)
135176
) : formValue?.id ? (
136177
<ConnectionSpecEditor
137178
handleBack={() => setConnectionType(undefined)}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Icon } from "@flanksource-ui/ui/Icons/Icon";
2+
import { useMemo } from "react";
3+
import { Connection } from "./ConnectionFormModal";
4+
import { connectionTypes } from "./connectionTypes";
5+
6+
type ConnectionIconProps = {
7+
connection: Pick<Connection, "type" | "name" | "id">;
8+
showLabel?: boolean;
9+
};
10+
export default function ConnectionIcon({
11+
connection,
12+
showLabel = false
13+
}: ConnectionIconProps) {
14+
const icon = useMemo(() => {
15+
return connectionTypes.find((item) => item.value === connection.type)?.icon;
16+
}, [connection.type]);
17+
18+
return (
19+
<div className="flex flex-row items-center gap-1">
20+
{typeof icon === "string" ? (
21+
<Icon name={icon} className="h-5" />
22+
) : (
23+
// if not a string, it's a react component
24+
// eslint-disable-next-line react/jsx-no-useless-fragment
25+
icon && <>{icon}</>
26+
)}
27+
{showLabel && <span>{connection.name}</span>}
28+
</div>
29+
);
30+
}

src/components/Connections/connectionTypes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const enum ConnectionValueType {
9696
export type ConnectionType = {
9797
title: string;
9898
value: ConnectionValueType;
99-
icon?: React.ReactNode | string | null;
99+
icon?: JSX.Element | string | null;
100100
fields: ConnectionFormFields[];
101101
convertToFormSpecificValue?: (data: Record<string, string>) => Connection;
102102
preSubmitConverter?: (data: Record<string, string>) => object;

src/components/Permissions/PermissionsTable.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { MRTDateCell } from "@flanksource-ui/ui/MRTDataTable/Cells/MRTDateCells"
55
import MRTDataTable from "@flanksource-ui/ui/MRTDataTable/MRTDataTable";
66
import { MRT_ColumnDef } from "mantine-react-table";
77
import CanaryLink from "../Canary/CanaryLink";
8-
import { CheckLink } from "../Canary/HealthChecks/CheckLink";
98
import ConfigLink from "../Configs/ConfigLink/ConfigLink";
9+
import ConnectionIcon from "../Connections/ConnectionIcon";
1010
import PlaybookSpecIcon from "../Playbooks/Settings/PlaybookSpecIcon";
1111
import { TopologyLink } from "../Topology/TopologyLink";
1212

@@ -17,18 +17,20 @@ const permissionsTableColumns: MRT_ColumnDef<PermissionAPIResponse>[] = [
1717
size: 250,
1818
Cell: ({ row }) => {
1919
const config = row.original.catalog;
20-
const check = row.original.checks;
20+
// const check = row.original.checks;
2121
const playbook = row.original.playbook;
2222
const canary = row.original.canary;
2323
const component = row.original.component;
24+
const connection = row.original.connection;
2425

2526
return (
2627
<div className="flex flex-col">
2728
{config && <ConfigLink config={config} />}
28-
{check && <CheckLink check={check} />}
29+
{/* {check && <CheckLink check={check} />} */}
2930
{playbook && <PlaybookSpecIcon playbook={playbook} showLabel />}
3031
{canary && <CanaryLink canary={canary} />}
3132
{component && <TopologyLink topology={component} />}
33+
{connection && <ConnectionIcon connection={connection} showLabel />}
3234
</div>
3335
);
3436
}

0 commit comments

Comments
 (0)