Skip to content

Commit

Permalink
Merge branch 'main' into feat/dl-65plus
Browse files Browse the repository at this point in the history
  • Loading branch information
stjanilofts authored Oct 7, 2024
2 parents ea0a7a8 + c7ad42c commit ccab305
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 24 deletions.
10 changes: 6 additions & 4 deletions apps/service-portal/src/screens/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
DocumentsPaths,
DocumentLine,
DocumentLineV3,
useDocumentList,
useDocumentListV3,
} from '@island.is/service-portal/documents'
import {
LinkResolver,
Expand All @@ -41,9 +41,7 @@ import { useFeatureFlagClient } from '@island.is/react/feature-flags'

export const Dashboard: FC<React.PropsWithChildren<unknown>> = () => {
const { userInfo } = useAuth()
const { filteredDocuments, data, loading } = useDocumentList({
defaultPageSize: 8,
})

const { data: organizations } = useOrganizations()
const { formatMessage } = useLocale()
const { width } = useWindowSize()
Expand All @@ -56,6 +54,10 @@ export const Dashboard: FC<React.PropsWithChildren<unknown>> = () => {
// Versioning feature flag. Remove after feature is live.
const [v3Enabled, setV3Enabled] = useState<boolean>()

const { filteredDocuments, data, loading } = useDocumentListV3({
defaultPageSize: 8,
})

const featureFlagClient = useFeatureFlagClient()
useEffect(() => {
const isFlagEnabled = async () => {
Expand Down
3 changes: 2 additions & 1 deletion libs/api/domains/documents/src/lib/document.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { DocumentServiceV2 } from './documentV2.service'
import { DocumentResolverV1 } from './documentV1.resolver'
import { DocumentResolverV2 } from './documentV2.resolver'
import { DocumentService } from './documentV1.service'
import { FeatureFlagModule } from '@island.is/nest/feature-flags'

@Module({
imports: [DocumentsClientV2Module, DocumentsClientModule],
imports: [DocumentsClientV2Module, DocumentsClientModule, FeatureFlagModule],
providers: [
DocumentResolverV2,
DocumentResolverV1,
Expand Down
36 changes: 27 additions & 9 deletions libs/api/domains/documents/src/lib/documentV2.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
Document as DocumentV2,
PaginatedDocuments,
} from './models/v2/document.model'

import {
FeatureFlagGuard,
FeatureFlagService,
Features,
} from '@island.is/nest/feature-flags'
import { PostRequestPaperInput } from './dto/postRequestPaperInput'
import { DocumentInput } from './models/v2/document.input'
import { DocumentServiceV2 } from './documentV2.service'
Expand All @@ -35,13 +39,14 @@ import { DocumentConfirmActions } from './models/v2/confirmActions.model'

const LOG_CATEGORY = 'documents-resolver'

@UseGuards(IdsUserGuard, ScopesGuard)
@UseGuards(IdsUserGuard, ScopesGuard, FeatureFlagGuard)
@Resolver(() => PaginatedDocuments)
@Audit({ namespace: '@island.is/api/document-v2' })
export class DocumentResolverV2 {
constructor(
private documentServiceV2: DocumentServiceV2,
private readonly auditService: AuditService,
private readonly featureFlagService: FeatureFlagService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

Expand All @@ -53,6 +58,7 @@ export class DocumentResolverV2 {
locale: Locale = 'is',
@CurrentUser() user: User,
): Promise<DocumentV2 | null> {
const ffEnabled = await this.getFeatureFlag()
try {
return await this.auditService.auditPromise(
{
Expand All @@ -62,12 +68,14 @@ export class DocumentResolverV2 {
resources: input.id,
meta: { includeDocument: input.includeDocument },
},
this.documentServiceV2.findDocumentById(
user.nationalId,
input.id,
locale,
input.includeDocument,
),
ffEnabled
? this.documentServiceV2.findDocumentByIdV3(
user.nationalId,
input.id,
locale,
input.includeDocument,
)
: this.documentServiceV2.findDocumentById(user.nationalId, input.id),
)
} catch (e) {
this.logger.info('failed to get single document', {
Expand All @@ -82,10 +90,13 @@ export class DocumentResolverV2 {
@Scopes(DocumentsScope.main)
@Query(() => PaginatedDocuments, { nullable: true })
@Audit()
documentsV2(
async documentsV2(
@Args('input') input: DocumentsInput,
@CurrentUser() user: User,
): Promise<PaginatedDocuments> {
const ffEnabled = await this.getFeatureFlag()
if (ffEnabled)
return this.documentServiceV2.listDocumentsV3(user.nationalId, input)
return this.documentServiceV2.listDocuments(user.nationalId, input)
}

Expand Down Expand Up @@ -206,4 +217,11 @@ export class DocumentResolverV2 {
throw e
}
}

private async getFeatureFlag(): Promise<boolean> {
return await this.featureFlagService.getValue(
Features.isServicePortalDocumentsV3PageEnabled,
false,
)
}
}
108 changes: 108 additions & 0 deletions libs/api/domains/documents/src/lib/documentV2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,51 @@ export class DocumentServiceV2 {
async findDocumentById(
nationalId: string,
documentId: string,
): Promise<Document | null> {
const document = await this.documentService.getCustomersDocument(
nationalId,
documentId,
)

if (!document) {
return null // Null document logged in clients-documents-v2
}

let type: FileType
switch (document.fileType) {
case 'html':
type = FileType.HTML
break
case 'pdf':
type = FileType.PDF
break
case 'url':
type = FileType.URL
break
default:
type = FileType.UNKNOWN
}

return {
...document,
publicationDate: document.date,
id: documentId,
name: document.fileName,
downloadUrl: `${this.downloadServiceConfig.baseUrl}/download/v1/electronic-documents/${documentId}`,
sender: {
id: document.senderNationalId,
name: document.senderName,
},
content: {
type,
value: document.content,
},
}
}

async findDocumentByIdV3(
nationalId: string,
documentId: string,
locale?: string,
includeDocument?: boolean,
): Promise<Document | null> {
Expand Down Expand Up @@ -123,6 +168,69 @@ export class DocumentServiceV2 {
nationalId,
})

if (typeof documents?.totalCount !== 'number') {
this.logger.warn('Document total count unavailable', {
category: LOG_CATEGORY,
totalCount: documents?.totalCount,
})
}

const documentData: Array<Document> =
documents?.documents
.map((d) => {
if (!d) {
return null
}

return {
...d,
id: d.id,
downloadUrl: `${this.downloadServiceConfig.baseUrl}/download/v1/electronic-documents/${d.id}`,
sender: {
name: d.senderName,
id: d.senderNationalId,
},
}
})
.filter(isDefined) ?? []

return {
data: documentData,
totalCount: documents?.totalCount ?? 0,
unreadCount: documents?.unreadCount,
pageInfo: {
hasNextPage: false,
},
}
}

async listDocumentsV3(
nationalId: string,
input: DocumentsInput,
): Promise<PaginatedDocuments> {
//If a delegated user is viewing the mailbox, do not return any health related data
//Category is now "1,2,3,...,n"
const { categoryIds, ...restOfInput } = input
let mutableCategoryIds = categoryIds ?? []

if (input.isLegalGuardian) {
if (!mutableCategoryIds.length) {
mutableCategoryIds = (await this.getCategories(nationalId, true)).map(
(c) => c.id,
)
} else {
mutableCategoryIds = mutableCategoryIds.filter(
(c) => c === HEALTH_CATEGORY_ID,
)
}
}

const documents = await this.documentService.getDocumentList({
...restOfInput,
categoryId: mutableCategoryIds.join(),
nationalId,
})

if (typeof documents?.totalCount !== 'number') {
this.logger.warn('Document total count unavailable', {
category: LOG_CATEGORY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export class DocumentContent {
@Field(() => FileType)
type!: FileType

@Field({
@Field(() => String, {
description: 'Either pdf base64 string, html markup string, or an url',
nullable: true,
})
value!: string
value?: string | null
}
2 changes: 1 addition & 1 deletion libs/feature-flags/src/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export enum Features {
ServicePortalNotificationsEnabled = 'isServicePortalNotificationsPageEnabled',
servicePortalLawAndOrderModuleEnabled = 'isServicePortalLawAndOrderModuleEnabled',
servicePortalDocumentsActionsEnabled = 'isServicePortalDocumentsActionsEnabled',

isServicePortalDocumentsV3PageEnabled = 'isServicePortalDocumentsV3PageEnabled',
//Occupational License Health directorate fetch enabled
occupationalLicensesHealthDirectorate = 'isHealthDirectorateOccupationalLicenseEnabled',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
useNavigate,
useParams,
} from 'react-router-dom'
import { useDocumentList } from '../../hooks/useDocumentListV3'
import { useDocumentListV3 } from '../../hooks/useDocumentListV3'
import { useIsChildFocusedorHovered } from '../../hooks/useIsChildFocused'
import { useMailAction } from '../../hooks/useMailActionV2'
import { DocumentsPaths } from '../../lib/paths'
Expand Down Expand Up @@ -75,7 +75,7 @@ export const DocumentLineV3: FC<Props> = ({
bookmarkSuccess,
} = useMailAction()

const { fetchObject, refetch } = useDocumentList()
const { fetchObject, refetch } = useDocumentListV3()

const {
setActiveDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import NoPDF from '../NoPDF/NoPDF'
import { SERVICE_PORTAL_HEADER_HEIGHT_LG } from '@island.is/service-portal/constants'
import { useDocumentContext } from '../../screens/Overview/DocumentContext'
import * as styles from './OverviewDisplay.css'
import { useDocumentList } from '../../hooks/useDocumentListV3'
import { useDocumentListV3 } from '../../hooks/useDocumentListV3'

interface Props {
activeBookmark: boolean
Expand All @@ -25,7 +25,7 @@ export const DesktopOverview: FC<Props> = ({
useNamespaces('sp.documents')
const { formatMessage } = useLocale()
const { activeDocument } = useDocumentContext()
const { activeArchive } = useDocumentList()
const { activeArchive } = useDocumentListV3()

if (loading) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const pageSize = 10

type UseDocumentListProps = { defaultPageSize?: number }

export const useDocumentList = (props?: UseDocumentListProps) => {
export const useDocumentListV3 = (props?: UseDocumentListProps) => {
const {
filterValue,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import DocumentLine from '../../components/DocumentLine/DocumentLineV3'
import { FavAndStashV3 } from '../../components/FavAndStash/FavAndStashV3'
import DocumentDisplay from '../../components/OverviewDisplay/OverviewDocumentDisplayV3'
import { useDocumentFilters } from '../../hooks/useDocumentFilters'
import { pageSize, useDocumentList } from '../../hooks/useDocumentListV3'
import { pageSize, useDocumentListV3 } from '../../hooks/useDocumentListV3'
import { useKeyDown } from '../../hooks/useKeyDown'
import { useMailAction } from '../../hooks/useMailActionV2'
import { DocumentsPaths } from '../../lib/paths'
Expand Down Expand Up @@ -58,7 +58,7 @@ export const ServicePortalDocumentsV3 = () => {
totalPages,
filteredDocuments,
totalCount,
} = useDocumentList()
} = useDocumentListV3()

const { handlePageChange, handleSearchChange } = useDocumentFilters()

Expand Down

0 comments on commit ccab305

Please sign in to comment.