Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide edit button for delegated eservices #1024

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ import { useTranslation } from 'react-i18next'
import EditIcon from '@mui/icons-material/Edit'
import type { AttributeKey } from '@/types/attribute.types'
import { ProviderEServiceUpdateDescriptorAttributesDrawer } from './ProviderEServiceUpdateDescriptorAttributesDrawer'
import { AuthHooks } from '@/api/auth'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

export const ProviderEServiceDescriptorAttributes: React.FC = () => {
const { t } = useTranslation('eservice', { keyPrefix: 'read.sections.attributes' })
const { t: tCommon } = useTranslation('common')
const { jwt } = AuthHooks.useJwt()

const { eserviceId, descriptorId } = useParams<'PROVIDE_ESERVICE_MANAGE'>()
const { data: descriptorAttributes } = useSuspenseQuery({
...EServiceQueries.getDescriptorProvider(eserviceId, descriptorId),
select: (d) => d.attributes,
})

const { isDelegator } = useGetDelegationUserRole({
eserviceId,
organizationId: jwt?.organizationId,
})

const [editAttributeDrawerState, setEditAttributeDrawerState] = useState<{
kind: AttributeKey
isOpen: boolean
}>({ isOpen: false, kind: 'certified' })

const getAttributeSectionActions = (kind: AttributeKey): Array<ActionItemButton> | undefined => {
if (descriptorAttributes[kind].length === 0) return
if (descriptorAttributes[kind].length === 0 || isDelegator) return

return [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,26 @@ import { EServiceVersionSelectorDrawer } from '@/components/shared/EServiceVersi
import EditIcon from '@mui/icons-material/Edit'
import { ProviderEServiceUpdateDescriptionDrawer } from './ProviderEServiceUpdateDescriptionDrawer'
import { useSuspenseQuery } from '@tanstack/react-query'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'
import { AuthHooks } from '@/api/auth'

export const ProviderEServiceGeneralInfoSection: React.FC = () => {
const { t } = useTranslation('eservice', {
keyPrefix: 'read.sections.generalInformations',
})
const { t: tCommon } = useTranslation('common')
const { jwt } = AuthHooks.useJwt()

const { eserviceId, descriptorId } = useParams<'PROVIDE_ESERVICE_MANAGE'>()
const { data: descriptor } = useSuspenseQuery(
EServiceQueries.getDescriptorProvider(eserviceId, descriptorId)
)

const { isDelegator } = useGetDelegationUserRole({
eserviceId,
organizationId: jwt?.organizationId,
})

const downloadConsumerList = EServiceDownloads.useDownloadConsumerList()
const exportVersion = EServiceDownloads.useExportVersion()

Expand Down Expand Up @@ -94,13 +102,17 @@ export const ProviderEServiceGeneralInfoSection: React.FC = () => {
innerSection
title={t('eserviceDescription.label')}
titleTypographyProps={{ variant: 'body1', fontWeight: 600 }}
topSideActions={[
{
action: openEServiceUpdateDescriptionDrawer,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]}
topSideActions={
isDelegator
? []
: [
{
action: openEServiceUpdateDescriptionDrawer,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]
}
>
<Typography variant="body2">{descriptor.eservice.description}</Typography>
</SectionContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import AttachFileIcon from '@mui/icons-material/AttachFile'
import { EServiceDownloads } from '@/api/eservice'
import { getDownloadDocumentName } from '@/utils/eservice.utils'
import { ProviderEServiceUpdateDocumentationDrawer } from './ProviderEServiceUpdateDocumentationDrawer'
import { AuthHooks } from '@/api/auth'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

type ProviderEServiceDocumentationSectionProps = {
descriptor: ProducerEServiceDescriptor
Expand All @@ -24,6 +26,13 @@ export const ProviderEServiceDocumentationSection: React.FC<
})
const { t: tCommon } = useTranslation('common')

const { jwt } = AuthHooks.useJwt()

const { isDelegator } = useGetDelegationUserRole({
eserviceId: descriptor.eservice.id,
organizationId: jwt?.organizationId,
})

const docs = [descriptor.interface, ...descriptor.docs]

const { isOpen, openDrawer, closeDrawer } = useDrawerState()
Expand All @@ -50,13 +59,17 @@ export const ProviderEServiceDocumentationSection: React.FC<
<SectionContainer
innerSection
title={t('documentation.title')}
topSideActions={[
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]}
topSideActions={
isDelegator
? []
: [
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]
}
>
<InformationContainer
label={t('documentation.label')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ProviderEServiceUsefulLinksSection } from './ProviderEServiceUsefulLink
import { ProviderEServiceDocumentationSection } from './ProviderEServiceDocumentationSection'
import { useSuspenseQuery } from '@tanstack/react-query'
import { STAGE } from '@/config/env'
import { PagoPAEnvVars } from '@/types/common.types'
import type { PagoPAEnvVars } from '@/types/common.types'

export const ProviderEServiceTechnicalInfoSection: React.FC = () => {
const signalHubFlagDisabledStage: PagoPAEnvVars['STAGE'][] = ['PROD', 'UAT']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { InformationContainer } from '@pagopa/interop-fe-commons'
import { formatThousands, secondsToMinutes } from '@/utils/format.utils'
import { useDrawerState } from '@/hooks/useDrawerState'
import { ProviderEServiceUpdateThresholdsDrawer } from './ProviderEServiceUpdateThresholdsDrawer'
import { AuthHooks } from '@/api/auth'
import { useGetDelegationUserRole } from '@/hooks/useGetDelegationUserRole'

type ProviderEServiceThresholdsSectionProps = {
descriptor: ProducerEServiceDescriptor
Expand All @@ -21,6 +23,13 @@ export const ProviderEServiceThresholdsSection: React.FC<
})
const { t: tCommon } = useTranslation('common')

const { jwt } = AuthHooks.useJwt()

const { isDelegator } = useGetDelegationUserRole({
eserviceId: descriptor.eservice.id,
organizationId: jwt?.organizationId,
})

const voucherLifespan = secondsToMinutes(descriptor.voucherLifespan)

const { isOpen, openDrawer, closeDrawer } = useDrawerState()
Expand All @@ -34,13 +43,17 @@ export const ProviderEServiceThresholdsSection: React.FC<
<SectionContainer
innerSection
title={t('thresholds.title')}
topSideActions={[
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]}
topSideActions={
isDelegator
? []
: [
{
action: onEdit,
label: tCommon('actions.edit'),
icon: EditIcon,
},
]
}
>
<Stack spacing={2}>
<InformationContainer
Expand Down
Loading