Skip to content

Commit adbf54f

Browse files
author
Frida Englund
committed
feat: Handle full view though URL params
1 parent 7860f32 commit adbf54f

5 files changed

Lines changed: 37 additions & 9 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: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
22
import IconButton from '@mui/material/IconButton';
33
import Box from '@mui/material/Box';
4+
import FullscreenIcon from '@mui/icons-material/Fullscreen';
45
import { InfoCard, InfoCardVariants } from '@backstage/core-components';
56
import { FetchComponent } from '../FetchComponent';
6-
import FullscreenIcon from '@mui/icons-material/Fullscreen';
77
import { ReadmeDialog } from '../ReadmeDialog/ReadmeDialog';
8+
import { useFullViewParam } from '../../hooks/useFullViewParam';
89

910
/**
1011
* ReadmeCardProps props.
1112
*
1213
* @public
1314
*/
14-
1515
export type ReadmeCardProps = {
1616
variant?: InfoCardVariants;
1717
maxHeight?: string | number;
1818
};
1919

2020
export const ReadmeCard = (props: ReadmeCardProps) => {
2121
const { variant = 'gridItem', maxHeight: propMaxHeight } = props;
22+
const [isFullViewOpen, setIsFullViewOpen] = useFullViewParam();
23+
2224
const maxHeight =
2325
variant === 'fullHeight' ? 'none' : propMaxHeight ?? '235px';
2426

25-
const [displayDialog, setDisplayDialog] = useState(false);
26-
2727
return (
2828
<>
2929
<InfoCard
@@ -32,9 +32,8 @@ export const ReadmeCard = (props: ReadmeCardProps) => {
3232
action={
3333
variant !== 'fullHeight' ? (
3434
<IconButton
35-
onClick={() => setDisplayDialog(true)}
35+
onClick={() => setIsFullViewOpen(true)}
3636
aria-label="Open full view"
37-
role="button"
3837
title="Open full view"
3938
size="large"
4039
>
@@ -51,8 +50,8 @@ export const ReadmeCard = (props: ReadmeCardProps) => {
5150
</InfoCard>
5251

5352
<ReadmeDialog
54-
open={displayDialog}
55-
onClose={() => setDisplayDialog(false)}
53+
open={isFullViewOpen}
54+
onClose={() => setIsFullViewOpen(false)}
5655
/>
5756
</>
5857
);
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)