Skip to content

Commit

Permalink
Merge branch 'main' into feature/web-single-expand-faq-list
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 29, 2024
2 parents 72c1b2e + cb65af3 commit dd1c6b6
Show file tree
Hide file tree
Showing 713 changed files with 20,117 additions and 6,714 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ jobs:
# See this for more information:
# https://github.blog/changelog/2020-10-08-github-actions-ability-to-change-retention-days-for-artifacts-and-logs/
- name: Keep PR run event
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@b18b1d32f3f31abcdc29dee3f2484801fe7822f4
with:
name: pr-event
path: event.json
retention-days: 90
include-hidden-files: true
if-no-files-found: error

- name: Get cache
id: get-cache
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ jobs:
# See this for more information:
# https://github.blog/changelog/2020-10-08-github-actions-ability-to-change-retention-days-for-artifacts-and-logs/
- name: Keep PR run event
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@b18b1d32f3f31abcdc29dee3f2484801fe7822f4
if: needs.pre-checks.outputs.PRE_CHECK && needs.pre-checks.outputs.PRE_CHECK == 'feature-deploy'
with:
name: pr-event
path: event.json
retention-days: 90
include-hidden-files: true
if-no-files-found: error

- name: Generate nodejs image tag
id: nodejs_image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
NationalRegistryClientModule,
} from '@island.is/clients/national-registry-v2'
import { CACHE_MANAGER } from '@nestjs/cache-manager'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { ConfigModule, XRoadConfig } from '@island.is/nest/config'
import { AirlineUser } from '../../../user/user.model'
import { createTestUser } from '../../../../../../test/createTestUser'
Expand Down Expand Up @@ -73,6 +74,12 @@ describe('DiscountController', () => {
getUser: () => ({}),
})),
},
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
})),
},
{
provide: FlightService,
useClass: jest.fn(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createTestUser } from '../../../../../../test/createTestUser'
import { getModelToken } from '@nestjs/sequelize'
import { ExplicitCode } from '../../discount.model'
import { AirDiscountSchemeScope } from '@island.is/auth/scopes'
import { LOGGER_PROVIDER } from '@island.is/logging'
import type { User as AuthUser } from '@island.is/auth-nest-tools'
import {
NationalRegistryService,
Expand Down Expand Up @@ -60,6 +61,12 @@ describe('DiscountService', () => {
create: () => ({}),
})),
},
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
})),
},
{
provide: FlightService,
useClass: jest.fn(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export class NationalRegistryService {
const response = await this.personApi.getIndividual(nationalId)

if (!response) {
this.logger.info('getUser individual not found', {
category: 'ads-backend',
})
return null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Cache as CacheManager } from 'cache-manager'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { Test } from '@nestjs/testing'
import { User } from '../../user.model'
import { UserService } from '../../user.service'
Expand Down Expand Up @@ -50,6 +51,12 @@ describe('UserService', () => {
set: () => ({}),
})),
},
{
provide: LOGGER_PROVIDER,
useClass: jest.fn(() => ({
error: () => ({}),
})),
},
],
}).compile()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
} from '../nationalRegistry'
import type { User as AuthUser } from '@island.is/auth-nest-tools'
import { info } from 'kennitala'
import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

const ONE_WEEK = 604800 // seconds
const CACHE_KEY = 'userService'
Expand All @@ -24,6 +26,8 @@ export class UserService {
constructor(
private readonly flightService: FlightService,
private readonly nationalRegistryService: NationalRegistryService,
@Inject(LOGGER_PROVIDER)
private readonly logger: Logger,
@Inject(CACHE_MANAGER) private readonly cacheManager: CacheManager,
) {}

Expand Down Expand Up @@ -118,9 +122,13 @@ export class UserService {
const result = (await Promise.all(allUsers)).filter(Boolean) as Array<User>

if (!result || result.length === 0) {
throw new Error(
'Could not find NationalRegistry records of neither User or relatives.',
this.logger.warn(
'National Registry records for the user or their relatives could not be found.',
{
category: 'ads-backend',
},
)
return []
}

return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ beforeAll(async () => {
describe('Application system payments callback API', () => {
// Sets the payment status to paid.
it(`POST /application-payment/32eee126-6b7f-4fca-b9a0-a3618b3e42bf/6b11dc9f-a694-440e-b3dd-7163b5f34815 should update payment fulfilled`, async () => {
await server
const response = await server
.post(
'/application-payment/32eee126-6b7f-4fca-b9a0-a3618b3e42bf/6b11dc9f-a694-440e-b3dd-7163b5f34815',
)
.send({
callback: {
receptionID: '1234567890',
chargeItemSubject: 'Very nice subject',
status: 'paid',
},
receptionID: '123e4567-e89b-12d3-a456-426614174000', // Updated to real UUID
chargeItemSubject: 'Very nice subject',
status: 'paid',
})
.expect(201)
expect(response.status).toBe(201)
})

// Fails to set the payment status to paid.
Expand All @@ -37,11 +35,9 @@ describe('Application system payments callback API', () => {
'/application-payment/32eee126-6b7f-4fca-b9a0-a3618b3e42bf/missing-id',
)
.send({
callback: {
receptionID: '1234567890',
chargeItemSubject: 'nice subject.. not',
status: 'paid',
},
receptionID: '123e4567-e89b-12d3-a456-426614174000', // Updated to real UUID
chargeItemSubject: 'nice subject.. not',
status: 'paid',
})
.expect(400)
})
Expand Down
1 change: 1 addition & 0 deletions apps/application-system/api/src/openApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const openApi = new DocumentBuilder()
.setVersion('1.0')
.addTag('application')
.addTag('payment')
.addTag('payment-callback')
.addBearerAuth()
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const GenericListEditor = () => {
skip,
'fields.internalTitle[match]': searchValue,
'fields.genericList.sys.id': sdk.entry.getSys().id,
'sys.archivedAt[exists]': false,
},
})
if (
Expand Down
180 changes: 180 additions & 0 deletions apps/contentful-apps/pages/fields/generic-tag-group-items-field.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import { useEffect, useRef, useState } from 'react'
import { useDebounce } from 'react-use'
import type { FieldExtensionSDK } from '@contentful/app-sdk'
import {
Box,
Button,
EntryCard,
Pagination,
Spinner,
Stack,
Text,
TextInput,
} from '@contentful/f36-components'
import { PlusIcon } from '@contentful/f36-icons'
import { useCMA, useSDK } from '@contentful/react-apps-toolkit'

const LIST_ITEMS_PER_PAGE = 4
const SEARCH_DEBOUNCE_TIME_IN_MS = 300

const GenericTagGroupItemsField = () => {
const [page, setPage] = useState(0)
const pageRef = useRef(0)
const [searchValue, setSearchValue] = useState('')
const searchValueRef = useRef('')
const [listItemResponse, setListItemResponse] = useState(null)
const [isLoading, setIsLoading] = useState(false)

const [counter, setCounter] = useState(0)

const sdk = useSDK<FieldExtensionSDK>()
const cma = useCMA()

const skip = LIST_ITEMS_PER_PAGE * page

const createGenericTag = async () => {
const tag = await cma.entry.create(
{
contentTypeId: 'genericTag',
environmentId: sdk.ids.environment,
spaceId: sdk.ids.space,
},
{
fields: {
genericTagGroup: {
[sdk.locales.default]: {
sys: {
id: sdk.entry.getSys().id,
linkType: 'Entry',
type: 'Link',
},
},
},
},
},
)
sdk.navigator
.openEntry(tag.sys.id, {
slideIn: { waitForClose: true },
})
.then(() => {
setCounter((c) => c + 1)
})
}

useDebounce(
async () => {
setIsLoading(true)
try {
const response = await cma.entry.getMany({
query: {
content_type: 'genericTag',
limit: LIST_ITEMS_PER_PAGE,
skip,
'fields.internalTitle[match]': searchValue,
'fields.genericTagGroup.sys.id': sdk.entry.getSys().id,
'sys.archivedAt[exists]': false,
},
})

if (
searchValueRef.current === searchValue &&
pageRef.current === page
) {
setListItemResponse(response)
}
} finally {
setIsLoading(false)
}
},
SEARCH_DEBOUNCE_TIME_IN_MS,
[page, searchValue, counter],
)

useEffect(() => {
sdk.window.startAutoResizer()
return () => {
sdk.window.stopAutoResizer()
}
}, [sdk.window])

return (
<div style={{ display: 'flex', flexDirection: 'column', gap: '24px' }}>
<Box>
<Box
onClick={createGenericTag}
style={{ display: 'flex', justifyContent: 'flex-end' }}
>
<Button startIcon={<PlusIcon />}>Create tag</Button>
</Box>
</Box>
<Box style={{ display: 'flex', flexFlow: 'column nowrap', gap: '24px' }}>
<TextInput
placeholder="Search for a generic tag"
value={searchValue}
onChange={(ev) => {
searchValueRef.current = ev.target.value
setSearchValue(ev.target.value)
setPage(0)
pageRef.current = 0
}}
/>

<Box
style={{
display: 'flex',
justifyContent: 'center',
visibility: isLoading ? 'visible' : 'hidden',
}}
>
<Spinner />
</Box>

{listItemResponse?.items?.length > 0 && (
<>
<Box style={{ minHeight: '440px' }}>
<Stack flexDirection="column" spacing="spacingL">
{listItemResponse.items.map((item) => (
<EntryCard
key={item.sys.id}
contentType="Generic Tag"
title={
item.fields.internalTitle?.[sdk.locales.default] ??
'Untitled'
}
onClick={() => {
sdk.navigator
.openEntry(item.sys.id, {
slideIn: { waitForClose: true },
})
.then(() => {
setCounter((c) => c + 1)
})
}}
/>
))}
</Stack>
</Box>
<Pagination
activePage={page}
itemsPerPage={LIST_ITEMS_PER_PAGE}
totalItems={listItemResponse.total}
onPageChange={(newPage) => {
pageRef.current = newPage
setPage(newPage)
}}
/>
</>
)}

{listItemResponse?.items?.length === 0 && (
<Box style={{ display: 'flex', justifyContent: 'center' }}>
<Text>No item was found</Text>
</Box>
)}
</Box>
</div>
)
}

export default GenericTagGroupItemsField
Loading

0 comments on commit dd1c6b6

Please sign in to comment.