@sanity/dashboard 0.147.10-next.22 → 1.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 (77) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +150 -58
  3. package/lib/cjs/index.js +1002 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/esm/index.js +977 -0
  6. package/lib/esm/index.js.map +1 -0
  7. package/lib/types/index.d.ts +42 -0
  8. package/lib/types/index.d.ts.map +1 -0
  9. package/package.json +58 -14
  10. package/src/components/DashboardLayout.tsx +10 -0
  11. package/src/components/DashboardWidgetContainer.tsx +69 -0
  12. package/src/components/NotFoundWidget.tsx +30 -0
  13. package/src/components/WidgetGroup.tsx +108 -0
  14. package/src/containers/Dashboard.tsx +19 -0
  15. package/src/containers/DashboardContext.tsx +8 -0
  16. package/src/containers/WidgetContainer.tsx +21 -0
  17. package/src/index.tsx +62 -0
  18. package/src/types.ts +21 -0
  19. package/src/versionedClient.ts +7 -0
  20. package/src/widgets/projectInfo/ProjectInfo.tsx +233 -0
  21. package/src/widgets/projectInfo/index.ts +10 -0
  22. package/src/widgets/projectUsers/ProjectUsers.tsx +171 -0
  23. package/src/widgets/projectUsers/index.ts +10 -0
  24. package/src/widgets/sanityTutorials/SanityTutorials.tsx +77 -0
  25. package/src/widgets/sanityTutorials/Tutorial.tsx +111 -0
  26. package/src/widgets/sanityTutorials/dataAdapter.ts +48 -0
  27. package/src/widgets/sanityTutorials/index.ts +10 -0
  28. package/.babelrc +0 -4
  29. package/lib/DashboardTool.js +0 -33
  30. package/lib/components/DashboardLayout.css +0 -8
  31. package/lib/components/DashboardLayout.js +0 -30
  32. package/lib/components/NotFoundWidget.css +0 -22
  33. package/lib/components/NotFoundWidget.js +0 -37
  34. package/lib/components/WidgetGroup.css +0 -59
  35. package/lib/components/WidgetGroup.js +0 -41
  36. package/lib/components/story.js +0 -95
  37. package/lib/containers/Dashboard.js +0 -32
  38. package/lib/containers/WidgetContainer.js +0 -56
  39. package/lib/dashboardConfig.js +0 -16
  40. package/lib/widget.css +0 -62
  41. package/lib/widgets/projectInfo/ProjectInfo.css +0 -103
  42. package/lib/widgets/projectInfo/ProjectInfo.js +0 -216
  43. package/lib/widgets/projectInfo/index.js +0 -19
  44. package/lib/widgets/projectUsers/ProjectUsers.css +0 -48
  45. package/lib/widgets/projectUsers/ProjectUsers.js +0 -147
  46. package/lib/widgets/projectUsers/index.js +0 -16
  47. package/lib/widgets/sanityTutorials/SanityTutorials.css +0 -39
  48. package/lib/widgets/sanityTutorials/SanityTutorials.js +0 -99
  49. package/lib/widgets/sanityTutorials/Tutorial.css +0 -106
  50. package/lib/widgets/sanityTutorials/Tutorial.js +0 -67
  51. package/lib/widgets/sanityTutorials/dataAdapter.js +0 -30
  52. package/lib/widgets/sanityTutorials/index.js +0 -19
  53. package/sanity.json +0 -59
  54. package/src/DashboardTool.js +0 -20
  55. package/src/components/DashboardLayout.css +0 -8
  56. package/src/components/DashboardLayout.js +0 -19
  57. package/src/components/NotFoundWidget.css +0 -22
  58. package/src/components/NotFoundWidget.js +0 -29
  59. package/src/components/WidgetGroup.css +0 -59
  60. package/src/components/WidgetGroup.js +0 -29
  61. package/src/components/story.js +0 -81
  62. package/src/containers/Dashboard.js +0 -20
  63. package/src/containers/WidgetContainer.js +0 -52
  64. package/src/dashboardConfig.js +0 -3
  65. package/src/widget.css +0 -62
  66. package/src/widgets/projectInfo/ProjectInfo.css +0 -103
  67. package/src/widgets/projectInfo/ProjectInfo.js +0 -189
  68. package/src/widgets/projectInfo/index.js +0 -7
  69. package/src/widgets/projectUsers/ProjectUsers.css +0 -48
  70. package/src/widgets/projectUsers/ProjectUsers.js +0 -126
  71. package/src/widgets/projectUsers/index.js +0 -6
  72. package/src/widgets/sanityTutorials/SanityTutorials.css +0 -39
  73. package/src/widgets/sanityTutorials/SanityTutorials.js +0 -82
  74. package/src/widgets/sanityTutorials/Tutorial.css +0 -106
  75. package/src/widgets/sanityTutorials/Tutorial.js +0 -42
  76. package/src/widgets/sanityTutorials/dataAdapter.js +0 -18
  77. package/src/widgets/sanityTutorials/index.js +0 -7
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 - 2020 Sanity.io
3
+ Copyright (c) 2016 - 2022 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,105 +1,197 @@
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).
4
8
 
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.
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.
16
+
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
47
+
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";
36
58
 
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.
38
59
 
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).
60
+ // configure the dashboard tool with widgets
61
+ dashboardTool({
62
+ widgets: [
63
+ sanityTutorialsWidget(),
64
+ projectInfoWidget(),
65
+ projectUsersWidget(),
66
+ ]
67
+ })
68
+ ```
69
+
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 which 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 styles defined in `./src/widgets.css` for your basic building blocks:
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
 
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.
125
+
126
+ If you need something more flexible you can create your own component.
127
+
128
+ Setting up the widget with the default setup will give you a basic widget that looks something like this:
129
+
130
+ ```js
131
+ <DashboardWidgetContainer
132
+ header="A cat"
133
+ footer={
134
+ <Flex direction="column" align="stretch">
135
+ <Button
136
+ flex={1}
137
+ paddingX={2}
138
+ paddingY={4}
139
+ mode="bleed"
140
+ tone="primary"
141
+ text="Get new cat"
142
+ />
143
+ </Flex>
144
+ }
145
+ >
146
+ <figure>
147
+ <img src="https://placekitten.com/300/450" />
148
+ </figure>
149
+ </DashboardWidgetContainer>
79
150
  ```
80
- @import 'part:@sanity/base/theme/variables-style';
81
151
 
82
- .container {
83
- composes: container from 'part:@sanity/dashboard/widget-styles';
84
- }
152
+ ### More examples
85
153
 
86
- .containerWithPadding {
87
- composes: containerWithPadding from 'part:@sanity/dashboard/widget-styles';
88
- }
154
+ You can study the source code of these widgets to get a sense of how you can approach fetching of documents, adding configuration, and so on:
89
155
 
90
- .header {
91
- composes: header from "part:@sanity/dashboard/widget-styles";
92
- }
156
+ - [dashboard-widget-document-list](https://github.com/sanity-io/dashboard-widget-document-list)
157
+ - [dashboard-widget-widget-document-count](https://github.com/sanity-io/example-dashboard-widget-document-count)
158
+ - [dashboard-widget-netlify](https://github.com/sanity-io/sanity-plugin-dashboard-widget-netlify)
93
159
 
94
- .title {
95
- composes: title from 'part:@sanity/dashboard/widget-styles';
96
- }
160
+ ---
97
161
 
98
- .buttonContainer {
99
- composes: bottomButtonContainer from 'part:@sanity/dashboard/widget-styles';
100
- }
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
101
182
  ```
102
183
 
103
- Your widget root element should aways be wrapped with the `container` style from `part:@sanity/dashboard/widget-styles`
184
+ In another shell, `cd` to your test studio and run:
104
185
 
105
- ---
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
195
+
196
+ This plugin uses [@sanity/plugin-sdk](https://github.com/sanity-io/plugin-sdk)
197
+ with default configuration for build & watch scripts.