Skip to content

Commit 76ac7ca

Browse files
committed
Merge branch 'main' into move-fullscreen-button
2 parents 5654cb2 + a6c6b9a commit 76ac7ca

File tree

8 files changed

+44
-46
lines changed

8 files changed

+44
-46
lines changed

xp-archive/client/content/Content.tsx

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { ExternalLinkIcon, SidebarRightIcon } from '@navikt/aksel-icons';
3-
import { Button, Detail, Heading, Label } from '@navikt/ds-react';
43
import { xpArchiveConfig } from '@common/shared/siteConfigs';
4+
import { Button, Detail, Heading, Label } from '@navikt/ds-react';
55
import { useFetchContent } from '../hooks/useFetchContent';
66
import { useAppState } from '../context/appState/useAppState';
77
import { ViewSelector, ViewVariant } from 'client/viewSelector/ViewSelector';
@@ -18,6 +18,11 @@ const getDefaultView = (isWebpage: boolean, hasAttachment: boolean): ViewVariant
1818
return undefined;
1919
};
2020

21+
const updateContentUrl = (nodeId: string, locale: string, versionId?: string) => {
22+
const newUrl = `${xpArchiveConfig.basePath}/${nodeId}/${locale}/${versionId ?? ''}`;
23+
window.history.pushState({}, '', newUrl);
24+
};
25+
2126
export const Content = () => {
2227
const { selectedContentId, selectedLocale, selectedVersion, setSelectedVersion } =
2328
useAppState();
@@ -37,6 +42,16 @@ export const Content = () => {
3742
versionId: selectedVersion ?? '',
3843
});
3944

45+
useEffect(() => {
46+
if (selectedVersion) {
47+
updateContentUrl(selectedContentId ?? '', selectedLocale, selectedVersion);
48+
} else if (data?.versions?.[0]) {
49+
const latestVersionId = data.versions[0].versionId;
50+
setSelectedVersion(latestVersionId);
51+
updateContentUrl(selectedContentId ?? '', selectedLocale, latestVersionId);
52+
}
53+
}, [data, selectedContentId, selectedLocale, selectedVersion]);
54+
4055
const isWebpage = !!data?.html && !data.json.attachment;
4156
const hasAttachment = !!data?.json.attachment;
4257
const [selectedView, setSelectedView] = useState<ViewVariant | undefined>(
@@ -52,6 +67,15 @@ export const Content = () => {
5267
data?.json._versionKey
5368
}`;
5469

70+
const getVersionDisplay = () => {
71+
if (selectedVersion && data?.versions) {
72+
return formatTimestamp(
73+
data.versions.find((v) => v.versionId === selectedVersion)?.timestamp ?? ''
74+
);
75+
}
76+
return 'Laster...';
77+
};
78+
5579
if (!selectedContentId) {
5680
return <EmptyState />;
5781
}
@@ -95,14 +119,7 @@ export const Content = () => {
95119
iconPosition={'right'}
96120
onClick={() => setIsVersionPanelOpen(true)}
97121
>
98-
{selectedVersion && data?.versions
99-
? formatTimestamp(
100-
data.versions.find((v) => v.versionId === selectedVersion)
101-
?.timestamp ?? ''
102-
)
103-
: data?.versions?.[0]
104-
? `${formatTimestamp(data.versions[0].timestamp, true)} (Siste versjon)`
105-
: 'Laster...'}
122+
{getVersionDisplay()}
106123
</Button>
107124
<VersionSelector
108125
versions={data?.versions || []}
@@ -112,7 +129,7 @@ export const Content = () => {
112129
</div>
113130
</div>
114131
<ContentView
115-
selectedView={selectedView || getDefaultView(isWebpage, hasAttachment) || 'html'}
132+
selectedView={selectedView || getDefaultView(isWebpage, hasAttachment)}
116133
isLoading={isLoading}
117134
data={data}
118135
/>

xp-archive/client/contentTree/contentTreeEntry/NavigationItem.tsx

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { ContentTreeEntryData } from '../../../shared/types';
3-
import { xpArchiveConfig } from '@common/shared/siteConfigs';
43
import { useAppState } from '../../context/appState/useAppState';
54
import { TreeItem } from '@mui/x-tree-view';
65
import { useContentTree } from 'client/hooks/useContentTree';
@@ -13,11 +12,6 @@ type Props = {
1312
export const getContentIconUrl = (type: string) =>
1413
`${import.meta.env.VITE_APP_ORIGIN}/xp/api/contentIcon?type=${type}`;
1514

16-
export const updateContentUrl = (nodeId: string, locale: string, versionId?: string) => {
17-
const newUrl = `${xpArchiveConfig.basePath}/${nodeId}/${locale}/${versionId ?? ''}`;
18-
window.history.pushState({}, '', newUrl);
19-
};
20-
2115
export const NavigationItem = ({ entry }: Props) => {
2216
const { setSelectedContentId } = useAppState();
2317

@@ -39,7 +33,6 @@ export const NavigationItem = ({ entry }: Props) => {
3933
const onClick = () => {
4034
if (!entry.isEmpty) {
4135
setSelectedContentId(entry.id);
42-
updateContentUrl(entry.id, entry.locale);
4336
}
4437
};
4538

xp-archive/client/contentTree/search/SearchResultItem/SearchResultItem.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { BodyShort, Detail } from '@navikt/ds-react';
22
import { classNames } from '@common/client/utils/classNames';
3-
import {
4-
updateContentUrl,
5-
getContentIconUrl,
6-
} from 'client/contentTree/contentTreeEntry/NavigationItem';
3+
import { getContentIconUrl } from 'client/contentTree/contentTreeEntry/NavigationItem';
74
import { useAppState } from 'client/context/appState/useAppState';
85
import { SearchResponse } from 'shared/types';
96

@@ -31,7 +28,6 @@ export const SearchResultItem = ({
3128
onClick={() => {
3229
setSelectedContentId(hit._id);
3330
setSelectedLocale(hit.layerLocale);
34-
updateContentUrl(hit._id, hit.layerLocale);
3531
}}
3632
>
3733
<img

xp-archive/client/contentView/ContentView.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { FilePreviewWrapper } from './filePreview/FilePreviewWrapper';
88

99
import style from './ContentView.module.css';
1010

11-
const getDisplayComponent = (viewVariant: ViewVariant, data?: ContentServiceResponse | null) => {
12-
if (!data) return null;
11+
const getDisplayComponent = (viewVariant?: ViewVariant, data?: ContentServiceResponse | null) => {
12+
if (!data || !viewVariant) return null;
1313
const components: Record<ViewVariant, React.ReactElement> = {
1414
html: (
1515
<HtmlView
@@ -25,7 +25,7 @@ const getDisplayComponent = (viewVariant: ViewVariant, data?: ContentServiceResp
2525
};
2626

2727
type Props = {
28-
selectedView: ViewVariant;
28+
selectedView: ViewVariant | undefined;
2929
isLoading: boolean;
3030
data?: ContentServiceResponse | null;
3131
};

xp-archive/client/contentView/htmlView/HtmlView.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ type Props = {
99
versionId: string;
1010
};
1111

12-
export const HtmlView = ({ nodeId, locale, versionId }: Props) => {
12+
const localesToOverwrite = ['uk', 'ru'];
13+
14+
export const HtmlView = ({ nodeId, locale: langLocale, versionId }: Props) => {
1315
const [isLoading, setIsLoading] = useState(true);
16+
const locale = localesToOverwrite.includes(langLocale) ? 'no' : langLocale;
1417
const htmlPath = `${xpArchiveConfig.basePath}/html/${nodeId}/${locale}/${versionId}`;
1518

1619
return (

xp-archive/client/versionSelector/VersionSelector.module.css

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
:global(.navds-label) {
1313
font-weight: var(--a-font-weight-regular);
14+
text-align: left;
1415
}
1516

1617
:global(.navds-button__icon) {

xp-archive/client/versionSelector/VersionSelector.tsx

+5-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Heading, Button, Search } from '@navikt/ds-react';
33
import { VersionReference } from 'shared/types';
44
import { formatTimestamp } from '@common/shared/timestamp';
55
import { useAppState } from 'client/context/appState/useAppState';
6-
import { updateContentUrl } from 'client/contentTree/contentTreeEntry/NavigationItem';
76
import { SlidePanel } from './SlidePanel/SlidePanel';
87
import { classNames } from '@common/client/utils/classNames';
98
import style from './VersionSelector.module.css';
@@ -35,13 +34,7 @@ const VersionButton = ({ isSelected, onClick, children }: VersionButtonProps) =>
3534

3635
export const VersionSelector = ({ versions, isOpen, onClose }: Props) => {
3736
const [searchQuery, setSearchQuery] = useState('');
38-
const {
39-
selectedContentId,
40-
setSelectedContentId,
41-
selectedVersion,
42-
setSelectedVersion,
43-
selectedLocale,
44-
} = useAppState();
37+
const { setSelectedContentId, selectedVersion, setSelectedVersion } = useAppState();
4538

4639
const handleClose = () => {
4740
setSearchQuery('');
@@ -51,7 +44,6 @@ export const VersionSelector = ({ versions, isOpen, onClose }: Props) => {
5144
const selectVersion = (versionId: string) => {
5245
const nodeId = versions.find((v) => v.versionId === versionId)?.nodeId;
5346
if (nodeId) setSelectedContentId(nodeId);
54-
updateContentUrl(selectedContentId ?? '', selectedLocale, versionId);
5547
setSelectedVersion(versionId);
5648
handleClose();
5749
};
@@ -73,23 +65,16 @@ export const VersionSelector = ({ versions, isOpen, onClose }: Props) => {
7365
className={style.search}
7466
/>
7567
<div className={style.versionList}>
76-
<VersionButton isSelected={!selectedVersion} onClick={() => selectVersion('')}>
77-
{versions[0] ? (
78-
<>
79-
{formatTimestamp(versions[0].timestamp, true)}
80-
<span style={{ fontWeight: 'normal' }}> (Siste versjon)</span>
81-
</>
82-
) : (
83-
'Laster...'
84-
)}
85-
</VersionButton>
86-
{filteredVersions.map((version) => (
68+
{filteredVersions.map((version, index) => (
8769
<VersionButton
8870
key={version.versionId}
8971
isSelected={version.versionId === selectedVersion}
9072
onClick={() => selectVersion(version.versionId)}
9173
>
9274
{formatTimestamp(version.timestamp)}
75+
{index === 0 && (
76+
<span style={{ fontWeight: 'normal' }}> (Siste versjon)</span>
77+
)}
9378
</VersionButton>
9479
))}
9580
</div>

xp-archive/client/viewSelector/ViewSelector.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export const ViewSelector = ({
3838
};
3939

4040
const relevantViewVariants = getRelevantViewVariants(isWebpage, hasAttachment);
41+
if (!relevantViewVariants.length || !selectedView) {
42+
return null;
43+
}
4144

4245
if (relevantViewVariants.length === 0) {
4346
return null;

0 commit comments

Comments
 (0)