Skip to content

Commit 81b6149

Browse files
author
Herman Wikner
authoredJul 14, 2021
refactor(dashboard): migrate to @sanity/ui (#2590)
* refactor(dashboard): migrate `DashboardLayout` to `@sanity/ui` * refactor(dashboard): add `DashboardWidget` component * refactor(dashboard): export parts from `legacyParts` file * refactor(dashboard): migrate `sanityTutorials` widget to `@sanity/ui` * refactor(dashboard): migrate `NotFoundWidget` to `@sanity/ui` * refactor(dashboard): migrate `WidgetGroup` to `@sanity/ui` * refactor(dashboard): migrate `ProjectUsers` to `@sanity/ui` * refactor(dashboard): migrate `ProjectInfo` to `@sanity/ui` * refactor(dashboard): add `@babel/typescript` to `.babelrc` * chore(dashboard): update dependencies in package.json * refactor(dashboard): remove storybook story * refactor(dashboard): update `Dashboard` parts import * refactor(dashboard): update `WidgetContainer` parts import * refactor(dashboard): update `versionedClient` parts import
1 parent f776a56 commit 81b6149

24 files changed

+471
-617
lines changed
 

‎packages/@sanity/dashboard/.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"extends": "../../../.babelrc",
3-
"presets": ["@babel/react"]
3+
"presets": ["@babel/react", "@babel/typescript"]
44
}

‎packages/@sanity/dashboard/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
"sanity-tool"
2020
],
2121
"dependencies": {
22+
"@sanity/icons": "1.1.2",
2223
"@sanity/image-url": "^0.140.19",
24+
"@sanity/ui": "0.34.4",
2325
"lodash": "^4.17.15",
24-
"rxjs": "^6.5.3"
26+
"rxjs": "^6.5.3",
27+
"styled-components": "^5.2.1"
2528
},
2629
"devDependencies": {
2730
"prop-types": "^15.6.0",

‎packages/@sanity/dashboard/src/DashboardTool.js

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const DashboardIcon = () => (
2222
</svg>
2323
)
2424

25+
export * from './components/dashboardWidget'
26+
2527
export default {
2628
title: 'Dashboard',
2729
name: 'dashboard',

‎packages/@sanity/dashboard/src/components/DashboardLayout.css

-13
This file was deleted.

‎packages/@sanity/dashboard/src/components/DashboardLayout.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
3-
4-
import styles from './DashboardLayout.css'
3+
import {Container} from '@sanity/ui'
54

65
function DashboardLayout(props) {
76
return (
8-
<div className={styles.root}>
9-
<div className={styles.inner}>{props.children}</div>
10-
</div>
7+
<Container width={4} padding={4} sizing="border" style={{minHeight: '100%'}}>
8+
{props.children}
9+
</Container>
1110
)
1211
}
1312

‎packages/@sanity/dashboard/src/components/NotFoundWidget.css

-22
This file was deleted.

‎packages/@sanity/dashboard/src/components/NotFoundWidget.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
3+
import {Card, Stack, Heading, Box} from '@sanity/ui'
4+
import styled from 'styled-components'
35

4-
import styles from './NotFoundWidget.css'
6+
const Root = styled(Card)`
7+
display: flex;
8+
flex-direction: column;
9+
justify-content: stretch;
10+
height: 100%;
11+
`
512

613
function NotFoundWidget(props) {
14+
const {title, children} = props
715
return (
8-
<div className={styles.root}>
9-
<div>
10-
{props.title && <h2 className={styles.title}>{props.title}</h2>}
11-
<div className={styles.content}>{props.children}</div>
12-
</div>
13-
</div>
16+
<Root radius={3} paddingX={3} paddingY={4} tone="critical">
17+
<Stack space={2}>
18+
{title && (
19+
<Heading size={1} as="h2">
20+
{title}
21+
</Heading>
22+
)}
23+
{children && <Box>{children}</Box>}
24+
</Stack>
25+
</Root>
1426
)
1527
}
1628

‎packages/@sanity/dashboard/src/components/WidgetGroup.css

-59
This file was deleted.

‎packages/@sanity/dashboard/src/components/WidgetGroup.js

+74-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,87 @@
11
/* eslint-disable react/prop-types */
2-
32
import React from 'react'
4-
import WidgetContainer from 'part:@sanity/dashboard/widget-container'
3+
import styled, {css} from 'styled-components'
4+
import {Grid} from '@sanity/ui'
5+
import {WidgetContainer} from '../legacyParts'
6+
7+
const media = {
8+
small: (...args) =>
9+
css`
10+
@media (min-width: ${({theme}) => theme.sanity.media[0]}px) {
11+
${css(...args)}
12+
}
13+
`,
14+
medium: (...args) =>
15+
css`
16+
@media (min-width: ${({theme}) => theme.sanity.media[2]}px) {
17+
${css(...args)}
18+
}
19+
`,
20+
}
21+
22+
const Root = styled(Grid)`
23+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
24+
25+
& > div {
26+
overflow: hidden;
27+
}
28+
29+
& > div[data-width='medium'] {
30+
${media.small`
31+
grid-column: span 2;
32+
`}
33+
}
34+
35+
& > div[data-width='large'] {
36+
${media.small`
37+
grid-column: span 2;
38+
`}
539
6-
import styles from './WidgetGroup.css'
40+
${media.medium`
41+
grid-column: span 3;
42+
`}
43+
}
44+
45+
& > div[data-width='full'] {
46+
${media.small`
47+
grid-column: 1 / -1;
48+
`}
49+
}
50+
51+
& > div[data-height='medium'] {
52+
${media.small`
53+
grid-row: span 2;
54+
`}
55+
}
56+
57+
& > div[data-height='large'] {
58+
${media.small`
59+
grid-row: span 2;
60+
`}
61+
62+
${media.medium`
63+
grid-row: span 3;
64+
`}
65+
}
66+
67+
& > div[data-height='full'] {
68+
${media.medium`
69+
grid-row: 1 / -1;
70+
`}
71+
}
72+
`
773

874
function WidgetGroup(props) {
975
const config = props.config || {}
1076
const widgets = config.widgets || []
1177
const layout = config.layout || {}
78+
1279
return (
13-
<div
14-
className={styles.root}
80+
<Root
81+
autoFlow="dense"
1582
data-width={layout.width || 'auto'}
1683
data-height={layout.height || 'auto'}
84+
gap={4}
1785
>
1886
{widgets.map((widgetConfig, index) => {
1987
if (widgetConfig.type === '__experimental_group') {
@@ -22,7 +90,7 @@ function WidgetGroup(props) {
2290

2391
return <WidgetContainer key={String(index)} config={widgetConfig} />
2492
})}
25-
</div>
93+
</Root>
2694
)
2795
}
2896

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, {forwardRef} from 'react'
2+
import {Card, Box, Heading} from '@sanity/ui'
3+
import styled from 'styled-components'
4+
5+
const Root = styled(Card)`
6+
display: flex;
7+
flex-direction: column;
8+
justify-content: stretch;
9+
height: 100%;
10+
box-sizing: border-box;
11+
position: relative;
12+
`
13+
14+
const Header = styled(Card)`
15+
position: sticky;
16+
top: 0;
17+
z-index: 2;
18+
border-top-left-radius: inherit;
19+
border-top-right-radius: inherit;
20+
`
21+
22+
const Footer = styled(Card)`
23+
position: sticky;
24+
overflow: hidden;
25+
bottom: 0;
26+
z-index: 2;
27+
border-bottom-right-radius: inherit;
28+
border-bottom-left-radius: inherit;
29+
margin-top: auto;
30+
`
31+
32+
const Content = styled(Box)`
33+
position: relative;
34+
z-index: 1;
35+
height: stretch;
36+
min-height: 21.5em;
37+
38+
@media (min-width: ${({theme}) => theme.sanity.media[0]}px) {
39+
overflow-y: auto;
40+
outline: none;
41+
}
42+
`
43+
44+
interface DashboardWidgetProps {
45+
header?: string
46+
children: React.ReactNode
47+
footer?: React.ReactNode
48+
}
49+
50+
export const DashboardWidget = forwardRef(
51+
(props: DashboardWidgetProps, ref: React.Ref<HTMLDivElement>) => {
52+
const {header, children, footer} = props
53+
54+
return (
55+
<Root radius={3} display="flex" ref={ref}>
56+
{header && (
57+
<Header borderBottom paddingX={3} paddingY={4}>
58+
<Heading size={1} textOverflow="ellipsis">
59+
{header}
60+
</Heading>
61+
</Header>
62+
)}
63+
{children && <Content>{children}</Content>}
64+
{footer && <Footer borderTop>{footer}</Footer>}
65+
</Root>
66+
)
67+
}
68+
)
69+
70+
DashboardWidget.displayName = 'DashboardWidget'

2 commit comments

Comments
 (2)

vercel[bot] commented on Jul 14, 2021

@vercel[bot]

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

vercel[bot] commented on Jul 14, 2021

@vercel[bot]

Successfully deployed to the following URLs:

perf-studio – ./

perf-studio.sanity.build
perf-studio-git-next.sanity.build

Please sign in to comment.