Skip to content

Commit a3c4833

Browse files
adityathebemoshloop
authored andcommitted
fix permission review comments for resource rendering and confirm loading
1 parent f345da1 commit a3c4833

3 files changed

Lines changed: 87 additions & 60 deletions

File tree

src/api/services/permissions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ function composeQueryParamForFetchPermissions({
5454
if (canaryId) {
5555
filters.push(`canary_id=eq.${canaryId}`);
5656
}
57-
if (playbookId && !subject) {
58-
filters.push(`subject=eq.${playbookId}`);
59-
filters.push(`subject_type=eq.playbook`);
57+
if (playbookId) {
58+
filters.push(`playbook_id=eq.${playbookId}`);
6059
}
6160
if (connectionId) {
6261
filters.push(`connection_id=eq.${connectionId}`);

src/components/Permissions/PermissionResourceCell.tsx

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { PermissionsSummary } from "@flanksource-ui/api/types/permissions";
1+
import {
2+
PermissionGlobalObject,
3+
PermissionsSummary
4+
} from "@flanksource-ui/api/types/permissions";
25
import CanaryLink from "../Canary/CanaryLink";
36
import ConfigLink from "../Configs/ConfigLink/ConfigLink";
47
import ConnectionIcon from "../Connections/ConnectionIcon";
58
import ConnectionLink from "../Connections/ConnectionLink";
69
import PlaybookSpecIcon from "../Playbooks/Settings/PlaybookSpecIcon";
710
import { TopologyLink } from "../Topology/TopologyLink";
8-
import { permissionObjectList } from "./ManagePermissions/Forms/FormikPermissionSelectResourceFields";
911
import { PermissionErrorDisplay } from "./PermissionErrorDisplay";
1012

1113
interface ScopeObject {
@@ -87,6 +89,16 @@ type PermissionResourceCellProps = {
8789
permission: PermissionsSummary;
8890
};
8991

92+
const OBJECT_LABELS: Record<PermissionGlobalObject, string> = {
93+
catalog: "Catalog",
94+
component: "Component",
95+
canaries: "Canaries",
96+
connection: "Connection",
97+
playbook: "Playbook",
98+
topology: "Topology",
99+
mcp: "MCP"
100+
};
101+
90102
export default function PermissionResourceCell({
91103
permission
92104
}: PermissionResourceCellProps) {
@@ -98,6 +110,9 @@ export default function PermissionResourceCell({
98110
const object = permission.object;
99111
const objectSelector = permission.object_selector;
100112
const error = permission.error;
113+
const hasConcreteObject = Boolean(
114+
config || playbook || component || canary || connection
115+
);
101116

102117
if (objectSelector) {
103118
// Format scopes as "Scope: namespace/name, namespace2/name2"
@@ -187,13 +202,69 @@ export default function PermissionResourceCell({
187202
);
188203
}
189204

205+
if (hasConcreteObject) {
206+
return (
207+
<div className="flex flex-row items-center gap-3">
208+
<div className="flex flex-row items-center gap-2">
209+
<div className="flex flex-col">
210+
{config && (
211+
<div className="flex items-center gap-1">
212+
<span className="text-sm text-gray-600">Catalog:</span>
213+
<ConfigLink config={config} />
214+
</div>
215+
)}
216+
217+
{playbook && (
218+
<div className="flex items-center gap-1">
219+
<span className="text-sm text-gray-600">Playbook:</span>
220+
<PlaybookSpecIcon
221+
playbook={{
222+
...playbook,
223+
title: playbook.name,
224+
spec: { icon: playbook.icon || "", actions: [] }
225+
}}
226+
showLabel
227+
/>
228+
</div>
229+
)}
230+
231+
{component && (
232+
<div className="flex items-center gap-1">
233+
<span className="text-sm text-gray-600">Component:</span>
234+
<TopologyLink
235+
topology={component}
236+
className="h-5 w-5 text-gray-600"
237+
linkClassName="text-gray-600"
238+
size="md"
239+
/>
240+
</div>
241+
)}
242+
243+
{canary && (
244+
<div className="flex items-center gap-1">
245+
<span className="text-sm text-gray-600">Canary:</span>
246+
<CanaryLink canary={canary} />
247+
</div>
248+
)}
249+
250+
{connection && (
251+
<div className="flex items-center gap-1">
252+
<span className="text-sm text-gray-600">Connection:</span>
253+
<ConnectionIcon connection={connection} showLabel />
254+
</div>
255+
)}
256+
</div>
257+
</div>
258+
<PermissionErrorDisplay error={error} />
259+
</div>
260+
);
261+
}
262+
190263
if (object) {
191264
return (
192265
<div className="flex flex-row items-center gap-3">
193266
<div className="flex flex-row items-center gap-2">
194-
<span>
195-
{permissionObjectList.find((o) => o.value === object)?.label}
196-
</span>
267+
<span>{OBJECT_LABELS[object] ?? object}</span>
197268
</div>
198269
<PermissionErrorDisplay error={error} />
199270
</div>
@@ -202,56 +273,6 @@ export default function PermissionResourceCell({
202273

203274
return (
204275
<div className="flex flex-row items-center gap-3">
205-
<div className="flex flex-row items-center gap-2">
206-
<div className="flex flex-col">
207-
{config && (
208-
<div className="flex items-center gap-1">
209-
<span className="text-sm text-gray-600">Catalog:</span>
210-
<ConfigLink config={config} />
211-
</div>
212-
)}
213-
214-
{playbook && (
215-
<div className="flex items-center gap-1">
216-
<span className="text-sm text-gray-600">Playbook:</span>
217-
<PlaybookSpecIcon
218-
playbook={{
219-
...playbook,
220-
title: playbook.name,
221-
spec: { icon: playbook.icon || "", actions: [] }
222-
}}
223-
showLabel
224-
/>
225-
</div>
226-
)}
227-
228-
{component && (
229-
<div className="flex items-center gap-1">
230-
<span className="text-sm text-gray-600">Component:</span>
231-
<TopologyLink
232-
topology={component}
233-
className="h-5 w-5 text-gray-600"
234-
linkClassName="text-gray-600"
235-
size="md"
236-
/>
237-
</div>
238-
)}
239-
240-
{canary && (
241-
<div className="flex items-center gap-1">
242-
<span className="text-sm text-gray-600">Canary:</span>
243-
<CanaryLink canary={canary} />
244-
</div>
245-
)}
246-
247-
{connection && (
248-
<div className="flex items-center gap-1">
249-
<span className="text-sm text-gray-600">Connection:</span>
250-
<ConnectionIcon connection={connection} showLabel />
251-
</div>
252-
)}
253-
</div>
254-
</div>
255276
<PermissionErrorDisplay error={error} />
256277
</div>
257278
);

src/ui/AlertDialog/ConfirmationPromptDialog.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,21 @@ export function ConfirmationPromptDialog({
109109
</DialogHeader>
110110

111111
<DialogFooter className="gap-2 sm:justify-end">
112-
<button className="btn btn-white" onClick={onClose}>
112+
<button type="button" className="btn btn-white" onClick={onClose}>
113113
{closeLabel}
114114
</button>
115115
<button
116+
type="button"
116117
className={clsx(
117118
confirmationStyle === "delete" ? "btn-danger" : "btn-primary"
118119
)}
119-
onClick={onConfirm}
120+
onClick={() => {
121+
if (!isLoading) {
122+
onConfirm();
123+
}
124+
}}
125+
disabled={isLoading}
126+
aria-busy={isLoading}
120127
data-testid={`confirm-button-${yesLabel}`}
121128
>
122129
{isLoading && (

0 commit comments

Comments
 (0)