Skip to content

Commit dd783e6

Browse files
Add permision check for benchmark panel
1 parent 016c7e9 commit dd783e6

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

packages/react-ui/src/app/features/navigation/layout/secondary-left-side-panel-container.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { cn, ResizableHandle, ResizablePanel } from '@openops/components/ui';
2+
import { Permission } from '@openops/shared';
23
import { t } from 'i18next';
34
import { useCallback, useEffect, useMemo, useRef } from 'react';
45
import { ImperativePanelHandle } from 'react-resizable-panels';
56

7+
import { useAuthorization } from '@/app/common/hooks/authorization-hooks';
68
import { useResizablePanelGroup } from '@/app/common/hooks/use-resizable-panel-group';
79
import { RESIZABLE_PANEL_IDS } from '@/app/constants/layout';
810
import AssistantUiChat from '@/app/features/ai/assistant/assistant-ui-chat';
@@ -32,6 +34,11 @@ const SecondaryLeftSidePanelContainer = ({
3234
setIsSidebarMinimized: s.setIsSidebarMinimized,
3335
}));
3436

37+
const { checkAccess } = useAuthorization();
38+
const hasBenchmarkAccess =
39+
checkAccess(Permission.WRITE_FLOW) &&
40+
checkAccess(Permission.READ_APP_CONNECTION);
41+
3542
const { hasActiveAiSettings, isLoading } =
3643
aiSettingsHooks.useHasActiveAiSettings();
3744

@@ -43,22 +50,23 @@ const SecondaryLeftSidePanelContainer = ({
4350
}, [hasActiveAiSettings, isAiChatOpened, isLoading]);
4451

4552
const prevVisibilityRef = useRef({
46-
shouldShowBenchmark: isBenchmarkWizardOpen,
53+
shouldShowBenchmark: hasBenchmarkAccess && isBenchmarkWizardOpen,
4754
shouldShowAiChat,
4855
});
4956

50-
const shouldShowPanelContent = isBenchmarkWizardOpen || shouldShowAiChat;
57+
const shouldShowBenchmark = hasBenchmarkAccess && isBenchmarkWizardOpen;
58+
const shouldShowPanelContent = shouldShowBenchmark || shouldShowAiChat;
5159

5260
const getDefaultPanelSize = useCallback(() => {
5361
if (!shouldShowPanelContent) return 0;
5462
return getPanelSize(RESIZABLE_PANEL_IDS.SECONDARY_LEFT_SIDEBAR) ?? 20;
5563
}, [getPanelSize, shouldShowPanelContent]);
5664

5765
useEffect(() => {
58-
if (isBenchmarkWizardOpen) {
66+
if (shouldShowBenchmark) {
5967
setIsSidebarMinimized(true);
6068
}
61-
}, [isBenchmarkWizardOpen, setIsSidebarMinimized]);
69+
}, [shouldShowBenchmark, setIsSidebarMinimized]);
6270

6371
useEffect(() => {
6472
if (!resizablePanelRef.current) {
@@ -67,7 +75,7 @@ const SecondaryLeftSidePanelContainer = ({
6775

6876
const shouldUpdatePanel = shouldUpdatePanelVisibility(
6977
prevVisibilityRef.current,
70-
isBenchmarkWizardOpen,
78+
shouldShowBenchmark,
7179
shouldShowAiChat,
7280
);
7381

@@ -82,20 +90,20 @@ const SecondaryLeftSidePanelContainer = ({
8290
}
8391

8492
prevVisibilityRef.current = {
85-
shouldShowBenchmark: isBenchmarkWizardOpen,
93+
shouldShowBenchmark,
8694
shouldShowAiChat,
8795
};
8896
}, [
8997
shouldShowPanelContent,
9098
getPanelSize,
91-
isBenchmarkWizardOpen,
99+
shouldShowBenchmark,
92100
shouldShowAiChat,
93101
]);
94102

95103
const size = getSize(
96104
hasActiveAiSettings,
97105
isAiChatOpened,
98-
isBenchmarkWizardOpen,
106+
shouldShowBenchmark,
99107
);
100108

101109
return (
@@ -113,7 +121,7 @@ const SecondaryLeftSidePanelContainer = ({
113121
collapsedSize={0}
114122
defaultSize={getDefaultPanelSize()}
115123
>
116-
{isBenchmarkWizardOpen && (
124+
{shouldShowBenchmark && (
117125
<div className="w-full h-full dark:bg-background">
118126
<BenchmarkWizard onClose={() => setIsBenchmarkWizardOpen(false)} />
119127
</div>

0 commit comments

Comments
 (0)