@sanity/dashboard 2.30.2-shopify.2 → 3.0.0-sanity-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.
Files changed (48) hide show
  1. package/README.md +123 -44
  2. package/lib/cjs/index.js +1002 -0
  3. package/lib/cjs/index.js.map +1 -0
  4. package/lib/esm/index.js +977 -0
  5. package/lib/esm/index.js.map +1 -0
  6. package/lib/types/index.d.ts +42 -0
  7. package/lib/types/index.d.ts.map +1 -0
  8. package/package.json +53 -14
  9. package/src/components/DashboardLayout.tsx +10 -0
  10. package/src/components/DashboardWidgetContainer.tsx +69 -0
  11. package/src/components/NotFoundWidget.tsx +30 -0
  12. package/src/components/WidgetGroup.tsx +108 -0
  13. package/src/containers/Dashboard.tsx +19 -0
  14. package/src/containers/DashboardContext.tsx +8 -0
  15. package/src/containers/WidgetContainer.tsx +21 -0
  16. package/src/index.tsx +62 -0
  17. package/src/types.ts +21 -0
  18. package/src/versionedClient.ts +7 -0
  19. package/src/widgets/projectInfo/ProjectInfo.tsx +233 -0
  20. package/src/widgets/projectInfo/index.ts +10 -0
  21. package/src/widgets/projectUsers/ProjectUsers.tsx +171 -0
  22. package/src/widgets/projectUsers/index.ts +10 -0
  23. package/src/widgets/sanityTutorials/SanityTutorials.tsx +77 -0
  24. package/src/widgets/sanityTutorials/Tutorial.tsx +111 -0
  25. package/src/widgets/sanityTutorials/dataAdapter.ts +48 -0
  26. package/src/widgets/sanityTutorials/index.ts +10 -0
  27. package/.babelrc +0 -4
  28. package/lib/DashboardTool.js +0 -59
  29. package/lib/components/DashboardLayout.js +0 -35
  30. package/lib/components/NotFoundWidget.js +0 -51
  31. package/lib/components/WidgetGroup.js +0 -67
  32. package/lib/components/dashboardWidget.js +0 -51
  33. package/lib/containers/Dashboard.js +0 -32
  34. package/lib/containers/WidgetContainer.js +0 -56
  35. package/lib/dashboardConfig.js +0 -16
  36. package/lib/legacyParts.js +0 -55
  37. package/lib/versionedClient.js +0 -20
  38. package/lib/widget.css +0 -62
  39. package/lib/widgets/projectInfo/ProjectInfo.js +0 -265
  40. package/lib/widgets/projectInfo/index.js +0 -19
  41. package/lib/widgets/projectUsers/ProjectUsers.js +0 -188
  42. package/lib/widgets/projectUsers/index.js +0 -16
  43. package/lib/widgets/sanityTutorials/SanityTutorials.js +0 -115
  44. package/lib/widgets/sanityTutorials/Tutorial.js +0 -111
  45. package/lib/widgets/sanityTutorials/dataAdapter.js +0 -28
  46. package/lib/widgets/sanityTutorials/index.js +0 -19
  47. package/sanity.json +0 -59
  48. package/tsconfig.json +0 -17
package/README.md CHANGED
@@ -1,90 +1,134 @@
1
- # Dashboard
1
+ # Sanity Dashboard
2
2
 
3
- Dashboard is a Sanity Content Studio Tool which picks up and renders any widgets which implement `part:@sanity/dashboard/widget`. Install this plugin in your Studio to display stats about your project, recently edited documents, etc.
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
- The Dashboard tool has been designed to be as generic as possible, making few assumptions about its widgets. The Dashboard itself is mostly concerned about the layout of the configured widgets.
17
+ ![Sanity dashboard](assets/dashboard.png)
6
18
 
7
19
  ## Install
8
20
 
9
- - `cd` to your Content Studio
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
- ## How to configure the Dashboard
23
+ `npm install --save @sanity/dashboard@sanity-v3`
17
24
 
18
- Changing what is rendered on your Dashboard is easy. To take control, do the following:
25
+ or
19
26
 
20
- 1. Implement your own dashboardConfig. In your `sanity.json` file, append the following line to the `parts` array:
27
+ `yarn add @sanity/dashboard@sanity-v3`
21
28
 
22
- ```json
23
- {
24
- "implements": "part:@sanity/dashboard/config",
25
- "path": "src/dashboardConfig.js"
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
- 2. Create the file `src/dashboardConfig.js` and make sure it's shaped something like this:
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
- ```js
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
- The `widgets` array is how you tell the Dashboard which widgets to render. The ones mentioned in the above example are bundled with Sanity and require no separate installation.
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
- 3. Restart your Studio and play around with the order of the widgets array in `src/dashboardConfig.js`. You can also duplicate them, should you want multiple instances of the same widget (see below).
70
+ Widgets can be configured by passing widget-specific config:
40
71
 
41
- A widget’s size behavior can be defined by adding a `layout` key to a the widget config. E.g.: `{name: 'project-users', layout: {width: 'full', height: 'small'}}`. Accepted values are `auto`, `small`, `medium`, `large` and `full`.
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 other [Sanity Studio plugin](https://www.sanity.io/docs/extending/plugins).
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. Type `sanity install dashboard-widget-cats` in your terminal (this works because it's published on npm under the name `sanity-plugin-dashboard-widget-cats`)
50
- 2. Update your `src/dashboardConfig.js` file by adding `{name: 'cats'}` to the `widgets` array
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 allow options to change aspects of their behavior. If you install the document-list widget mentioned below, it can be configured with:
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
- ```js
56
- {name: 'document-list', options: {title: 'Last edited books', order: '_updatedAt desc', types: ['book']}}
90
+ ```ts
91
+ documentListWidget({
92
+ showCreateButton: true,
93
+ limit: 5,
94
+ types: ["my-document-type"],
95
+ })
57
96
  ```
58
97
 
59
- Thus, if you want your dashboard to display both newest documents across all document types and another widget showing the last edited books, your dashboardConfig would look like this:
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
- {name: 'document-list', options: {title: 'New', order: '_createdAt desc'}},
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 Sanity plugins that implement the part `part:@sanity/dashboard/widget`. Stay tuned for a complete "Widget Authors Cookbook", but until then, have a look at some sample widgets: E.g. [A document List](https://github.com/sanity-io/dashboard-widget-document-list/tree/master) or [maybe some cats](https://github.com/sanity-io/example-dashboard-widget-cats)?
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 `DashboardWidget` component from the Sanity Studio by importing it like so: `import { DashboardWidget } from "@sanity/dashboard";`.
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, and the option of presenting your content in the header, footer, or body of the widget.
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
- <DashboardWidget
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
- </DashboardWidget>
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.