Skip to content

Commit dc987d0

Browse files
feat(ui) Add ability to edit global template on homepage
1 parent be645ea commit dc987d0

File tree

7 files changed

+171
-0
lines changed

7 files changed

+171
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { BADGE } from '@geometricpanda/storybook-addon-badges';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import React from 'react';
4+
import styled from 'styled-components';
5+
6+
import { ActionsBar, ActionsBarProps } from '@components/components/ActionsBar/ActionsBar';
7+
import { Button } from '@components/components/Button';
8+
import { Drawer } from '@components/components/Drawer/Drawer';
9+
import { Icon } from '@components/components/Icon';
10+
import colors from '@components/theme/foundations/colors';
11+
12+
// Auto Docs
13+
const meta = {
14+
title: 'Components / ActionsBar',
15+
component: ActionsBar,
16+
17+
// Display Properties
18+
parameters: {
19+
layout: 'centered',
20+
badges: [BADGE.EXPERIMENTAL],
21+
docs: {
22+
subtitle: 'A floating actions bar on the bottom of the screen that renders its children inside.',
23+
},
24+
},
25+
26+
// Component-level argTypes
27+
argTypes: {},
28+
29+
// Define default args
30+
args: {},
31+
} satisfies Meta<typeof Drawer>;
32+
33+
export default meta;
34+
35+
// Stories
36+
37+
type Story = StoryObj<typeof meta>;
38+
39+
const Warning = styled.div`
40+
padding: 8pxs
41+
background-color: ${colors.red[0]};
42+
color: ${colors.red[1000]};
43+
display: flex;
44+
align-items: center;
45+
gap: 8px;
46+
font-weight: 600;
47+
font-size: 14px;
48+
border-radius: 8px;
49+
`;
50+
51+
const Wrapper = styled.div`
52+
min-width: 600px;
53+
height: 50px;
54+
`;
55+
56+
const WrappedActionsBar = ({ ...props }: ActionsBarProps) => {
57+
return (
58+
<Wrapper>
59+
<ActionsBar {...props}>
60+
<Warning>
61+
<Icon icon="ExclamationMark" color="red" weight="fill" source="phosphor" />
62+
<span>Editing default user view</span>
63+
</Warning>
64+
<Button>Done</Button>
65+
</ActionsBar>
66+
</Wrapper>
67+
);
68+
};
69+
// Basic story is what is displayed 1st in storybook
70+
// Pass props to this so that it can be customized via the UI props panel
71+
export const sandbox: Story = {
72+
tags: ['dev'],
73+
render: () => <WrappedActionsBar />,
74+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
const ActionsContainer = styled.div`
5+
display: flex;
6+
padding: 4px;
7+
justify-content: center;
8+
align-items: center;
9+
gap: 8px;
10+
width: fit-content;
11+
align-self: center;
12+
border-radius: 12px;
13+
box-shadow: 0px 4px 12px 0px rgba(9, 1, 61, 0.12);
14+
15+
background-color: white;
16+
position: absolute;
17+
left: 50%;
18+
bottom: 2px;
19+
transform: translateX(-55%);
20+
`;
21+
22+
export type ActionsBarProps = {};
23+
24+
export const ActionsBar = ({ children }: React.PropsWithChildren<ActionsBarProps>) => {
25+
return <ActionsContainer>{children}</ActionsContainer>;
26+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ActionsBar } from './ActionsBar';

datahub-web-react/src/alchemy-components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export * from './theme';
33

44
// example usage: import { Button } from '@components';
5+
export * from './components/ActionsBar';
56
export * from './components/AutoComplete';
67
export * from './components/Avatar';
78
export * from './components/Badge';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Button, Icon, Tooltip, colors } from '@components';
2+
import React from 'react';
3+
import styled from 'styled-components';
4+
5+
import { ActionsBar } from '@components/components/ActionsBar/ActionsBar';
6+
7+
import { usePageTemplateContext } from '@app/homeV3/context/PageTemplateContext';
8+
9+
const Warning = styled.div`
10+
padding: 8px;
11+
background-color: ${colors.red[0]};
12+
color: ${colors.red[1000]};
13+
display: flex;
14+
align-items: center;
15+
gap: 8px;
16+
font-weight: 600;
17+
font-size: 14px;
18+
border-radius: 8px;
19+
`;
20+
21+
export default function EditDefaultTemplateBar() {
22+
const { setIsEditingGlobalTemplate, isEditingGlobalTemplate } = usePageTemplateContext();
23+
24+
// TODO: also hide this if you don't have permissions - CH-510
25+
if (!isEditingGlobalTemplate) return null;
26+
27+
return (
28+
<ActionsBar>
29+
<Warning>
30+
<Icon icon="ExclamationMark" color="red" weight="fill" source="phosphor" />
31+
<span>Editing default user view</span>
32+
</Warning>
33+
<Button onClick={() => setIsEditingGlobalTemplate(false)}>Done</Button>
34+
</ActionsBar>
35+
);
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Button, Tooltip } from '@components';
2+
import React from 'react';
3+
import styled from 'styled-components';
4+
5+
import { usePageTemplateContext } from '@app/homeV3/context/PageTemplateContext';
6+
7+
const ButtonWrapper = styled.div`
8+
display: flex;
9+
justify-content: flex-end;
10+
`;
11+
12+
export default function EditDefaultTemplateButton() {
13+
const { setIsEditingGlobalTemplate, isEditingGlobalTemplate } = usePageTemplateContext();
14+
15+
// TODO: also hide this if you don't have permissions - CH-510
16+
if (isEditingGlobalTemplate) return null;
17+
18+
return (
19+
<ButtonWrapper>
20+
<Tooltip title="Edit the home page that users see by default">
21+
<Button
22+
icon={{ icon: 'PencilSimpleLine', color: 'gray', source: 'phosphor' }}
23+
variant="text"
24+
onClick={() => setIsEditingGlobalTemplate(true)}
25+
/>
26+
</Tooltip>
27+
</ButtonWrapper>
28+
);
29+
}

datahub-web-react/src/app/homeV3/HomePageContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React from 'react';
22

33
import { useGlobalSettings } from '@app/context/GlobalSettingsContext';
44
import { useUserContext } from '@app/context/useUserContext';
5+
import EditDefaultTemplateBar from '@app/homeV3/EditDefaultTemplateBar';
6+
import EditDefaultTemplateButton from '@app/homeV3/EditDefaultTemplateButton';
57
import { Announcements } from '@app/homeV3/announcements/Announcements';
68
import { PageTemplateProvider } from '@app/homeV3/context/PageTemplateContext';
79
import { CenteredContainer, ContentContainer, ContentDiv } from '@app/homeV3/styledComponents';
@@ -21,8 +23,10 @@ const HomePageContent = () => {
2123
<ContentContainer>
2224
<CenteredContainer>
2325
<ContentDiv>
26+
<EditDefaultTemplateButton />
2427
<Announcements />
2528
<Template />
29+
<EditDefaultTemplateBar />
2630
</ContentDiv>
2731
</CenteredContainer>
2832
</ContentContainer>

0 commit comments

Comments
 (0)