@sanity/dashboard 3.1.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +42 -55
- package/lib/index.d.mts +65 -0
- package/lib/index.esm.js +466 -635
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +455 -644
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +584 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +37 -36
- package/src/components/DashboardWidgetContainer.tsx +2 -2
- package/src/components/NotFoundWidget.tsx +1 -1
- package/src/components/WidgetGroup.tsx +11 -13
- package/src/containers/WidgetContainer.tsx +1 -1
- package/src/versionedClient.ts +1 -1
- package/src/widgets/projectInfo/ProjectInfo.tsx +16 -6
- package/src/widgets/projectUsers/ProjectUser.tsx +45 -0
- package/src/widgets/projectUsers/ProjectUsers.tsx +28 -49
- package/src/widgets/sanityTutorials/Tutorial.tsx +1 -1
- package/src/widgets/sanityTutorials/dataAdapter.ts +2 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
Sanity Dashboard
|
|
2
2
|
|
|
3
3
|
> This is a **Sanity Studio v3** plugin.
|
|
4
4
|
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/dashboard/tree/studio-v2).
|
|
5
5
|
|
|
6
6
|
## What is it?
|
|
7
7
|
|
|
8
|
-
Dashboard is a Sanity Content Studio Tool which renders any widgets configured for it.
|
|
8
|
+
Dashboard is a Sanity Content Studio Tool which renders any widgets configured for it.
|
|
9
9
|
Install this plugin in your Studio to display stats about your project, recently edited documents, etc.
|
|
10
10
|
|
|
11
|
-
The Dashboard tool has been designed to be as generic as possible, making few assumptions about its widgets.
|
|
11
|
+
The Dashboard tool has been designed to be as generic as possible, making few assumptions about its widgets.
|
|
12
12
|
The Dashboard itself is mostly concerned about the layout of the configured widgets.
|
|
13
13
|
|
|
14
14
|

|
|
@@ -24,16 +24,15 @@ or
|
|
|
24
24
|
`yarn add @sanity/dashboard`
|
|
25
25
|
|
|
26
26
|
## Basic usage
|
|
27
|
+
|
|
27
28
|
In `sanity.config.js` (or .ts), add the dashboard tool to the defineConfig plugins array:
|
|
28
29
|
|
|
29
30
|
```ts
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
31
|
+
import {defineConfig} from 'sanity'
|
|
32
|
+
import {dashboardTool} from '@sanity/dashboard'
|
|
32
33
|
export default defineConfig({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
dashboardTool({ widgets: []})
|
|
36
|
-
]
|
|
34
|
+
/* ... */
|
|
35
|
+
plugins: [dashboardTool({widgets: []})],
|
|
37
36
|
})
|
|
38
37
|
```
|
|
39
38
|
|
|
@@ -45,22 +44,17 @@ It should show an empty dashboard, with a message encouraging you to add some wi
|
|
|
45
44
|
Now, add any widgets you might want. The dashboard plugin provides three widgets out-of-the-box:
|
|
46
45
|
|
|
47
46
|
```ts
|
|
48
|
-
import {
|
|
47
|
+
import {defineConfig} from 'sanity'
|
|
49
48
|
import {
|
|
50
49
|
dashboardTool,
|
|
51
50
|
sanityTutorialsWidget,
|
|
52
51
|
projectUsersWidget,
|
|
53
52
|
projectInfoWidget,
|
|
54
|
-
} from
|
|
55
|
-
|
|
53
|
+
} from '@sanity/dashboard'
|
|
56
54
|
|
|
57
55
|
// configure the dashboard tool with widgets
|
|
58
|
-
dashboardTool({
|
|
59
|
-
widgets: [
|
|
60
|
-
sanityTutorialsWidget(),
|
|
61
|
-
projectInfoWidget(),
|
|
62
|
-
projectUsersWidget(),
|
|
63
|
-
]
|
|
56
|
+
dashboardTool({
|
|
57
|
+
widgets: [sanityTutorialsWidget(), projectInfoWidget(), projectUsersWidget()],
|
|
64
58
|
})
|
|
65
59
|
```
|
|
66
60
|
|
|
@@ -73,15 +67,17 @@ projectUsersWidget({layout: 'medium'})
|
|
|
73
67
|
You can change the name, title and icon of the dashboard tool should you want to - which also allows you to configure multiple dashboards with different configurations:
|
|
74
68
|
|
|
75
69
|
```ts
|
|
76
|
-
import {
|
|
77
|
-
import {
|
|
78
|
-
import {
|
|
70
|
+
import {defineConfig} from 'sanity'
|
|
71
|
+
import {dashboardTool} from '@sanity/dashboard'
|
|
72
|
+
import {ActivityIcon} from '@sanity/icons'
|
|
79
73
|
|
|
80
|
-
dashboardTool({
|
|
81
|
-
name:
|
|
82
|
-
title:
|
|
74
|
+
dashboardTool({
|
|
75
|
+
name: 'stats',
|
|
76
|
+
title: 'Statistics',
|
|
83
77
|
icon: ActivityIcon,
|
|
84
|
-
widgets: [
|
|
78
|
+
widgets: [
|
|
79
|
+
/* ... */
|
|
80
|
+
],
|
|
85
81
|
})
|
|
86
82
|
```
|
|
87
83
|
|
|
@@ -95,20 +91,20 @@ E.g. if you want to install the cats example widget mentioned below, proceed as
|
|
|
95
91
|
2. Update your `sanity.config.js` by importing the widget and adding it to the widget array.
|
|
96
92
|
3. You've got 🐱 in your Studio
|
|
97
93
|
|
|
98
|
-
Some widgets have widget-specific options to change aspects of their behavior.
|
|
99
|
-
If you install the `@sanity/sanity-plugin-dashboard-widget-document-list` widget mentioned below,
|
|
94
|
+
Some widgets have widget-specific options to change aspects of their behavior.
|
|
95
|
+
If you install the `@sanity/sanity-plugin-dashboard-widget-document-list` widget mentioned below,
|
|
100
96
|
it can be configured with:
|
|
101
97
|
|
|
102
98
|
```ts
|
|
103
99
|
documentListWidget({
|
|
104
100
|
showCreateButton: true,
|
|
105
101
|
limit: 5,
|
|
106
|
-
types: [
|
|
102
|
+
types: ['my-document-type'],
|
|
107
103
|
})
|
|
108
104
|
```
|
|
109
105
|
|
|
110
106
|
You can add multiple instances of a widget with different configuration.
|
|
111
|
-
So, if you want your dashboard to display both newest documents across all document types and
|
|
107
|
+
So, if you want your dashboard to display both newest documents across all document types and
|
|
112
108
|
another widget showing the last edited books, dashboard config could look like this:
|
|
113
109
|
|
|
114
110
|
```js
|
|
@@ -116,23 +112,23 @@ export default {
|
|
|
116
112
|
widgets: [
|
|
117
113
|
documentListWidget({title: 'New', order: '_createdAt desc'}),
|
|
118
114
|
documentListWidget({title: 'Last edited books', order: '_updatedAt desc', types: ['book']}),
|
|
119
|
-
]
|
|
115
|
+
],
|
|
120
116
|
}
|
|
121
117
|
```
|
|
122
118
|
|
|
123
119
|
## How to create a widget
|
|
124
120
|
|
|
125
|
-
Widgets are simply objects that follow implement the [DashboardWidget](src/types.ts) interface.
|
|
126
|
-
Let's have a look at some sample widgets:
|
|
121
|
+
Widgets are simply objects that follow implement the [DashboardWidget](src/types.ts) interface.
|
|
122
|
+
Let's have a look at some sample widgets:
|
|
127
123
|
|
|
128
|
-
For example, [a document list](https://github.com/sanity-io/dashboard-widget-document-list/tree/master) or
|
|
124
|
+
For example, [a document list](https://github.com/sanity-io/dashboard-widget-document-list/tree/master) or
|
|
129
125
|
[maybe some cats](https://github.com/sanity-io/example-dashboard-widget-cats)?
|
|
130
126
|
|
|
131
|
-
When writing your widget components, it's recommended to use the `DashboardWidgetContainer` component from
|
|
132
|
-
this package by importing it like so:
|
|
127
|
+
When writing your widget components, it's recommended to use the `DashboardWidgetContainer` component from
|
|
128
|
+
this package by importing it like so:
|
|
133
129
|
`import { DashboardWidgetContainer } from "@sanity/dashboard";`.
|
|
134
130
|
|
|
135
|
-
This gives you a typical widget component structure with basic styles,
|
|
131
|
+
This gives you a typical widget component structure with basic styles,
|
|
136
132
|
and the option of presenting your content in the header, footer, or body of the widget.
|
|
137
133
|
|
|
138
134
|
If you need something more flexible you can create your own component.
|
|
@@ -144,14 +140,7 @@ Setting up the widget with the default setup will give you a basic widget that l
|
|
|
144
140
|
header="A cat"
|
|
145
141
|
footer={
|
|
146
142
|
<Flex direction="column" align="stretch">
|
|
147
|
-
<Button
|
|
148
|
-
flex={1}
|
|
149
|
-
paddingX={2}
|
|
150
|
-
paddingY={4}
|
|
151
|
-
mode="bleed"
|
|
152
|
-
tone="primary"
|
|
153
|
-
text="Get new cat"
|
|
154
|
-
/>
|
|
143
|
+
<Button flex={1} paddingX={2} paddingY={4} mode="bleed" tone="primary" text="Get new cat" />
|
|
155
144
|
</Flex>
|
|
156
145
|
}
|
|
157
146
|
>
|
|
@@ -175,15 +164,15 @@ You can study the source code of these widgets to get a sense of how you can app
|
|
|
175
164
|
|
|
176
165
|
If you were previously using @sanity/dashboard in a v2 Sanity Studio, will have to make the following changes:
|
|
177
166
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
167
|
+
- Install the v3 version of @sanity/dashboard in the Studio
|
|
168
|
+
- Install v3 versions of any widgets
|
|
169
|
+
- Configure the dashboard as described above:
|
|
170
|
+
- Add dashboardTool to plugins array
|
|
171
|
+
- Add widgets to widgets configuration
|
|
172
|
+
- Move any config you had in v2 `dashboardConfiguration.js` on a widget-by-widget basis.
|
|
173
|
+
- V2 used an options-object to pass widget-specific configuration. In v3, options have been replaced by
|
|
174
|
+
passing the same configuration directly to the widget-function.
|
|
175
|
+
- Custom widget components should import DashboardWidgetContainer instead of DashboardWidget
|
|
187
176
|
|
|
188
177
|
## Develop & test
|
|
189
178
|
|
|
@@ -200,8 +189,6 @@ Make sure to select the main branch and check "Release new version".
|
|
|
200
189
|
|
|
201
190
|
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
202
191
|
|
|
203
|
-
|
|
204
|
-
|
|
205
192
|
## License
|
|
206
193
|
|
|
207
194
|
MIT-licensed. See LICENSE.
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {ComponentClass} from 'react'
|
|
2
|
+
import {ComponentType} from 'react'
|
|
3
|
+
import {FunctionComponent} from 'react'
|
|
4
|
+
import {Plugin as Plugin_2} from 'sanity'
|
|
5
|
+
import {default as React_2} from 'react'
|
|
6
|
+
|
|
7
|
+
export declare interface DashboardConfig {
|
|
8
|
+
widgets: DashboardWidget[]
|
|
9
|
+
layout?: LayoutConfig
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare interface DashboardPluginConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Dashboard tool title
|
|
15
|
+
*/
|
|
16
|
+
title?: string
|
|
17
|
+
/**
|
|
18
|
+
* Dashboard tool name (used in url path)
|
|
19
|
+
*/
|
|
20
|
+
name?: string
|
|
21
|
+
/**
|
|
22
|
+
* Dashboard tool icon
|
|
23
|
+
*/
|
|
24
|
+
icon?: ComponentType
|
|
25
|
+
widgets?: DashboardWidget[]
|
|
26
|
+
/**
|
|
27
|
+
* Will be used for widgets that do not define a layout directly.
|
|
28
|
+
*/
|
|
29
|
+
defaultLayout?: LayoutConfig
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export declare const dashboardTool: Plugin_2<DashboardPluginConfig>
|
|
33
|
+
|
|
34
|
+
export declare interface DashboardWidget {
|
|
35
|
+
name: string
|
|
36
|
+
type?: '__experimental_group'
|
|
37
|
+
component: FunctionComponent<any> | ComponentClass<any>
|
|
38
|
+
layout?: LayoutConfig
|
|
39
|
+
widgets?: DashboardWidget[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare const DashboardWidgetContainer: React_2.ForwardRefExoticComponent<
|
|
43
|
+
DashboardWidgetProps & React_2.RefAttributes<HTMLDivElement>
|
|
44
|
+
>
|
|
45
|
+
|
|
46
|
+
declare interface DashboardWidgetProps {
|
|
47
|
+
header?: string
|
|
48
|
+
children: React_2.ReactNode
|
|
49
|
+
footer?: React_2.ReactNode
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export declare interface LayoutConfig {
|
|
53
|
+
width?: LayoutSize
|
|
54
|
+
height?: LayoutSize
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export declare type LayoutSize = 'auto' | 'small' | 'medium' | 'large' | 'full'
|
|
58
|
+
|
|
59
|
+
export declare function projectInfoWidget(config?: {layout?: LayoutConfig}): DashboardWidget
|
|
60
|
+
|
|
61
|
+
export declare function projectUsersWidget(config?: {layout?: LayoutConfig}): DashboardWidget
|
|
62
|
+
|
|
63
|
+
export declare function sanityTutorialsWidget(config?: {layout?: LayoutConfig}): DashboardWidget
|
|
64
|
+
|
|
65
|
+
export {}
|