Skip to content

Commit 486deaf

Browse files
Roman SnapkoCopilot
andauthored
Fix Templates Banner on home page (#2103)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Fixes OPS-3843 The banner is not visible in the templates dialog so I copied the check from there https://github.com/openops-cloud/openops/blob/9b4caf09455206483e7084229db2a2601418a79b/packages/react-ui/src/app/features/templates/components/select-flow-template-dialog-content.tsx#L99-L106 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0368565 commit 486deaf

4 files changed

Lines changed: 34 additions & 16 deletions

File tree

packages/react-ui/src/app/features/home/components/home-onboarding-view.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Permission } from '@openops/shared';
2323
import { t } from 'i18next';
2424
import { useEffect, useState } from 'react';
2525
import { useNavigate } from 'react-router-dom';
26+
import { useShowTemplatesBanner } from '../../templates/hooks/use-show-templates-banner';
2627
import { useOpenBenchmarkWizard } from './use-open-benchmark-wizard';
2728
import { useBenchmarkBannerState } from './useBenchmarkBannerState';
2829

@@ -56,11 +57,12 @@ const HomeOnboardingView = ({
5657
});
5758
const { updateUserSettings } = userSettingsHooks.useUpdateUserSettings();
5859

59-
const { cloudUser, isHomeCloudConnectionClosed } = useAppStore((state) => ({
60-
cloudUser: state.cloudUser,
60+
const { isHomeCloudConnectionClosed } = useAppStore((state) => ({
6161
isHomeCloudConnectionClosed: state.userSettings.isHomeCloudConnectionClosed,
6262
}));
6363

64+
const { isCloudUser } = useShowTemplatesBanner();
65+
6466
const { checkAccess } = useAuthorization();
6567
const hasWriteFlowPermission = checkAccess(Permission.WRITE_FLOW);
6668

@@ -72,7 +74,7 @@ const HomeOnboardingView = ({
7274
setTimeout(() => {
7375
refetch({ cancelRefetch: true });
7476
}, 1000);
75-
}, [cloudUser, refetch, setSelectedDomains]);
77+
}, [isCloudUser, refetch, setSelectedDomains]);
7678

7779
const onExploreMoreClick = () => {
7880
const currentUser = authenticationSession.getCurrentUser();
@@ -123,11 +125,11 @@ const HomeOnboardingView = ({
123125
onSeeAllClick={onExploreTemplatesClick}
124126
onFilterClick={onTemplatesFilterClick}
125127
templates={templatesWithIntegrations}
126-
showFilters={!!cloudUser}
128+
showFilters={isCloudUser}
127129
filters={domains}
128130
onTemplateClick={onTemplateClick}
129131
/>
130-
{!cloudUser && !isHomeCloudConnectionClosed && (
132+
{!isCloudUser && !isHomeCloudConnectionClosed && (
131133
<DismissiblePanel
132134
className="h-fit"
133135
buttonClassName="z-50 size-6"
@@ -140,7 +142,7 @@ const HomeOnboardingView = ({
140142
/>
141143
</DismissiblePanel>
142144
)}
143-
{(isHelpViewClosed || cloudUser || isHomeCloudConnectionClosed) && (
145+
{(isHelpViewClosed || isCloudUser || isHomeCloudConnectionClosed) && (
144146
<div className="flex-1 border rounded-sm overflow-hidden min-h-[120px]">
145147
<NoWorkflowsPlaceholder
146148
onExploreTemplatesClick={onExploreTemplatesClick}

packages/react-ui/src/app/features/templates/components/select-flow-template-dialog-content.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useAuthorization } from '@/app/common/hooks/authorization-hooks';
2-
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
32
import { useTheme } from '@/app/common/providers/theme-provider';
43
import { OPENOPS_CONNECT_TEMPLATES_URL } from '@/app/constants/cloud';
54
import { ExpandedTemplate } from '@/app/features/templates/components/expanded-template';
@@ -19,8 +18,8 @@ import {
1918
} from '@openops/components/ui';
2019
import { FlowTemplateDto, Permission } from '@openops/shared';
2120
import { popupFeatures } from '../../cloud/lib/popup';
22-
import { useCloudProfile } from '../../cloud/lib/use-cloud-profile';
2321
import { useUserInfoPolling } from '../../cloud/lib/use-user-info-polling';
22+
import { useShowTemplatesBanner } from '../hooks/use-show-templates-banner';
2423
import {
2524
FlowTemplateFilterSidebarProps,
2625
PublicFlowTemplateFilterSidebarWrapper,
@@ -96,14 +95,11 @@ const SelectFlowTemplateDialogContent = ({
9695
}: SelectFlowTemplateDialogContentProps) => {
9796
const { theme } = useTheme();
9897
const ownerLogoUrl = useOwnerLogoUrl();
99-
const { isConnectedToCloudTemplates } = useCloudProfile();
10098
const { createPollingInterval } = useUserInfoPolling();
101-
const useCloudTemplates = flagsHooks.useShouldFetchCloudTemplates();
99+
const { isCloudUser } = useShowTemplatesBanner();
102100
const { checkAccess } = useAuthorization();
103101
const hasWriteFlowPermission = checkAccess(Permission.WRITE_FLOW);
104-
const isFullCatalog =
105-
!isTemplatePreselected &&
106-
(isConnectedToCloudTemplates || !useCloudTemplates);
102+
const isFullCatalog = !isTemplatePreselected && isCloudUser;
107103

108104
const onExploreMoreClick = () => {
109105
const currentUser = authenticationSession.getCurrentUser();

packages/react-ui/src/app/features/templates/components/select-flow-template-dialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { useMutation } from '@tanstack/react-query';
2323
import React, { useEffect, useState } from 'react';
2424
import { useNavigate } from 'react-router-dom';
2525
import { useDebounceValue } from 'usehooks-ts';
26-
import { useCloudProfile } from '../../cloud/lib/use-cloud-profile';
26+
import { useShowTemplatesBanner } from '../hooks/use-show-templates-banner';
2727
import { cloudTemplatesApi } from '../lib/cloud-templates-api';
2828
import { SelectFlowTemplateDialogContent } from './select-flow-template-dialog-content';
2929

@@ -93,7 +93,7 @@ const SelectFlowTemplateDialog = ({
9393
TEMPLATE_FILTER_DEBOUNCE_DELAY,
9494
);
9595

96-
const { isConnectedToCloudTemplates } = useCloudProfile();
96+
const { isCloudUser } = useShowTemplatesBanner();
9797

9898
const { templatesWithIntegrations, isLoading: isTemplateListLoading } =
9999
templatesHooks.useTemplatesMetadataWithIntegrations({
@@ -105,7 +105,7 @@ const SelectFlowTemplateDialog = ({
105105
categories: selectedCategories,
106106
useCloudTemplates,
107107
gettingStartedTemplateFilter: 'exclude',
108-
isConnectedToCloudTemplates,
108+
isConnectedToCloudTemplates: isCloudUser,
109109
});
110110

111111
const {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
2+
import { useMemo } from 'react';
3+
import { useCloudProfile } from '../../cloud/lib/use-cloud-profile';
4+
5+
/**
6+
* Custom hook to determine if the templates banner should be shown.
7+
* It checks if the user is connected to cloud templates and if the cloud templates flag is enabled.
8+
*
9+
* @returns {boolean} isCloudUser - True if the user is connected to cloud templates and cloud templates are enabled.
10+
*/
11+
export const useShowTemplatesBanner = () => {
12+
const { isConnectedToCloudTemplates } = useCloudProfile();
13+
const useCloudTemplates = flagsHooks.useShouldFetchCloudTemplates();
14+
15+
const isCloudUser = useMemo(() => {
16+
return isConnectedToCloudTemplates && !!useCloudTemplates;
17+
}, [isConnectedToCloudTemplates, useCloudTemplates]);
18+
19+
return { isCloudUser };
20+
};

0 commit comments

Comments
 (0)