sanity-plugin-dashboard-widget-document-list 0.0.12 → 0.1.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/.github/workflows/main.yml +133 -0
- package/.releaserc.json +7 -0
- package/.semantic-release/sanity-plugin-dashboard-widget-document-list-0.1.0.tgz +0 -0
- package/CHANGELOG.md +18 -0
- package/LICENSE +1 -1
- package/README.md +11 -2
- package/lib/DocumentList.js +133 -174
- package/lib/DocumentList.js.map +1 -0
- package/lib/index.js +8 -7
- package/lib/index.js.map +1 -0
- package/lib/sanityConnector.js +42 -41
- package/lib/sanityConnector.js.map +1 -0
- package/package.json +25 -26
- package/sanity.json +0 -1
- package/.babelrc +0 -7
- package/.eslintignore +0 -1
- package/.eslintrc +0 -11
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: CI & Release
|
|
3
|
+
|
|
4
|
+
# Workflow name based on selected inputs. Fallback to default Github naming when expression evaluates to empty string
|
|
5
|
+
run-name: >-
|
|
6
|
+
${{
|
|
7
|
+
inputs.release && inputs.test && format('Build {0} ➤ Test ➤ Publish to NPM', github.ref_name) ||
|
|
8
|
+
inputs.release && !inputs.test && format('Build {0} ➤ Skip Tests ➤ Publish to NPM', github.ref_name) ||
|
|
9
|
+
github.event_name == 'workflow_dispatch' && inputs.test && format('Build {0} ➤ Test', github.ref_name) ||
|
|
10
|
+
github.event_name == 'workflow_dispatch' && !inputs.test && format('Build {0} ➤ Skip Tests', github.ref_name) ||
|
|
11
|
+
''
|
|
12
|
+
}}
|
|
13
|
+
|
|
14
|
+
on:
|
|
15
|
+
# Build on pushes branches that have a PR (including drafts)
|
|
16
|
+
pull_request:
|
|
17
|
+
# Build on commits pushed to branches without a PR if it's in the allowlist
|
|
18
|
+
push:
|
|
19
|
+
branches: [main,studio-v2]
|
|
20
|
+
# https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
|
|
21
|
+
workflow_dispatch:
|
|
22
|
+
inputs:
|
|
23
|
+
test:
|
|
24
|
+
description: Run tests
|
|
25
|
+
required: true
|
|
26
|
+
default: true
|
|
27
|
+
type: boolean
|
|
28
|
+
release:
|
|
29
|
+
description: Release new version
|
|
30
|
+
required: true
|
|
31
|
+
default: false
|
|
32
|
+
type: boolean
|
|
33
|
+
|
|
34
|
+
concurrency:
|
|
35
|
+
# On PRs builds will cancel if new pushes happen before the CI completes, as it defines `github.head_ref` and gives it the name of the branch the PR wants to merge into
|
|
36
|
+
# Otherwise `github.run_id` ensures that you can quickly merge a queue of PRs without causing tests to auto cancel on any of the commits pushed to main.
|
|
37
|
+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
38
|
+
cancel-in-progress: true
|
|
39
|
+
|
|
40
|
+
jobs:
|
|
41
|
+
log-the-inputs:
|
|
42
|
+
name: Log inputs
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- run: |
|
|
46
|
+
echo "Inputs: $INPUTS"
|
|
47
|
+
env:
|
|
48
|
+
INPUTS: ${{ toJSON(inputs) }}
|
|
49
|
+
|
|
50
|
+
build:
|
|
51
|
+
runs-on: ubuntu-latest
|
|
52
|
+
name: Lint & Build
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
|
|
55
|
+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
|
|
56
|
+
with:
|
|
57
|
+
cache: npm
|
|
58
|
+
node-version: lts/*
|
|
59
|
+
- run: npm ci
|
|
60
|
+
# Linting can be skipped
|
|
61
|
+
- run: npm run lint --if-present
|
|
62
|
+
if: github.event.inputs.test != 'false'
|
|
63
|
+
# But not the build script, as semantic-release will crash if this command fails so it makes sense to test it early
|
|
64
|
+
- run: npm run prepublishOnly --if-present
|
|
65
|
+
|
|
66
|
+
# test:
|
|
67
|
+
# needs: build
|
|
68
|
+
# # The test matrix can be skipped, in case a new release needs to be fast-tracked and tests are already passing on main
|
|
69
|
+
# if: github.event.inputs.test != 'false'
|
|
70
|
+
# runs-on: ${{ matrix.os }}
|
|
71
|
+
# name: Node.js ${{ matrix.node }} / ${{ matrix.os }}
|
|
72
|
+
# strategy:
|
|
73
|
+
# # A test failing on windows doesn't mean it'll fail on macos. It's useful to let all tests run to its completion to get the full picture
|
|
74
|
+
# fail-fast: false
|
|
75
|
+
# matrix:
|
|
76
|
+
# # Run the testing suite on each major OS with the latest LTS release of Node.js
|
|
77
|
+
# os: [macos-latest, ubuntu-latest, windows-latest]
|
|
78
|
+
# node: [lts/*]
|
|
79
|
+
# # It makes sense to also test the oldest, and latest, versions of Node.js, on ubuntu-only since it's the fastest CI runner
|
|
80
|
+
# include:
|
|
81
|
+
# - os: ubuntu-latest
|
|
82
|
+
# # Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
|
|
83
|
+
# node: lts/-2
|
|
84
|
+
# - os: ubuntu-latest
|
|
85
|
+
# # Test the actively developed version that will become the latest LTS release next October
|
|
86
|
+
# node: current
|
|
87
|
+
# steps:
|
|
88
|
+
# # It's only necessary to do this for windows, as mac and ubuntu are sane OS's that already use LF
|
|
89
|
+
# - name: Set git to use LF
|
|
90
|
+
# if: matrix.os == 'windows-latest'
|
|
91
|
+
# run: |
|
|
92
|
+
# git config --global core.autocrlf false
|
|
93
|
+
# git config --global core.eol lf
|
|
94
|
+
# - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
|
|
95
|
+
# - uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
|
|
96
|
+
# with:
|
|
97
|
+
# cache: npm
|
|
98
|
+
# node-version: ${{ matrix.node }}
|
|
99
|
+
# - run: npm i
|
|
100
|
+
# - run: npm test --if-present
|
|
101
|
+
|
|
102
|
+
release:
|
|
103
|
+
# needs: [build, test]
|
|
104
|
+
needs: [build]
|
|
105
|
+
# only run if opt-in during workflow_dispatch
|
|
106
|
+
if: always() && github.event.inputs.release == 'true' && needs.build.result != 'failure' && needs.test.result != 'failure' && needs.test.result != 'cancelled'
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
name: Semantic release
|
|
109
|
+
steps:
|
|
110
|
+
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3
|
|
111
|
+
with:
|
|
112
|
+
# Need to fetch entire commit history to
|
|
113
|
+
# analyze every commit since last release
|
|
114
|
+
fetch-depth: 0
|
|
115
|
+
- uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # tag=v3
|
|
116
|
+
with:
|
|
117
|
+
cache: npm
|
|
118
|
+
node-version: lts/*
|
|
119
|
+
- run: npm ci
|
|
120
|
+
# Branches that will release new versions are defined in .releaserc.json
|
|
121
|
+
- run: npx semantic-release
|
|
122
|
+
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
|
|
123
|
+
# e.g. git tags were pushed but it exited before `npm publish`
|
|
124
|
+
if: always()
|
|
125
|
+
env:
|
|
126
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
127
|
+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
|
128
|
+
# Re-run semantic release with rich logs if it failed to publish for easier debugging
|
|
129
|
+
- run: npx semantic-release --dry-run --debug
|
|
130
|
+
if: failure()
|
|
131
|
+
env:
|
|
132
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
133
|
+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
package/.releaserc.json
ADDED
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!-- markdownlint-disable --><!-- textlint-disable -->
|
|
2
|
+
|
|
3
|
+
# 📓 Changelog
|
|
4
|
+
|
|
5
|
+
All notable changes to this project will be documented in this file. See
|
|
6
|
+
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
|
+
|
|
8
|
+
## [0.1.0](https://github.com/sanity-io/dashboard-widget-document-list/compare/v0.0.13...v0.1.0) (2022-11-22)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
- make semantic-release happy (not really a feat) ([afe6342](https://github.com/sanity-io/dashboard-widget-document-list/commit/afe634251827e4651422ea82e4841954447d2e35))
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- added workflow so it can be triggered from v3 ([1fcacd7](https://github.com/sanity-io/dashboard-widget-document-list/commit/1fcacd76267754c7a8c8480ceb04d10c3fda981b))
|
|
17
|
+
- **ci:** publish using semantic-release ([8f5b196](https://github.com/sanity-io/dashboard-widget-document-list/commit/8f5b1964c484552bc712d88c962c94f9cf150004))
|
|
18
|
+
- typo ([3929617](https://github.com/sanity-io/dashboard-widget-document-list/commit/39296177e02b56c4748eff1fcaabcd275e746c06))
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2022, Sanity.io <hello@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
|
package/README.md
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
# dashboard-widget-document-list
|
|
2
|
-
Dashboard widget for the Sanity Content Studio which displays a list of documents
|
|
3
2
|
|
|
3
|
+
>This is a **Sanity Studio v2** plugin.
|
|
4
|
+
> For the v3 version, please refer to the [v3-branch](https://github.com/sanity-io/dashboard-widget-document-list).
|
|
4
5
|
|
|
6
|
+
Dashboard widget for the Sanity Content Studio which displays a list of documents
|
|
5
7
|
|
|
6
8
|
## Usage
|
|
7
9
|
Assuming you already have a functional Dashboard in your Sanity Content Studio.
|
|
8
10
|
|
|
9
11
|
1. Install this widget in your Studio folder like so:
|
|
10
12
|
|
|
13
|
+
```sh
|
|
14
|
+
yarn add sanity-plugin-dashboard-widget-document-list@studio-v2
|
|
11
15
|
```
|
|
12
|
-
|
|
16
|
+
|
|
17
|
+
Next, add `"dashboard-widget-document-list"` to `sanity.json` plugins array:
|
|
18
|
+
```json
|
|
19
|
+
"plugins": [
|
|
20
|
+
"dashboard-widget-document-list"
|
|
21
|
+
]
|
|
13
22
|
```
|
|
14
23
|
|
|
15
24
|
2. Update your `src/dashboardConfig.js` file by adding `{name: 'document-list'}` to the `widgets` array
|
package/lib/DocumentList.js
CHANGED
|
@@ -1,85 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
11
|
|
|
11
|
-
var
|
|
12
|
+
var _router = require("part:@sanity/base/router");
|
|
12
13
|
|
|
13
|
-
var
|
|
14
|
+
var _preview = _interopRequireDefault(require("part:@sanity/base/preview"));
|
|
14
15
|
|
|
15
|
-
var
|
|
16
|
+
var _spinner = _interopRequireDefault(require("part:@sanity/components/loading/spinner"));
|
|
16
17
|
|
|
17
|
-
var
|
|
18
|
+
var _schema = _interopRequireDefault(require("part:@sanity/base/schema"));
|
|
18
19
|
|
|
19
|
-
var
|
|
20
|
+
var _intent = _interopRequireDefault(require("part:@sanity/components/buttons/intent"));
|
|
20
21
|
|
|
21
|
-
var
|
|
22
|
+
var _default2 = require("part:@sanity/components/lists/default");
|
|
22
23
|
|
|
23
|
-
var
|
|
24
|
+
var _draftUtils = require("part:@sanity/base/util/draft-utils");
|
|
24
25
|
|
|
25
|
-
var
|
|
26
|
+
var _lodash = require("lodash");
|
|
26
27
|
|
|
27
|
-
var
|
|
28
|
+
var _sanityConnector = require("./sanityConnector");
|
|
28
29
|
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
var _intent = require('part:@sanity/components/buttons/intent');
|
|
32
|
-
|
|
33
|
-
var _intent2 = _interopRequireDefault(_intent);
|
|
34
|
-
|
|
35
|
-
var _default = require('part:@sanity/components/lists/default');
|
|
36
|
-
|
|
37
|
-
var _draftUtils = require('part:@sanity/base/util/draft-utils');
|
|
38
|
-
|
|
39
|
-
var _lodash = require('lodash');
|
|
40
|
-
|
|
41
|
-
var _sanityConnector = require('./sanityConnector');
|
|
42
|
-
|
|
43
|
-
var _DocumentList = require('./DocumentList.css');
|
|
44
|
-
|
|
45
|
-
var _DocumentList2 = _interopRequireDefault(_DocumentList);
|
|
30
|
+
var _DocumentList = _interopRequireDefault(require("./DocumentList.css"));
|
|
46
31
|
|
|
47
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
48
33
|
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
52
|
-
|
|
53
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable complexity */
|
|
34
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
54
35
|
|
|
36
|
+
var schemaTypeNames = _schema.default.getTypeNames();
|
|
55
37
|
|
|
56
|
-
|
|
38
|
+
class DocumentList extends _react.default.Component {
|
|
39
|
+
constructor() {
|
|
40
|
+
super(...arguments);
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
_inherits(DocumentList, _React$Component);
|
|
60
|
-
|
|
61
|
-
function DocumentList() {
|
|
62
|
-
var _ref;
|
|
63
|
-
|
|
64
|
-
var _temp, _this, _ret;
|
|
65
|
-
|
|
66
|
-
_classCallCheck(this, DocumentList);
|
|
67
|
-
|
|
68
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
69
|
-
args[_key] = arguments[_key];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = DocumentList.__proto__ || Object.getPrototypeOf(DocumentList)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
|
42
|
+
_defineProperty(this, "state", {
|
|
73
43
|
documents: null,
|
|
74
44
|
loading: true,
|
|
75
45
|
error: null
|
|
76
|
-
}
|
|
77
|
-
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
_defineProperty(this, "componentDidMount", () => {
|
|
49
|
+
var _this$props = this.props,
|
|
78
50
|
query = _this$props.query,
|
|
79
51
|
limit = _this$props.limit,
|
|
80
52
|
apiVersion = _this$props.apiVersion;
|
|
81
53
|
|
|
82
|
-
var _this$assembleQuery =
|
|
54
|
+
var _this$assembleQuery = this.assembleQuery(),
|
|
83
55
|
assembledQuery = _this$assembleQuery.assembledQuery,
|
|
84
56
|
params = _this$assembleQuery.params;
|
|
85
57
|
|
|
@@ -87,17 +59,22 @@ var DocumentList = function (_React$Component) {
|
|
|
87
59
|
return;
|
|
88
60
|
}
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
next:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
62
|
+
this.unsubscribe();
|
|
63
|
+
this.subscription = (0, _sanityConnector.getSubscription)(assembledQuery, params, apiVersion).subscribe({
|
|
64
|
+
next: documents => this.setState({
|
|
65
|
+
documents: documents.slice(0, limit),
|
|
66
|
+
loading: false
|
|
67
|
+
}),
|
|
68
|
+
error: _error => this.setState({
|
|
69
|
+
error: _error,
|
|
70
|
+
query,
|
|
71
|
+
loading: false
|
|
72
|
+
})
|
|
98
73
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
_defineProperty(this, "assembleQuery", () => {
|
|
77
|
+
var _this$props2 = this.props,
|
|
101
78
|
query = _this$props2.query,
|
|
102
79
|
queryParams = _this$props2.queryParams,
|
|
103
80
|
types = _this$props2.types,
|
|
@@ -105,125 +82,104 @@ var DocumentList = function (_React$Component) {
|
|
|
105
82
|
limit = _this$props2.limit;
|
|
106
83
|
|
|
107
84
|
if (query) {
|
|
108
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
assembledQuery: query,
|
|
87
|
+
params: queryParams
|
|
88
|
+
};
|
|
109
89
|
}
|
|
110
90
|
|
|
111
|
-
var documentTypes = schemaTypeNames.filter(
|
|
112
|
-
var schemaType =
|
|
91
|
+
var documentTypes = schemaTypeNames.filter(typeName => {
|
|
92
|
+
var schemaType = _schema.default.get(typeName);
|
|
93
|
+
|
|
113
94
|
return schemaType.type && schemaType.type.name === 'document';
|
|
114
95
|
});
|
|
115
|
-
|
|
116
96
|
return {
|
|
117
|
-
assembledQuery:
|
|
118
|
-
params: {
|
|
97
|
+
assembledQuery: "*[_type in $types] | order(".concat(order, ") [0...").concat(limit * 2, "]"),
|
|
98
|
+
params: {
|
|
99
|
+
types: types ? (0, _lodash.intersection)(types, documentTypes) : documentTypes
|
|
100
|
+
}
|
|
119
101
|
};
|
|
120
|
-
}
|
|
102
|
+
});
|
|
121
103
|
}
|
|
122
104
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
105
|
+
componentWillUnmount() {
|
|
106
|
+
this.unsubscribe();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
unsubscribe() {
|
|
110
|
+
if (this.subscription) {
|
|
111
|
+
this.subscription.unsubscribe();
|
|
127
112
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
render() {
|
|
116
|
+
var _this$props3 = this.props,
|
|
117
|
+
title = _this$props3.title,
|
|
118
|
+
types = _this$props3.types,
|
|
119
|
+
showCreateButton = _this$props3.showCreateButton,
|
|
120
|
+
createButtonText = _this$props3.createButtonText;
|
|
121
|
+
var _this$state = this.state,
|
|
122
|
+
documents = _this$state.documents,
|
|
123
|
+
loading = _this$state.loading,
|
|
124
|
+
error = _this$state.error;
|
|
125
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
126
|
+
className: _DocumentList.default.container
|
|
127
|
+
}, /*#__PURE__*/_react.default.createElement("header", {
|
|
128
|
+
className: _DocumentList.default.header
|
|
129
|
+
}, /*#__PURE__*/_react.default.createElement("h2", {
|
|
130
|
+
className: _DocumentList.default.title
|
|
131
|
+
}, title)), /*#__PURE__*/_react.default.createElement("div", {
|
|
132
|
+
className: _DocumentList.default.content
|
|
133
|
+
}, error && /*#__PURE__*/_react.default.createElement("div", null, error.message), !error && loading && /*#__PURE__*/_react.default.createElement(_spinner.default, {
|
|
134
|
+
center: true,
|
|
135
|
+
message: "Loading..."
|
|
136
|
+
}), !error && !documents && !loading && /*#__PURE__*/_react.default.createElement("div", null, "Could not locate any documents :/"), /*#__PURE__*/_react.default.createElement(_default2.List, null, documents && documents.map(doc => {
|
|
137
|
+
var type = _schema.default.get(doc._type);
|
|
138
|
+
|
|
139
|
+
return /*#__PURE__*/_react.default.createElement(_default2.Item, {
|
|
140
|
+
key: doc._id
|
|
141
|
+
}, /*#__PURE__*/_react.default.createElement(_router.IntentLink, {
|
|
142
|
+
intent: "edit",
|
|
143
|
+
params: {
|
|
144
|
+
type: doc._type,
|
|
145
|
+
id: (0, _draftUtils.getPublishedId)(doc._id)
|
|
146
|
+
},
|
|
147
|
+
className: _DocumentList.default.link
|
|
148
|
+
}, /*#__PURE__*/_react.default.createElement(_preview.default, {
|
|
149
|
+
layout: "default",
|
|
150
|
+
type: type,
|
|
151
|
+
value: doc,
|
|
152
|
+
key: doc._id
|
|
153
|
+
})));
|
|
154
|
+
}))), types && types.length === 1 && showCreateButton && /*#__PURE__*/_react.default.createElement("div", {
|
|
155
|
+
className: _DocumentList.default.footer
|
|
156
|
+
}, /*#__PURE__*/_react.default.createElement(_intent.default, {
|
|
157
|
+
bleed: true,
|
|
158
|
+
color: "primary",
|
|
159
|
+
kind: "simple",
|
|
160
|
+
intent: "create",
|
|
161
|
+
params: {
|
|
162
|
+
type: types[0]
|
|
133
163
|
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
'header',
|
|
154
|
-
{ className: _DocumentList2.default.header },
|
|
155
|
-
_react2.default.createElement(
|
|
156
|
-
'h2',
|
|
157
|
-
{ className: _DocumentList2.default.title },
|
|
158
|
-
title
|
|
159
|
-
)
|
|
160
|
-
),
|
|
161
|
-
_react2.default.createElement(
|
|
162
|
-
'div',
|
|
163
|
-
{ className: _DocumentList2.default.content },
|
|
164
|
-
error && _react2.default.createElement(
|
|
165
|
-
'div',
|
|
166
|
-
null,
|
|
167
|
-
error.message
|
|
168
|
-
),
|
|
169
|
-
!error && loading && _react2.default.createElement(_spinner2.default, { center: true, message: 'Loading...' }),
|
|
170
|
-
!error && !documents && !loading && _react2.default.createElement(
|
|
171
|
-
'div',
|
|
172
|
-
null,
|
|
173
|
-
'Could not locate any documents :/'
|
|
174
|
-
),
|
|
175
|
-
_react2.default.createElement(
|
|
176
|
-
_default.List,
|
|
177
|
-
null,
|
|
178
|
-
documents && documents.map(function (doc) {
|
|
179
|
-
var type = _schema2.default.get(doc._type);
|
|
180
|
-
return _react2.default.createElement(
|
|
181
|
-
_default.Item,
|
|
182
|
-
{ key: doc._id },
|
|
183
|
-
_react2.default.createElement(
|
|
184
|
-
_router.IntentLink,
|
|
185
|
-
{
|
|
186
|
-
intent: 'edit',
|
|
187
|
-
params: {
|
|
188
|
-
type: doc._type,
|
|
189
|
-
id: (0, _draftUtils.getPublishedId)(doc._id)
|
|
190
|
-
},
|
|
191
|
-
className: _DocumentList2.default.link
|
|
192
|
-
},
|
|
193
|
-
_react2.default.createElement(_preview2.default, { layout: 'default', type: type, value: doc, key: doc._id })
|
|
194
|
-
)
|
|
195
|
-
);
|
|
196
|
-
})
|
|
197
|
-
)
|
|
198
|
-
),
|
|
199
|
-
types && types.length === 1 && showCreateButton && _react2.default.createElement(
|
|
200
|
-
'div',
|
|
201
|
-
{ className: _DocumentList2.default.footer },
|
|
202
|
-
_react2.default.createElement(
|
|
203
|
-
_intent2.default,
|
|
204
|
-
{ bleed: true, color: 'primary', kind: 'simple', intent: 'create', params: { type: types[0] } },
|
|
205
|
-
createButtonText || 'Create new ' + types[0]
|
|
206
|
-
)
|
|
207
|
-
)
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
}]);
|
|
211
|
-
|
|
212
|
-
return DocumentList;
|
|
213
|
-
}(_react2.default.Component);
|
|
214
|
-
|
|
215
|
-
DocumentList.propTypes = {
|
|
216
|
-
title: _propTypes2.default.string,
|
|
217
|
-
types: _propTypes2.default.arrayOf(_propTypes2.default.string),
|
|
218
|
-
query: _propTypes2.default.string,
|
|
219
|
-
queryParams: _propTypes2.default.object, // eslint-disable-line react/forbid-prop-types
|
|
220
|
-
order: _propTypes2.default.string,
|
|
221
|
-
limit: _propTypes2.default.number,
|
|
222
|
-
showCreateButton: _propTypes2.default.bool,
|
|
223
|
-
createButtonText: _propTypes2.default.string,
|
|
224
|
-
apiVersion: _propTypes2.default.string
|
|
225
|
-
};
|
|
226
|
-
DocumentList.defaultProps = {
|
|
164
|
+
}, createButtonText || "Create new ".concat(types[0]))));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_defineProperty(DocumentList, "propTypes", {
|
|
170
|
+
title: _propTypes.default.string,
|
|
171
|
+
types: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
172
|
+
query: _propTypes.default.string,
|
|
173
|
+
queryParams: _propTypes.default.object,
|
|
174
|
+
// eslint-disable-line react/forbid-prop-types
|
|
175
|
+
order: _propTypes.default.string,
|
|
176
|
+
limit: _propTypes.default.number,
|
|
177
|
+
showCreateButton: _propTypes.default.bool,
|
|
178
|
+
createButtonText: _propTypes.default.string,
|
|
179
|
+
apiVersion: _propTypes.default.string
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
_defineProperty(DocumentList, "defaultProps", {
|
|
227
183
|
title: 'Last created',
|
|
228
184
|
order: '_createdAt desc',
|
|
229
185
|
limit: 10,
|
|
@@ -233,5 +189,8 @@ DocumentList.defaultProps = {
|
|
|
233
189
|
showCreateButton: true,
|
|
234
190
|
createButtonText: null,
|
|
235
191
|
apiVersion: 'v1'
|
|
236
|
-
};
|
|
237
|
-
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
var _default = DocumentList;
|
|
195
|
+
exports.default = _default;
|
|
196
|
+
//# sourceMappingURL=DocumentList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/DocumentList.js"],"names":["schemaTypeNames","schema","getTypeNames","DocumentList","React","Component","documents","loading","error","props","query","limit","apiVersion","assembleQuery","assembledQuery","params","unsubscribe","subscription","subscribe","next","setState","slice","queryParams","types","order","documentTypes","filter","typeName","schemaType","get","type","name","componentWillUnmount","render","title","showCreateButton","createButtonText","state","styles","container","header","content","message","map","doc","_type","_id","id","link","length","footer","PropTypes","string","arrayOf","object","number","bool"],"mappings":";;;;;;;AACA;;AACA;;A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,EAAC,QAAzD;AAAkE,MAAA,MAAM,EAAE;AAACpB,QAAAA,IAAI,EAAEP,KAAK,CAAC,CAAD;AAAZ;AAA1E,OACGa,gBAAgB,yBAAkBb,KAAK,CAAC,CAAD,CAAvB,CADnB,CADF,CA9BJ,CADF;AAuCD;;AAxHwC;;gBAArCpB,Y,eAQe;AACjB+B,EAAAA,KAAK,EAAEiB,mBAAUC,MADA;AAEjB7B,EAAAA,KAAK,EAAE4B,mBAAUE,OAAV,CAAkBF,mBAAUC,MAA5B,CAFU;AAGjB1C,EAAAA,KAAK,EAAEyC,mBAAUC,MAHA;AAIjB9B,EAAAA,WAAW,EAAE6B,mBAAUG,MAJN;AAIc;AAC/B9B,EAAAA,KAAK,EAAE2B,mBAAUC,MALA;AAMjBzC,EAAAA,KAAK,EAAEwC,mBAAUI,MANA;AAOjBpB,EAAAA,gBAAgB,EAAEgB,mBAAUK,IAPX;AAQjBpB,EAAAA,gBAAgB,EAAEe,mBAAUC,MARX;AASjBxC,EAAAA,UAAU,EAAEuC,mBAAUC;AATL,C;;gBARfjD,Y,kBAoBkB;AACpB+B,EAAAA,KAAK,EAAE,cADa;AAEpBV,EAAAA,KAAK,EAAE,iBAFa;AAGpBb,EAAAA,KAAK,EAAE,EAHa;AAIpBY,EAAAA,KAAK,EAAE,IAJa;AAKpBb,EAAAA,KAAK,EAAE,IALa;AAMpBY,EAAAA,WAAW,EAAE,EANO;AAOpBa,EAAAA,gBAAgB,EAAE,IAPE;AAQpBC,EAAAA,gBAAgB,EAAE,IARE;AASpBxB,EAAAA,UAAU,EAAE;AATQ,C;;eAuGTT,Y","sourcesContent":["/* eslint-disable complexity */\nimport React from 'react'\nimport PropTypes from 'prop-types'\nimport {IntentLink} from 'part:@sanity/base/router'\nimport SanityPreview from 'part:@sanity/base/preview'\nimport Spinner from 'part:@sanity/components/loading/spinner'\nimport schema from 'part:@sanity/base/schema'\nimport IntentButton from 'part:@sanity/components/buttons/intent'\nimport {List, Item} from 'part:@sanity/components/lists/default'\nimport {getPublishedId} from 'part:@sanity/base/util/draft-utils'\nimport {intersection} from 'lodash'\nimport {getSubscription} from './sanityConnector'\nimport styles from './DocumentList.css'\n\nconst schemaTypeNames = schema.getTypeNames()\n\nclass DocumentList extends React.Component {\n\n state = {\n documents: null,\n loading: true,\n error: null\n }\n\n static propTypes = {\n title: PropTypes.string,\n types: PropTypes.arrayOf(PropTypes.string),\n query: PropTypes.string,\n queryParams: PropTypes.object, // eslint-disable-line react/forbid-prop-types\n order: PropTypes.string,\n limit: PropTypes.number,\n showCreateButton: PropTypes.bool,\n createButtonText: PropTypes.string,\n apiVersion: PropTypes.string\n }\n\n static defaultProps = {\n title: 'Last created',\n order: '_createdAt desc',\n limit: 10,\n types: null,\n query: null,\n queryParams: {},\n showCreateButton: true,\n createButtonText: null,\n apiVersion: 'v1'\n }\n\n componentDidMount = () => {\n const {query, limit, apiVersion} = this.props\n const {assembledQuery, params} = this.assembleQuery()\n if (!assembledQuery) {\n return\n }\n\n this.unsubscribe()\n this.subscription = getSubscription(assembledQuery, params, apiVersion)\n .subscribe({\n next: documents =>\n this.setState({documents: documents.slice(0, limit), loading: false}),\n error: error =>\n this.setState({error, query, loading: false})\n })\n }\n\n componentWillUnmount() {\n this.unsubscribe()\n }\n\n unsubscribe() {\n if (this.subscription) {\n this.subscription.unsubscribe()\n }\n }\n\n assembleQuery = () => {\n const {query, queryParams, types, order, limit} = this.props\n if (query) {\n return {assembledQuery: query, params: queryParams}\n }\n\n const documentTypes = schemaTypeNames.filter(typeName => {\n const schemaType = schema.get(typeName)\n return schemaType.type && schemaType.type.name === 'document'\n })\n\n return {\n assembledQuery: `*[_type in $types] | order(${order}) [0...${limit * 2}]`,\n params: {types: types ? intersection(types, documentTypes) : documentTypes}\n }\n }\n\n\n render() {\n const {title, types, showCreateButton, createButtonText} = this.props\n const {documents, loading, error} = this.state\n\n return (\n <div className={styles.container}>\n <header className={styles.header}>\n <h2 className={styles.title}>{title}</h2>\n </header>\n <div className={styles.content}>\n {error && <div>{error.message}</div>}\n {!error && loading && <Spinner center message=\"Loading...\" />}\n {(!error && !documents && !loading) && <div>Could not locate any documents :/</div>}\n <List>\n {documents && documents.map(doc => {\n const type = schema.get(doc._type)\n return (\n <Item key={doc._id}>\n <IntentLink\n intent=\"edit\"\n params={{\n type: doc._type,\n id: getPublishedId(doc._id)\n }}\n className={styles.link}\n >\n <SanityPreview layout=\"default\" type={type} value={doc} key={doc._id} />\n </IntentLink>\n </Item>\n )\n\n })}\n </List>\n </div>\n {types && types.length === 1 && showCreateButton && (\n <div className={styles.footer}>\n <IntentButton bleed color=\"primary\" kind=\"simple\" intent=\"create\" params={{type: types[0]}}>\n {createButtonText || `Create new ${types[0]}`}\n </IntentButton>\n </div>\n )}\n </div>\n )\n }\n}\n\nexport default DocumentList\n"],"file":"DocumentList.js"}
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = void 0;
|
|
6
7
|
|
|
7
|
-
var _DocumentList = require(
|
|
8
|
-
|
|
9
|
-
var _DocumentList2 = _interopRequireDefault(_DocumentList);
|
|
8
|
+
var _DocumentList = _interopRequireDefault(require("./DocumentList"));
|
|
10
9
|
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
var _default = {
|
|
14
13
|
name: 'document-list',
|
|
15
|
-
component:
|
|
16
|
-
};
|
|
14
|
+
component: _DocumentList.default
|
|
15
|
+
};
|
|
16
|
+
exports.default = _default;
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["name","component","DocumentList"],"mappings":";;;;;;;AAAA;;;;eAEe;AACbA,EAAAA,IAAI,EAAE,eADO;AAEbC,EAAAA,SAAS,EAAEC;AAFE,C","sourcesContent":["import DocumentList from './DocumentList'\n\nexport default {\n name: 'document-list',\n component: DocumentList\n}\n"],"file":"index.js"}
|
package/lib/sanityConnector.js
CHANGED
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var _rxjs = require(
|
|
3
|
+
var _rxjs = require("rxjs");
|
|
4
4
|
|
|
5
|
-
var _operators = require(
|
|
5
|
+
var _operators = require("rxjs/operators");
|
|
6
6
|
|
|
7
|
-
var _lodash = require(
|
|
7
|
+
var _lodash = require("lodash");
|
|
8
8
|
|
|
9
|
-
var _client = require(
|
|
10
|
-
|
|
11
|
-
var _client2 = _interopRequireDefault(_client);
|
|
9
|
+
var _client = _interopRequireDefault(require("part:@sanity/base/client"));
|
|
12
10
|
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
12
|
|
|
15
|
-
var withConfig =
|
|
16
|
-
return typeof
|
|
13
|
+
var withConfig = config => {
|
|
14
|
+
return typeof _client.default.withConfig === 'function' ? _client.default.withConfig(config) : _client.default;
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
var draftId =
|
|
20
|
-
return 'drafts.' + nonDraftDoc._id;
|
|
21
|
-
};
|
|
17
|
+
var draftId = nonDraftDoc => "drafts.".concat(nonDraftDoc._id);
|
|
22
18
|
|
|
23
|
-
var prepareDocumentList =
|
|
19
|
+
var prepareDocumentList = (incoming, apiVersion) => {
|
|
24
20
|
if (!incoming) {
|
|
25
21
|
return Promise.resolve([]);
|
|
26
22
|
}
|
|
27
|
-
var documents = Array.isArray(incoming) ? incoming : [incoming];
|
|
28
|
-
|
|
29
|
-
var ids = documents.filter(function (doc) {
|
|
30
|
-
return !doc._id.startsWith('drafts.');
|
|
31
|
-
}).map(draftId);
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
var documents = Array.isArray(incoming) ? incoming : [incoming];
|
|
25
|
+
var ids = documents.filter(doc => !doc._id.startsWith('drafts.')).map(draftId);
|
|
26
|
+
return withConfig({
|
|
27
|
+
apiVersion
|
|
28
|
+
}).fetch('*[_id in $ids]', {
|
|
29
|
+
ids
|
|
30
|
+
}).then(drafts => {
|
|
31
|
+
var outgoing = documents.map(doc => {
|
|
32
|
+
var foundDraft = drafts.find(draft => draft._id === draftId(doc));
|
|
38
33
|
return foundDraft || doc;
|
|
39
34
|
});
|
|
40
35
|
return (0, _lodash.uniqBy)(outgoing, '_id');
|
|
41
|
-
}).catch(
|
|
42
|
-
throw new Error(
|
|
36
|
+
}).catch(error => {
|
|
37
|
+
throw new Error("Problems fetching docs ".concat(ids, ". Error: ").concat(error.message));
|
|
43
38
|
});
|
|
44
39
|
};
|
|
45
40
|
|
|
46
|
-
var getSubscription =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
var getSubscription = (query, params, apiVersion) => withConfig({
|
|
42
|
+
apiVersion
|
|
43
|
+
}).listen(query, params, {
|
|
44
|
+
events: ['welcome', 'mutation'],
|
|
45
|
+
includeResult: false,
|
|
46
|
+
visibility: 'query'
|
|
47
|
+
}).pipe((0, _operators.switchMap)(event => {
|
|
48
|
+
return (0, _rxjs.of)(1).pipe(event.type === 'welcome' ? (0, _operators.tap)() : (0, _operators.delay)(1000), (0, _operators.mergeMap)(() => withConfig({
|
|
49
|
+
apiVersion
|
|
50
|
+
}).fetch(query, params).then(incoming => {
|
|
51
|
+
return prepareDocumentList(incoming, apiVersion);
|
|
52
|
+
}).catch(error => {
|
|
53
|
+
if (error.message.startsWith('Problems fetching docs')) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw new Error("Query failed ".concat(query, " and ").concat(JSON.stringify(params), ". Error: ").concat(error.message));
|
|
58
|
+
})));
|
|
59
|
+
}));
|
|
60
60
|
|
|
61
61
|
module.exports = {
|
|
62
|
-
getSubscription
|
|
63
|
-
};
|
|
62
|
+
getSubscription
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=sanityConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sanityConnector.js"],"names":["withConfig","config","sanityClient","draftId","nonDraftDoc","_id","prepareDocumentList","incoming","apiVersion","Promise","resolve","documents","Array","isArray","ids","filter","doc","startsWith","map","fetch","then","drafts","outgoing","foundDraft","find","draft","catch","error","Error","message","getSubscription","query","params","listen","events","includeResult","visibility","pipe","event","type","JSON","stringify","module","exports"],"mappings":";;AAAA;;AACA;;AACA;;AACA;;;;AAEA,IAAMA,UAAU,GAAGC,MAAM,IAAI;AAC3B,SAAO,OAAOC,gBAAaF,UAApB,KAAmC,UAAnC,GACHE,gBAAaF,UAAb,CAAwBC,MAAxB,CADG,GAEHC,eAFJ;AAGD,CAJD;;AAMA,IAAMC,OAAO,GAAGC,WAAW,qBAAcA,WAAW,CAACC,GAA1B,CAA3B;;AAEA,IAAMC,mBAAmB,GAAG,CAACC,QAAD,EAAWC,UAAX,KAA0B;AACpD,MAAI,CAACD,QAAL,EAAe;AACb,WAAOE,OAAO,CAACC,OAAR,CAAgB,EAAhB,CAAP;AACD;;AACD,MAAMC,SAAS,GAAGC,KAAK,CAACC,OAAN,CAAcN,QAAd,IAA0BA,QAA1B,GAAqC,CAACA,QAAD,CAAvD;AAEA,MAAMO,GAAG,GAAGH,SAAS,CAClBI,MADS,CACFC,GAAG,IAAI,CAACA,GAAG,CAACX,GAAJ,CAAQY,UAAR,CAAmB,SAAnB,CADN,EAETC,GAFS,CAELf,OAFK,CAAZ;AAIA,SAAOH,UAAU,CAAC;AAACQ,IAAAA;AAAD,G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;AACd,QAAIA,KAAK,CAACE,OAAN,CAAcZ,UAAd,CAAyB,wBAAzB,CAAJ,EAAwD;AACtD,YAAMU,KAAN;AACD;;AACD,UAAM,IAAIC,KAAJ,wBAA0BG,KAA1B,kBAAuCS,IAAI,CAACC,SAAL,CAAeT,MAAf,CAAvC,sBAAyEL,KAAK,CAACE,OAA/E,EAAN;AACD,GATY,CAAf,CAFK,CAAP;AAaD,CAdK,CAFR,CADF;;AAoBAa,MAAM,CAACC,OAAP,GAAiB;AACfb,EAAAA;AADe,CAAjB","sourcesContent":["import {of as observableOf} from 'rxjs'\nimport {switchMap, delay, tap, mergeMap} from 'rxjs/operators'\nimport {uniqBy} from 'lodash'\nimport sanityClient from 'part:@sanity/base/client'\n\nconst withConfig = config => {\n return typeof sanityClient.withConfig === 'function'\n ? sanityClient.withConfig(config)\n : sanityClient\n}\n\nconst draftId = nonDraftDoc => `drafts.${nonDraftDoc._id}`\n\nconst prepareDocumentList = (incoming, apiVersion) => {\n if (!incoming) {\n return Promise.resolve([])\n }\n const documents = Array.isArray(incoming) ? incoming : [incoming]\n\n const ids = documents\n .filter(doc => !doc._id.startsWith('drafts.'))\n .map(draftId)\n\n return withConfig({apiVersion}).fetch('*[_id in $ids]', {ids})\n .then(drafts => {\n const outgoing = documents.map(doc => {\n const foundDraft = drafts.find(draft => draft._id === draftId(doc))\n return foundDraft || doc\n })\n return uniqBy(outgoing, '_id')\n })\n .catch(error => {\n throw new Error(`Problems fetching docs ${ids}. Error: ${error.message}`)\n })\n}\n\nconst getSubscription = (query, params, apiVersion) =>\n withConfig({apiVersion})\n .listen(query, params, {events: ['welcome', 'mutation'], includeResult: false, visibility: 'query'})\n .pipe(switchMap(event => {\n return observableOf(1).pipe(\n event.type === 'welcome' ? tap() : delay(1000),\n mergeMap(() => withConfig({apiVersion}).fetch(query, params)\n .then(incoming => {\n return prepareDocumentList(incoming, apiVersion)\n })\n .catch(error => {\n if (error.message.startsWith('Problems fetching docs')) {\n throw error\n }\n throw new Error(`Query failed ${query} and ${JSON.stringify(params)}. Error: ${error.message}`)\n }))\n )\n }))\n\n\nmodule.exports = {\n getSubscription\n}\n"],"file":"sanityConnector.js"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"public": true,
|
|
3
2
|
"name": "sanity-plugin-dashboard-widget-document-list",
|
|
4
|
-
"version": "0.0
|
|
5
|
-
"author": "Sanity.io <hello@sanity.io>",
|
|
3
|
+
"version": "0.1.0",
|
|
6
4
|
"description": "Example dashboard widget for Sanity Content Studio",
|
|
7
|
-
"homepage": "https://github.com/sanity-io/dashboard-widget-document-list#readme",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"sanity",
|
|
10
7
|
"plugin",
|
|
@@ -13,41 +10,43 @@
|
|
|
13
10
|
"widget",
|
|
14
11
|
"documents"
|
|
15
12
|
],
|
|
16
|
-
"
|
|
17
|
-
"license": "MIT",
|
|
13
|
+
"homepage": "https://github.com/sanity-io/dashboard-widget-document-list#readme",
|
|
18
14
|
"bugs": {
|
|
19
15
|
"url": "https://github.com/sanity-io/dashboard-widget-document-list/issues"
|
|
20
16
|
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git@github.com:sanity-io/dashboard-widget-document-list.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
23
|
+
"main": "lib/index.js",
|
|
21
24
|
"scripts": {
|
|
22
|
-
"build": "babel src -d lib --copy-files",
|
|
23
|
-
"clean": "rimraf lib",
|
|
24
25
|
"prebuild": "npm run clean",
|
|
25
|
-
"
|
|
26
|
+
"build": "sanipack build",
|
|
27
|
+
"clean": "rimraf lib",
|
|
28
|
+
"prepublishOnly": "npm run build && npm test",
|
|
29
|
+
"test": "sanipack verify"
|
|
26
30
|
},
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"lodash": "^4.17.15",
|
|
33
|
+
"prop-types": "^15.7.2",
|
|
34
|
+
"rxjs": "^6.0.0"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
32
|
-
"
|
|
37
|
+
"@commitlint/cli": "^17.1.2",
|
|
38
|
+
"@commitlint/config-conventional": "^17.1.0",
|
|
39
|
+
"@sanity/semantic-release-preset": "^2.0.1",
|
|
33
40
|
"babel-eslint": "^7.2.3",
|
|
34
|
-
"babel-plugin-syntax-class-properties": "^6.13.0",
|
|
35
|
-
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
36
|
-
"babel-preset-es2015": "^6.24.1",
|
|
37
|
-
"babel-preset-react": "^6.24.1",
|
|
38
41
|
"eslint": "^4.3.0",
|
|
39
42
|
"eslint-config-sanity": "^2.1.4",
|
|
40
43
|
"eslint-plugin-react": "^7.1.0",
|
|
41
|
-
"rimraf": "^2.
|
|
44
|
+
"rimraf": "^2.7.1",
|
|
45
|
+
"sanipack": "^1.0.8"
|
|
42
46
|
},
|
|
43
47
|
"peerDependencies": {
|
|
44
|
-
"@sanity/base": "
|
|
45
|
-
"
|
|
46
|
-
"prop-types": "^15.6 || ^16 || ^17",
|
|
47
|
-
"react": "^16 || ^17",
|
|
48
|
-
"rxjs": "^6.1.0"
|
|
48
|
+
"@sanity/base": ">=1",
|
|
49
|
+
"react": "^16 || ^17"
|
|
49
50
|
},
|
|
50
|
-
"
|
|
51
|
-
"lodash": "^4.17.15"
|
|
52
|
-
}
|
|
51
|
+
"public": true
|
|
53
52
|
}
|
package/sanity.json
CHANGED
package/.babelrc
DELETED
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/lib
|