diff --git a/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccessPackageAccordion/PolicyAccessPackageAccordion.tsx b/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccessPackageAccordion/PolicyAccessPackageAccordion.tsx index a6e5fb81132..54fac99ece4 100644 --- a/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccessPackageAccordion/PolicyAccessPackageAccordion.tsx +++ b/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccessPackageAccordion/PolicyAccessPackageAccordion.tsx @@ -1,4 +1,4 @@ -import React, { type ReactElement, useState } from 'react'; +import React, { type ReactElement } from 'react'; import { useTranslation } from 'react-i18next'; import classes from './PolicyAccessPackageAccordion.module.css'; import type { AccessPackageResource, PolicyAccessPackage } from '@altinn/policy-editor'; @@ -19,26 +19,6 @@ export const PolicyAccessPackageAccordion = ({ isChecked, handleSelectChange, }: PolicyAccessPackageAccordionProps): React.ReactElement => { - const { t } = useTranslation(); - const [isServicesEnabled, setIsServicesEnabled] = useState(false); - - // Determine enviroment to load resources/apps connected to each access packages from. Option to override this - // value with a localStorage setting is for testing. Valid options are 'at22', 'at23', 'at24', 'tt02' - const accessPackageResourcesEnv = localStorage.getItem('accessPackageResourcesEnv') || 'prod'; - - const { data: services, isLoading } = useResourceAccessPackageServicesQuery( - accessPackage.urn, - accessPackageResourcesEnv, - isServicesEnabled, - ); - - const onOpenAccordion = () => { - setIsServicesEnabled(true); - }; - - const hasServices: boolean = services?.length > 0; - const serviceListIsEmpty: boolean = services?.length === 0; - return (
} - onOpened={onOpenAccordion} > - {isLoading && ( - - )} - {hasServices && } - {serviceListIsEmpty && ( - - {t('policy_editor.access_package_no_services')} - - )} +
); }; +type AccordionContentProps = { accessPackageUrn: string }; +const AccordionContent = ({ accessPackageUrn }: AccordionContentProps): ReactElement => { + const { t } = useTranslation(); + // Determine enviroment to load resources/apps connected to each access packages from. Option to override this + // value with a localStorage setting is for testing. Valid options are 'at22', 'at23', 'at24', 'tt02' + const accessPackageResourcesEnv = localStorage.getItem('accessPackageResourcesEnv') || 'prod'; + + const { data: services, isLoading } = useResourceAccessPackageServicesQuery( + accessPackageUrn, + accessPackageResourcesEnv, + ); + + const hasServices: boolean = services?.length > 0; + const serviceListIsEmpty: boolean = services?.length === 0; + return ( + <> + {isLoading && ( + + )} + {hasServices && } + {serviceListIsEmpty && ( + + {t('policy_editor.access_package_no_services')} + + )} + + ); +}; + type ServicesProps = { services: AccessPackageResource[]; }; diff --git a/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccordion/PolicyAccordion.tsx b/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccordion/PolicyAccordion.tsx index e583e85852a..1d581b08027 100644 --- a/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccordion/PolicyAccordion.tsx +++ b/frontend/packages/policy-editor/src/components/PolicyCardRules/PolicyRule/PolicyAccessPackages/PolicyAccordion/PolicyAccordion.tsx @@ -1,4 +1,4 @@ -import React, { type ReactNode, useEffect, useId, useState } from 'react'; +import React, { type ReactNode, useId, useState } from 'react'; import cn from 'classnames'; import { StudioButton, StudioLabelAsParagraph } from '@studio/components'; import * as StudioIcons from '@studio/icons'; @@ -10,7 +10,6 @@ interface PolicyAccordion { subTitle: string; extraHeaderContent?: ReactNode; defaultOpen?: boolean; - onOpened?: () => void; children: ReactNode; } @@ -20,7 +19,6 @@ export const PolicyAccordion = ({ subTitle, extraHeaderContent, defaultOpen, - onOpened, children, }: PolicyAccordion): ReactNode => { const contentId = useId(); @@ -28,12 +26,6 @@ export const PolicyAccordion = ({ const [isExpanded, setIsExpanded] = useState(initialExpandedState); const IconComponent = StudioIcons[icon]; - useEffect(() => { - if (isExpanded && onOpened) { - onOpened(); - } - }, [isExpanded, onOpened]); - return (
diff --git a/frontend/packages/shared/src/hooks/queries/useResourceAccessPackageServicesQuery.ts b/frontend/packages/shared/src/hooks/queries/useResourceAccessPackageServicesQuery.ts index 5f6ebdc6856..3088201886a 100644 --- a/frontend/packages/shared/src/hooks/queries/useResourceAccessPackageServicesQuery.ts +++ b/frontend/packages/shared/src/hooks/queries/useResourceAccessPackageServicesQuery.ts @@ -16,13 +16,11 @@ import type { AxiosError } from 'axios'; export const useResourceAccessPackageServicesQuery = ( accessPackageUrn: string, env: string, - enabled: boolean, ): UseQueryResult => { const { getAccessPackageServices } = useServicesContext(); return useQuery({ queryKey: [QueryKey.ResourcePolicyAccessPackageServices, accessPackageUrn, env], queryFn: () => getAccessPackageServices(accessPackageUrn, env), - enabled: enabled, }); };