-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add PDF config for layoutset (#13512)
Co-authored-by: Erling Hauan <148075168+ErlingHauan@users.noreply.github.com>
- Loading branch information
1 parent
9b8ebe5
commit 8292aeb
Showing
33 changed files
with
717 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...d/packages/ux-editor/src/components/Properties/PageConfigPanel/PageConfigPanel.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.pdf, | ||
.text { | ||
padding: var(--fds-spacing-5) 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../PageConfigPanel/PdfConfig/ConvertPageToPdfWhenExistingModal/ConvertChoicesModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { createRef } from 'react'; | ||
import { formLayoutSettingsMock, renderWithProviders } from '@altinn/ux-editor/testing/mocks'; | ||
import { ConvertChoicesModal } from '@altinn/ux-editor/components/Properties/PageConfigPanel/PdfConfig/ConvertPageToPdfWhenExistingModal/ConvertChoicesModal'; | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
import { app, org } from '@studio/testing/testids'; | ||
import { layoutSet1NameMock } from '@altinn/ux-editor/testing/layoutSetsMock'; | ||
import { layout1NameMock } from '@altinn/ux-editor/testing/layoutMock'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { screen } from '@testing-library/react'; | ||
import type { ILayoutSettings } from 'app-shared/types/global'; | ||
import type { AppContextProps } from '@altinn/ux-editor/AppContext'; | ||
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext'; | ||
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
|
||
const selectedLayoutSet = layoutSet1NameMock; | ||
const handleModalActionMock = jest.fn(); | ||
|
||
describe('ConvertChoicesModal', () => { | ||
afterEach(() => jest.clearAllMocks()); | ||
it('converts existing pdf back to formLayout when clicking convert in conversion choices modal', async () => { | ||
const user = userEvent.setup(); | ||
const pdfLayoutNameMock = 'pdfLayoutNameMock'; | ||
const mutateLayoutSettingsMock = jest.fn(); | ||
await renderConvertChoicesModal( | ||
{ pages: { order: [layout1NameMock], pdfLayoutName: pdfLayoutNameMock } }, | ||
{}, | ||
{ saveFormLayoutSettings: mutateLayoutSettingsMock }, | ||
); | ||
const convertExistingPdfToFormLayout = screen.getByRole('button', { | ||
name: textMock('ux_editor.page_config_pdf_convert_existing_pdf'), | ||
}); | ||
await user.click(convertExistingPdfToFormLayout); | ||
expect(mutateLayoutSettingsMock).toHaveBeenCalledTimes(1); | ||
expect(mutateLayoutSettingsMock).toHaveBeenCalledWith(org, app, layoutSet1NameMock, { | ||
pages: { order: [pdfLayoutNameMock], pdfLayoutName: layout1NameMock }, | ||
}); | ||
}); | ||
|
||
it('deletes existing pdf when clicking delete in conversion choices modal', async () => { | ||
const user = userEvent.setup(); | ||
const pdfLayoutNameMock = 'pdfLayoutNameMock'; | ||
const mutateLayoutSettingsMock = jest.fn(); | ||
const deleteLayoutMock = jest.fn(); | ||
await renderConvertChoicesModal( | ||
{ pages: { order: [layout1NameMock], pdfLayoutName: pdfLayoutNameMock } }, | ||
{}, | ||
{ saveFormLayoutSettings: mutateLayoutSettingsMock, deleteFormLayout: deleteLayoutMock }, | ||
); | ||
const deleteExistingPdf = screen.getByRole('button', { | ||
name: textMock('ux_editor.page_config_pdf_delete_existing_pdf'), | ||
}); | ||
await user.click(deleteExistingPdf); | ||
expect(mutateLayoutSettingsMock).toHaveBeenCalledTimes(2); // Once from pdfConfig and another from deleteLayout | ||
expect(mutateLayoutSettingsMock).toHaveBeenCalledWith(org, app, layoutSet1NameMock, { | ||
pages: { order: [], pdfLayoutName: layout1NameMock }, | ||
}); | ||
expect(deleteLayoutMock).toHaveBeenCalledTimes(1); | ||
expect(deleteLayoutMock).toHaveBeenCalledWith(org, app, pdfLayoutNameMock, selectedLayoutSet); | ||
}); | ||
|
||
it('calls handleModalAction when converting existing pdf', async () => { | ||
const user = userEvent.setup(); | ||
const pdfLayoutNameMock = 'pdfLayoutNameMock'; | ||
await renderConvertChoicesModal({ | ||
pages: { order: [layout1NameMock], pdfLayoutName: pdfLayoutNameMock }, | ||
}); | ||
const convertExistingPdfToFormLayout = screen.getByRole('button', { | ||
name: textMock('ux_editor.page_config_pdf_convert_existing_pdf'), | ||
}); | ||
await user.click(convertExistingPdfToFormLayout); | ||
expect(handleModalActionMock).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('calls handleModalAction when deleting existing pdf', async () => { | ||
const user = userEvent.setup(); | ||
const pdfLayoutNameMock = 'pdfLayoutNameMock'; | ||
await renderConvertChoicesModal({ | ||
pages: { order: [layout1NameMock], pdfLayoutName: pdfLayoutNameMock }, | ||
}); | ||
const deleteExistingPdf = screen.getByRole('button', { | ||
name: textMock('ux_editor.page_config_pdf_delete_existing_pdf'), | ||
}); | ||
await user.click(deleteExistingPdf); | ||
expect(handleModalActionMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
const renderConvertChoicesModal = async ( | ||
layoutSettings: Partial<ILayoutSettings> = {}, | ||
appContextProps: Partial<AppContextProps> = {}, | ||
queries: Partial<ServicesContextProps> = {}, | ||
) => { | ||
const ref = createRef<HTMLDialogElement>(); | ||
const queryClient = createQueryClientMock(); | ||
queryClient.setQueryData([QueryKey.FormLayoutSettings, org, app, selectedLayoutSet], { | ||
...formLayoutSettingsMock, | ||
...layoutSettings, | ||
}); | ||
renderWithProviders(<ConvertChoicesModal handleModalAction={handleModalActionMock} ref={ref} />, { | ||
queries, | ||
queryClient, | ||
appContextProps, | ||
}); | ||
ref.current?.showModal(); | ||
await screen.findByRole('dialog'); | ||
}; |
57 changes: 57 additions & 0 deletions
57
...rties/PageConfigPanel/PdfConfig/ConvertPageToPdfWhenExistingModal/ConvertChoicesModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { StudioModal } from '@studio/components'; | ||
import { useForwardedRef } from '@studio/hooks'; | ||
import { OverrideCurrentPdfByConversionChoices } from './OverrideCurrentPdfByConversionChoices'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { usePdf } from '@altinn/ux-editor/hooks/usePdf/usePdf'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
import { useAppContext } from '@altinn/ux-editor/hooks'; | ||
import { useDeleteLayoutMutation } from '@altinn/ux-editor/hooks/mutations/useDeleteLayoutMutation'; | ||
import { useSavableFormLayoutSettings } from '@altinn/ux-editor/hooks/useSavableFormLayoutSettings'; | ||
|
||
type ConvertChoicesModalProps = { | ||
handleModalAction: () => void; | ||
}; | ||
export const ConvertChoicesModal = forwardRef<HTMLDialogElement, ConvertChoicesModalProps>( | ||
({ handleModalAction }, ref): JSX.Element => { | ||
const { org, app } = useStudioEnvironmentParams(); | ||
const { selectedFormLayoutSetName } = useAppContext(); | ||
const { t } = useTranslation(); | ||
const { mutate: deleteLayout } = useDeleteLayoutMutation(org, app, selectedFormLayoutSetName); | ||
const { getPdfLayoutName, convertCurrentPageToPdf, convertExistingPdfToPage } = usePdf(); | ||
const savableLayoutSettings = useSavableFormLayoutSettings(); | ||
const dialogRef = useForwardedRef<HTMLDialogElement>(ref); | ||
|
||
const handleConvertPageToPdfAndConvertCurrent = () => { | ||
convertExistingPdfToPage(); | ||
convertCurrentPageToPdf(); | ||
savableLayoutSettings.save(); | ||
handleModalAction(); | ||
dialogRef.current?.close(); | ||
}; | ||
|
||
const handleConvertPageToPdfAndDeleteCurrent = () => { | ||
const currentPdfLayoutName = getPdfLayoutName(); | ||
convertCurrentPageToPdf(); | ||
deleteLayout(currentPdfLayoutName); | ||
savableLayoutSettings.save(); | ||
handleModalAction(); | ||
dialogRef.current?.close(); | ||
}; | ||
|
||
return ( | ||
<StudioModal.Dialog | ||
closeButtonTitle={t('ux_editor.page_config_pdf_abort_converting_page_to_pdf')} | ||
heading={t('ux_editor.page_config_pdf_convert_page_to_pdf')} | ||
ref={dialogRef} | ||
> | ||
<OverrideCurrentPdfByConversionChoices | ||
onConvertPageToPdfAndConvertCurrent={handleConvertPageToPdfAndConvertCurrent} | ||
onConvertPageToPdfAndDeleteCurrent={handleConvertPageToPdfAndDeleteCurrent} | ||
/> | ||
</StudioModal.Dialog> | ||
); | ||
}, | ||
); | ||
|
||
ConvertChoicesModal.displayName = 'ConvertChoicesModal'; |
6 changes: 6 additions & 0 deletions
6
...Config/ConvertPageToPdfWhenExistingModal/OverrideCurrentPdfByConversionChoices.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.buttonContainer { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--fds-spacing-2); | ||
padding-top: var(--fds-spacing-10); | ||
} |
Oops, something went wrong.