Skip to content

Commit

Permalink
Add PDF capability to area search export
Browse files Browse the repository at this point in the history
  • Loading branch information
EmiliaMakelaVincit committed Sep 20, 2023
1 parent c0ded7c commit 6f9460e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/areaSearch/components/AreaSearchApplicationListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,8 @@ export default (flowRight(
initialValues: {
mode: null,
selectedSearches: {},
includeInformationChecks: false,
includeAttachments: false,
},
})
)(AreaSearchApplicationListPage): React$ComponentType<OwnProps>);
81 changes: 74 additions & 7 deletions src/areaSearch/components/AreaSearchExportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Props = {
change: Function,
selectedMode: ?string,
selectedSearches: {[key: string]: boolean},
includeInformationChecks: boolean,
includeAttachments: boolean,
};

export const ExportModes = {
Expand All @@ -39,11 +41,20 @@ class AreaSearchExportModal extends Component<Props> {

if (isOpen && !prevProps.isOpen) {
change('mode', null);
change('includePreparerInformation', false);
change('includeAttachments', false);
}
}

render(): React$Node {
const {isOpen, onClose, selectedMode, selectedSearches} = this.props;
const {
isOpen,
onClose,
selectedMode,
selectedSearches,
includeInformationChecks,
includeAttachments,
} = this.props;

const selectedSearchIds = Object.keys(selectedSearches).reduce((acc, key) => {
if (selectedSearches[key]) {
Expand All @@ -58,11 +69,24 @@ class AreaSearchExportModal extends Component<Props> {
switch (selectedMode) {
case ExportModes.APPLICATIONS_PDF:
guideText = 'Tulostus sisältää valitut hakemukset .pdf-muodossa.';
downloadUrl = createUrl(`area_search/get_answers_pdf/?ids=${selectedSearchIds.join(',')}`);

const params: {[key: string]: string} = {
ids: selectedSearchIds.join(','),
};
if (includeInformationChecks) {
params.show_information_check = '1';
}
if (includeAttachments) {
params.show_attachments = '1';
}

downloadUrl = createUrl('area_search_pdf/', params);
break;
case ExportModes.APPLICATIONS_XLS:
guideText = 'Tulostus sisältää valitut hakemukset .xls-muodossa.';
downloadUrl = createUrl(`area_search/get_answers_xlsx/?ids=${selectedSearchIds.join(',')}`);
downloadUrl = createUrl('area_search/get_answers_xlsx/', {
ids: selectedSearchIds.join(','),
});
break;
}

Expand All @@ -71,7 +95,7 @@ class AreaSearchExportModal extends Component<Props> {
isOpen={isOpen}
onClose={onClose}
title="Tulosta tiedostoon"
className="PlotSearchExportModal"
className="AreaSearchExportModal"
>

<FormField
Expand All @@ -94,7 +118,47 @@ class AreaSearchExportModal extends Component<Props> {
}}
disableDirty
/>
{guideText}
<span className="AreaSearchExportModal__guide-text">{guideText}</span>
{selectedMode === ExportModes.APPLICATIONS_PDF && <>
<FormField
name="includeInformationChecks"
fieldAttributes={{
type: FieldTypes.CHECKBOX,
required: false,
read_only: false,
label: 'Sisällytä tulostukseen käsittelytiedot',
}}
overrideValues={{
options: [
{
value: true,
label: 'Sisällytä tulostukseen käsittelytiedot',
},
],
}}
disableDirty
invisibleLabel
/>
<FormField
name="includeAttachments"
fieldAttributes={{
type: FieldTypes.CHECKBOX,
required: false,
read_only: false,
label: 'Sisällytä tulostukseen liitteet',
}}
overrideValues={{
options: [
{
value: true,
label: 'Sisällytä tulostukseen liitteet',
},
],
}}
disableDirty
invisibleLabel
/>
</>}
<ModalButtonWrapper>
<Button
className={ButtonColors.SECONDARY}
Expand All @@ -114,11 +178,14 @@ class AreaSearchExportModal extends Component<Props> {
}

const formName = FormNames.AREA_SEARCH_EXPORT;
const selector = formValueSelector(formName);

export default (flowRight(
connect((state: RootState) => ({
selectedMode: formValueSelector(formName)(state, 'mode'),
selectedSearches: formValueSelector(formName)(state, 'selectedSearches'),
selectedMode: selector(state, 'mode'),
selectedSearches: selector(state, 'selectedSearches'),
includeInformationChecks: selector(state, 'includeInformationChecks'),
includeAttachments: selector(state, 'includeAttachments'),
})),
reduxForm({
form: formName,
Expand Down
6 changes: 6 additions & 0 deletions src/areaSearch/components/_area-search-export-modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.AreaSearchExportModal {
.AreaSearchExportModal__guide-text {
display: block;
margin-bottom: rem-calc(8px);
}
}
5 changes: 3 additions & 2 deletions src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@
@import "plotApplications/components/infoCheck/plotApplicationInfoCheckCollapse";
@import "plotApplications/components/exportModal/PlotSearchExportModal";
@import "areaSearch/components/area-search-application";
@import "areaSearch/components/area-search-application-create";
@import "areaSearch/components/area-search-application-list-page";
@import "areaSearch/components/map/single-area-search-map";
@import "areaSearch/components/area-search-export-modal";
@import "areaSearch/components/area-search-status-note-history";
@import "areaSearch/components/edit-area-search-preparer-modal";
@import "areaSearch/components/area-search-application-create";
@import "areaSearch/components/map/area-search-map";
@import "areaSearch/components/map/single-area-search-map";
@import "application/components/applicant-info-check";

@import "foundation/styles";
Expand Down

0 comments on commit 6f9460e

Please sign in to comment.