Skip to content

Commit 2e4a8a5

Browse files
committed
Frontend for pdf-export
1 parent 83a3c82 commit 2e4a8a5

File tree

6 files changed

+117
-6
lines changed

6 files changed

+117
-6
lines changed

src/components/left-section/search/search-input/search-settings/SearchSettings.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const SearchSettings = () => {
7373
</RadioGroup>
7474
</div>
7575
<UNSAFE_Combobox
76-
label={'Avgrens til valgte kategorier'}
76+
label={'Avgrens søket til valgte kategorier:'}
7777
size={'small'}
7878
className={style.categoriesSelector}
7979
clearButton={true}

src/components/main-section/content-view/ContentView.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ViewSelector, ViewState } from '../view-selector/ViewSelector';
77
import { VersionSelector } from './version-selector/VersionSelector';
88
import { Heading } from '@navikt/ds-react';
99
import { CategoriesPath } from '../../common/categories-path/CategoriesPath';
10+
import { HtmlExporter } from './html-exporter/HtmlExporter';
1011

1112
import style from './ContentView.module.css';
1213

@@ -39,7 +40,12 @@ export const ContentView = ({ content }: Props) => {
3940
<VersionSelector content={content} />
4041
</div>
4142
<XmlView xml={xmlAsString} hidden={viewState !== 'xml'} />
42-
{html && <HtmlView html={html} versionKey={versionKey} hidden={viewState !== 'html'} />}
43+
{html && (
44+
<>
45+
<HtmlView html={html} versionKey={versionKey} hidden={viewState !== 'html'} />
46+
<HtmlExporter content={content} hidden={viewState !== 'export'} />
47+
</>
48+
)}
4349
{content.binaries && (
4450
<FilesView binaries={content.binaries} hidden={viewState !== 'files'} />
4551
)}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.exporter {
2+
overflow-y: scroll;
3+
height: 100%;
4+
scrollbar-width: thin;
5+
}
6+
7+
.hidden {
8+
display: none;
9+
}
10+
11+
.topRow {
12+
display: flex;
13+
justify-content: space-between;
14+
align-items: center;
15+
border-bottom: 1px solid var(--a-gray-400);
16+
margin-bottom: 0.75rem;
17+
padding: 0.5rem 0;
18+
}
19+
20+
.downloadCurrent {
21+
margin-right: 0.5rem;
22+
}
23+
24+
.downloadCurrentIcon{
25+
transform: rotate(-90deg);
26+
}
27+
28+
.checkboxGroup {
29+
margin-top: 1rem;
30+
31+
:global(.navds-checkbox__label) {
32+
padding: 0.1875rem;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, { useState } from 'react';
2+
import { CmsContentDocument } from '../../../../../common/cms-documents/content';
3+
import { Button, Checkbox, CheckboxGroup, Heading } from '@navikt/ds-react';
4+
import { classNames } from '../../../../utils/classNames';
5+
import { useAppState } from '../../../../context/app-state/useAppState';
6+
import { ArrowDownRightIcon } from '@navikt/aksel-icons';
7+
8+
import style from './HtmlExporter.module.css';
9+
10+
type Props = {
11+
content: CmsContentDocument;
12+
hidden?: boolean;
13+
};
14+
15+
export const HtmlExporter = ({ content, hidden }: Props) => {
16+
const { appContext } = useAppState();
17+
const { basePath } = appContext;
18+
19+
const [versionKeysSelected, setVersionKeysSelected] = useState<string[]>([]);
20+
21+
const pdfApi = `${basePath}/pdf`;
22+
23+
const { versionKey, versions } = content;
24+
25+
return (
26+
<div className={classNames(style.exporter, hidden && style.hidden)}>
27+
<div className={style.topRow}>
28+
<Heading size={'small'} level={'3'}>
29+
{'Eksporter til PDF'}
30+
</Heading>
31+
<Button
32+
variant={'primary'}
33+
size={'small'}
34+
as={'a'}
35+
href={`${pdfApi}/single/${versionKey}`}
36+
icon={<ArrowDownRightIcon className={style.downloadCurrentIcon} />}
37+
iconPosition={'right'}
38+
className={style.downloadCurrent}
39+
>
40+
{'Last ned denne versjonen'}
41+
</Button>
42+
</div>
43+
<Button
44+
variant={'primary'}
45+
size={'small'}
46+
as={'a'}
47+
href={`${pdfApi}/multi/${versionKeysSelected.join(',')}`}
48+
disabled={versionKeysSelected.length === 0}
49+
>
50+
{'Last ned valgte versjoner'}
51+
</Button>
52+
<CheckboxGroup
53+
legend={'Last ned flere versjoner'}
54+
size={'small'}
55+
className={style.checkboxGroup}
56+
onChange={setVersionKeysSelected}
57+
>
58+
{versions.map((version) => {
59+
const dateTime = new Date(version.timestamp).toLocaleString('no');
60+
return (
61+
<Checkbox value={version.key} size={'small'} key={version.key}>
62+
{`${version.title} - [${dateTime}]`}
63+
</Checkbox>
64+
);
65+
})}
66+
</CheckboxGroup>
67+
</div>
68+
);
69+
};

src/components/main-section/content-view/xml-view/XmlView.module.css

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.container {
22
position: relative;
33
overflow: hidden;
4+
height: 100%;
45
}
56

67
.xmlContainer {

src/components/main-section/view-selector/ViewSelector.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CmsContent } from '../../../../common/cms-documents/content';
55

66
import style from './ViewSelector.module.css';
77

8-
export type ViewState = 'html' | 'xml' | 'files' | 'none';
8+
export type ViewState = 'html' | 'xml' | 'files' | 'export' | 'none';
99

1010
type Props = {
1111
content: CmsContent;
@@ -36,9 +36,10 @@ export const ViewSelector = ({ content, viewState, setViewState }: Props) => {
3636
}
3737
}}
3838
>
39-
{'Vis nettside'}
39+
{'Nettside'}
4040
</ToggleGroup.Item>
4141
</WithTooltip>
42+
{html && <ToggleGroup.Item value={'export'}>{'Eksporter'}</ToggleGroup.Item>}
4243
<WithTooltip tooltip={filesCount === 0 ? 'Innholdet har ingen filer' : undefined}>
4344
<ToggleGroup.Item
4445
value={'files'}
@@ -49,10 +50,10 @@ export const ViewSelector = ({ content, viewState, setViewState }: Props) => {
4950
}
5051
}}
5152
>
52-
{`Vis filer (${filesCount})`}
53+
{`Filer (${filesCount})`}
5354
</ToggleGroup.Item>
5455
</WithTooltip>
55-
<ToggleGroup.Item value={'xml'}>{'Vis XML'}</ToggleGroup.Item>
56+
<ToggleGroup.Item value={'xml'}>{'XML'}</ToggleGroup.Item>
5657
</ToggleGroup>
5758
);
5859
};

0 commit comments

Comments
 (0)