@sanity/dashboard 2.30.2-shopify.0 → 3.0.0-studio-v3.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/README.md +123 -44
- package/lib/cjs/index.js +1002 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/esm/index.js +977 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/types/index.d.ts +42 -0
- package/lib/types/index.d.ts.map +1 -0
- package/package.json +53 -14
- package/src/components/DashboardLayout.tsx +10 -0
- package/src/components/DashboardWidgetContainer.tsx +69 -0
- package/src/components/NotFoundWidget.tsx +30 -0
- package/src/components/WidgetGroup.tsx +108 -0
- package/src/containers/Dashboard.tsx +19 -0
- package/src/containers/DashboardContext.tsx +8 -0
- package/src/containers/WidgetContainer.tsx +21 -0
- package/src/index.tsx +62 -0
- package/src/types.ts +21 -0
- package/src/versionedClient.ts +7 -0
- package/src/widgets/projectInfo/ProjectInfo.tsx +233 -0
- package/src/widgets/projectInfo/index.ts +10 -0
- package/src/widgets/projectUsers/ProjectUsers.tsx +171 -0
- package/src/widgets/projectUsers/index.ts +10 -0
- package/src/widgets/sanityTutorials/SanityTutorials.tsx +77 -0
- package/src/widgets/sanityTutorials/Tutorial.tsx +111 -0
- package/src/widgets/sanityTutorials/dataAdapter.ts +48 -0
- package/src/widgets/sanityTutorials/index.ts +10 -0
- package/.babelrc +0 -4
- package/lib/DashboardTool.js +0 -59
- package/lib/components/DashboardLayout.js +0 -35
- package/lib/components/NotFoundWidget.js +0 -51
- package/lib/components/WidgetGroup.js +0 -67
- package/lib/components/dashboardWidget.js +0 -51
- package/lib/containers/Dashboard.js +0 -32
- package/lib/containers/WidgetContainer.js +0 -56
- package/lib/dashboardConfig.js +0 -16
- package/lib/legacyParts.js +0 -55
- package/lib/versionedClient.js +0 -20
- package/lib/widget.css +0 -62
- package/lib/widgets/projectInfo/ProjectInfo.js +0 -265
- package/lib/widgets/projectInfo/index.js +0 -19
- package/lib/widgets/projectUsers/ProjectUsers.js +0 -188
- package/lib/widgets/projectUsers/index.js +0 -16
- package/lib/widgets/sanityTutorials/SanityTutorials.js +0 -115
- package/lib/widgets/sanityTutorials/Tutorial.js +0 -111
- package/lib/widgets/sanityTutorials/dataAdapter.js +0 -28
- package/lib/widgets/sanityTutorials/index.js +0 -19
- package/sanity.json +0 -59
- package/tsconfig.json +0 -17
package/README.md
CHANGED
|
@@ -1,90 +1,134 @@
|
|
|
1
|
-
# Dashboard
|
|
1
|
+
# Sanity Dashboard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **NOTE**
|
|
4
|
+
>
|
|
5
|
+
> This is the **Sanity Studio v3 version** of @sanity/dashboard.
|
|
6
|
+
>
|
|
7
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/dashboard).
|
|
8
|
+
|
|
9
|
+
## What is it?
|
|
10
|
+
|
|
11
|
+
Dashboard is a Sanity Content Studio Tool which renders any widgets configured for it.
|
|
12
|
+
Install this plugin in your Studio to display stats about your project, recently edited documents, etc.
|
|
13
|
+
|
|
14
|
+
The Dashboard tool has been designed to be as generic as possible, making few assumptions about its widgets.
|
|
15
|
+
The Dashboard itself is mostly concerned about the layout of the configured widgets.
|
|
4
16
|
|
|
5
|
-
|
|
17
|
+

|
|
6
18
|
|
|
7
19
|
## Install
|
|
8
20
|
|
|
9
|
-
|
|
10
|
-
- Type `sanity install @sanity/dashboard`. This will cause two things happen:
|
|
11
|
-
1. The Dashboard tool gets installed to `./node_modules` in your Studio
|
|
12
|
-
2. `@sanity/dashboard` is appended to the `plugins` array in the `sanity.json` file of your Studio
|
|
13
|
-
- To verify that all is well, fire up your Studio (`sanity start`) and point your browser to `http://localhost:3333/dashboard`
|
|
14
|
-
- \o/
|
|
21
|
+
In your Sanity Content Studio run:
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
`npm install --save @sanity/dashboard@sanity-v3`
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
or
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
`yarn add @sanity/dashboard@sanity-v3`
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
29
|
+
## Basic usage
|
|
30
|
+
In `sanity.config.js` (or .ts), add the dashboard tool to the createConfig plugins array:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { createConfig } from "sanity";
|
|
34
|
+
import { dashboardTool } from "@sanity/dashboard";
|
|
35
|
+
export default createConfig({
|
|
36
|
+
/* ... */
|
|
37
|
+
plugins: [
|
|
38
|
+
dashboardTool({ widgets: []})
|
|
39
|
+
]
|
|
40
|
+
})
|
|
27
41
|
```
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
To verify that all is well, fire up your Studio (`sanity start`) and point your browser to `http://localhost:3333/dashboard`.
|
|
44
|
+
It should show an empty dashboard, with a message encouraging you to add some widgets to the dashboard.
|
|
30
45
|
|
|
31
|
-
|
|
32
|
-
export default {
|
|
33
|
-
widgets: [{name: 'sanity-tutorials'}, {name: 'project-info'}, {name: 'project-users'}]
|
|
34
|
-
}
|
|
35
|
-
```
|
|
46
|
+
## How to configure the Dashboard
|
|
36
47
|
|
|
37
|
-
|
|
48
|
+
Now, add any widgets you might want. The dashboard plugin provides three widgets out-of-the-box:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { createConfig } from "sanity";
|
|
52
|
+
import {
|
|
53
|
+
dashboardTool,
|
|
54
|
+
sanityTutorialsWidget,
|
|
55
|
+
projectUsersWidget,
|
|
56
|
+
projectInfoWidget,
|
|
57
|
+
} from "@sanity/dashboard";
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// configure the dashboard tool with widgets
|
|
61
|
+
dashboardTool({
|
|
62
|
+
widgets: [
|
|
63
|
+
sanityTutorialsWidget(),
|
|
64
|
+
projectInfoWidget(),
|
|
65
|
+
projectUsersWidget(),
|
|
66
|
+
]
|
|
67
|
+
})
|
|
68
|
+
```
|
|
38
69
|
|
|
39
|
-
|
|
70
|
+
Widgets can be configured by passing widget-specific config:
|
|
40
71
|
|
|
41
|
-
|
|
72
|
+
```ts
|
|
73
|
+
projectUsersWidget({layout: 'medium'})
|
|
74
|
+
```
|
|
42
75
|
|
|
43
76
|
## How to install a widget
|
|
44
77
|
|
|
45
|
-
Install a Dashboard widget as you would any
|
|
78
|
+
Install a Dashboard widget as you would any npm package.
|
|
46
79
|
|
|
47
80
|
E.g. if you want to install the cats example widget mentioned below, proceed as follows:
|
|
48
81
|
|
|
49
|
-
1.
|
|
50
|
-
2. Update your `
|
|
82
|
+
1. Run `yarn install @sanity/sanity-plugin-dashboard-widget-cats` in the studio directory
|
|
83
|
+
2. Update your `sanity.config.js` by importing the widget and adding it to the widget array.
|
|
51
84
|
3. You've got 🐱 in your Studio
|
|
52
85
|
|
|
53
|
-
Some widgets
|
|
86
|
+
Some widgets have widget-specific options to change aspects of their behavior.
|
|
87
|
+
If you install the `@sanity/sanity-plugin-dashboard-widget-document-list` widget mentioned below,
|
|
88
|
+
it can be configured with:
|
|
54
89
|
|
|
55
|
-
```
|
|
56
|
-
{
|
|
90
|
+
```ts
|
|
91
|
+
documentListWidget({
|
|
92
|
+
showCreateButton: true,
|
|
93
|
+
limit: 5,
|
|
94
|
+
types: ["my-document-type"],
|
|
95
|
+
})
|
|
57
96
|
```
|
|
58
97
|
|
|
59
|
-
|
|
98
|
+
You can add multiple instances of a widget with different configuration.
|
|
99
|
+
So, if you want your dashboard to display both newest documents across all document types and
|
|
100
|
+
another widget showing the last edited books, dashboard config could look like this:
|
|
60
101
|
|
|
61
102
|
```js
|
|
62
103
|
export default {
|
|
63
104
|
widgets: [
|
|
64
|
-
{
|
|
65
|
-
{
|
|
66
|
-
name: 'document-list',
|
|
67
|
-
options: {title: 'Last edited books', order: '_updatedAt desc', types: ['book']}
|
|
68
|
-
}
|
|
105
|
+
documentListWidget({title: 'New', order: '_createdAt desc'}),
|
|
106
|
+
documentListWidget({title: 'Last edited books', order: '_updatedAt desc', types: ['book']}),
|
|
69
107
|
]
|
|
70
108
|
}
|
|
71
109
|
```
|
|
72
110
|
|
|
73
111
|
## How to create a widget
|
|
74
112
|
|
|
75
|
-
Widgets are
|
|
113
|
+
Widgets are simply objects that follow implement the [DashboardWidget](src/types.ts) interface.
|
|
114
|
+
Let's have a look at some sample widgets:
|
|
115
|
+
|
|
116
|
+
For example, [a document list](https://github.com/sanity-io/dashboard-widget-document-list/tree/master) or
|
|
117
|
+
[maybe some cats](https://github.com/sanity-io/example-dashboard-widget-cats)?
|
|
76
118
|
|
|
77
|
-
When writing your widget components, it's recommended to use the `
|
|
119
|
+
When writing your widget components, it's recommended to use the `DashboardWidgetContainer` component from
|
|
120
|
+
this package by importing it like so:
|
|
121
|
+
`import { DashboardWidgetContainer } from "@sanity/dashboard";`.
|
|
78
122
|
|
|
79
|
-
This gives you a typical widget component structure with basic styles,
|
|
123
|
+
This gives you a typical widget component structure with basic styles,
|
|
124
|
+
and the option of presenting your content in the header, footer, or body of the widget.
|
|
80
125
|
|
|
81
126
|
If you need something more flexible you can create your own component.
|
|
82
127
|
|
|
83
128
|
Setting up the widget with the default setup will give you a basic widget that looks something like this:
|
|
84
129
|
|
|
85
|
-
|
|
86
130
|
```js
|
|
87
|
-
<
|
|
131
|
+
<DashboardWidgetContainer
|
|
88
132
|
header="A cat"
|
|
89
133
|
footer={
|
|
90
134
|
<Flex direction="column" align="stretch">
|
|
@@ -102,7 +146,7 @@ Setting up the widget with the default setup will give you a basic widget that l
|
|
|
102
146
|
<figure>
|
|
103
147
|
<img src="https://placekitten.com/300/450" />
|
|
104
148
|
</figure>
|
|
105
|
-
</
|
|
149
|
+
</DashboardWidgetContainer>
|
|
106
150
|
```
|
|
107
151
|
|
|
108
152
|
### More examples
|
|
@@ -115,4 +159,39 @@ You can study the source code of these widgets to get a sense of how you can app
|
|
|
115
159
|
|
|
116
160
|
---
|
|
117
161
|
|
|
162
|
+
### Upgrading from v2
|
|
163
|
+
|
|
164
|
+
If you were previously using @sanity/dashboard in a v2 Sanity Studio, will have to make the following changes:
|
|
165
|
+
|
|
166
|
+
* Install the v3 version of @sanity/dashboard in the Studio
|
|
167
|
+
* Install v3 versions of any widgets
|
|
168
|
+
* Configure the dashboard as described above:
|
|
169
|
+
* Add dashboardTool to plugins array
|
|
170
|
+
* Add widgets to widgets configuration
|
|
171
|
+
* Move any config you had in v2 `dashboardConfiguration.js` on a widget-by-widget basis.
|
|
172
|
+
* V2 used an options-object to pass widget-specific configuration. In v3, options have been replaced by
|
|
173
|
+
passing the same configuration directly to the widget-function.
|
|
174
|
+
* Custom widget components should import DashboardWidgetContainer instead of DashboardWidget
|
|
175
|
+
|
|
176
|
+
## Develop & test
|
|
177
|
+
|
|
178
|
+
Make sure to run `npm run build` once, then run
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
npm run link-watch
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
In another shell, `cd` to your test studio and run:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npx yalc add @sanity/dashboard --link && yarn install
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Now, changes in this repo will be automatically built and pushed to the studio,
|
|
191
|
+
triggering hotreload. Yalc avoids issues with react-hooks that are typical when using yarn/npm link.
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
### About build & watch
|
|
118
195
|
|
|
196
|
+
This plugin uses [@sanity/plugin-sdk](https://github.com/sanity-io/plugin-sdk)
|
|
197
|
+
with default configuration for build & watch scripts.
|