Skip to content

Commit 2a2afb8

Browse files
fridajacFrida Englund
andauthored
Improve full view functionality in ReadmeCard (#298)
* Update full view icon and title in ReadmeCard * feat: Handle full view though URL params --------- Co-authored-by: Frida Englund <fridaja@axis.com>
1 parent 818c231 commit 2a2afb8

5 files changed

Lines changed: 39 additions & 12 deletions

File tree

.changeset/silly-rooms-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@axis-backstage/plugin-readme': minor
3+
---
4+
5+
Add URL state management and update fullscreen icon
7.95 KB
Loading

plugins/readme/media/readme.png

-22.6 KB
Binary file not shown.

plugins/readme/src/components/ReadmeCard/ReadmeCard.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
import { useState } from 'react';
21
import IconButton from '@mui/material/IconButton';
32
import Box from '@mui/material/Box';
3+
import FullscreenIcon from '@mui/icons-material/Fullscreen';
44
import { InfoCard, InfoCardVariants } from '@backstage/core-components';
55
import { FetchComponent } from '../FetchComponent';
6-
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
76
import { ReadmeDialog } from '../ReadmeDialog/ReadmeDialog';
7+
import { useFullViewParam } from '../../hooks/useFullViewParam';
88

99
/**
1010
* ReadmeCardProps props.
1111
*
1212
* @public
1313
*/
14-
1514
export type ReadmeCardProps = {
1615
variant?: InfoCardVariants;
1716
maxHeight?: string | number;
1817
};
1918

2019
export const ReadmeCard = (props: ReadmeCardProps) => {
2120
const { variant = 'gridItem', maxHeight: propMaxHeight } = props;
21+
const [isFullViewOpen, setIsFullViewOpen] = useFullViewParam();
22+
2223
const maxHeight =
2324
variant === 'fullHeight' ? 'none' : propMaxHeight ?? '235px';
2425

25-
const [displayDialog, setDisplayDialog] = useState(false);
26-
2726
return (
2827
<>
2928
<InfoCard
@@ -32,13 +31,12 @@ export const ReadmeCard = (props: ReadmeCardProps) => {
3231
action={
3332
variant !== 'fullHeight' ? (
3433
<IconButton
35-
onClick={() => setDisplayDialog(true)}
36-
aria-label="open dialog"
37-
role="button"
38-
title="Open in dialog"
34+
onClick={() => setIsFullViewOpen(true)}
35+
aria-label="Open full view"
36+
title="Open full view"
3937
size="large"
4038
>
41-
<OpenInNewIcon />
39+
<FullscreenIcon />
4240
</IconButton>
4341
) : undefined
4442
}
@@ -51,8 +49,8 @@ export const ReadmeCard = (props: ReadmeCardProps) => {
5149
</InfoCard>
5250

5351
<ReadmeDialog
54-
open={displayDialog}
55-
onClose={() => setDisplayDialog(false)}
52+
open={isFullViewOpen}
53+
onClose={() => setIsFullViewOpen(false)}
5654
/>
5755
</>
5856
);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useLocation, useNavigate } from 'react-router-dom';
2+
import { useMemo } from 'react';
3+
4+
export const useFullViewParam = (): [boolean, (open: boolean) => void] => {
5+
const location = useLocation();
6+
const navigate = useNavigate();
7+
8+
const isFullView = useMemo(() => {
9+
const params = new URLSearchParams(location.search);
10+
return params.get('fullView') === 'true';
11+
}, [location.search]);
12+
13+
const setFullView = (open: boolean) => {
14+
const params = new URLSearchParams(location.search);
15+
if (open) {
16+
params.set('fullView', 'true');
17+
} else {
18+
params.delete('fullView');
19+
}
20+
navigate({ search: params.toString() }, { replace: true });
21+
};
22+
23+
return [isFullView, setFullView];
24+
};

0 commit comments

Comments
 (0)