cozy-harvest-lib 22.5.7 → 22.5.8
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/CHANGELOG.md +11 -0
- package/dist/connections/accounts.js +0 -19
- package/dist/datacards/ViewerModal.js +26 -1
- package/dist/helpers/queries.js +19 -0
- package/package.json +2 -2
- package/src/connections/accounts.js +0 -18
- package/src/datacards/ViewerModal.jsx +39 -1
- package/src/helpers/queries.js +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [22.5.8](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@22.5.7...cozy-harvest-lib@22.5.8) (2024-03-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Use sourceAccountIdentifier and konnector slug to show viewer modal ([4d0957c](https://github.com/cozy/cozy-libs/commit/4d0957c657b5edc91c8557bd2404081f5dfbe42d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [22.5.7](https://github.com/cozy/cozy-libs/compare/cozy-harvest-lib@22.5.6...cozy-harvest-lib@22.5.7) (2024-03-27)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -67,25 +67,6 @@ export var createAccount = /*#__PURE__*/function () {
|
|
|
67
67
|
return _ref.apply(this, arguments);
|
|
68
68
|
};
|
|
69
69
|
}();
|
|
70
|
-
/**
|
|
71
|
-
* Build an account query for the given konnector.
|
|
72
|
-
* ("getById" throws an error even if the query is not enabled)
|
|
73
|
-
* @param {string} accountId - io.cozy.accounts document's id
|
|
74
|
-
* @returns {object} - a query spec
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
export var buildAccountQueryById = function buildAccountQueryById(accountId) {
|
|
78
|
-
return {
|
|
79
|
-
definition: function definition() {
|
|
80
|
-
return Q(ACCOUNTS_DOCTYPE).where({
|
|
81
|
-
_id: accountId
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
options: {
|
|
85
|
-
as: "".concat(ACCOUNTS_DOCTYPE, "/").concat(accountId)
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
70
|
export var createAccountQuerySpec = function createAccountQuerySpec(accountId) {
|
|
90
71
|
if (!accountId) {
|
|
91
72
|
throw new Error('createAccountQuerySpec called with undefined accountId');
|
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
import React, { useContext } from 'react';
|
|
2
2
|
import { useParams } from 'react-router-dom';
|
|
3
|
+
import { models, useQuery } from 'cozy-client';
|
|
3
4
|
import Viewer from 'cozy-ui/transpiled/react/Viewer';
|
|
4
5
|
import Overlay from 'cozy-ui/transpiled/react/deprecated/Overlay';
|
|
5
6
|
import { useDataCardFiles } from './useDataCardFiles';
|
|
6
7
|
import { MountPointContext } from '../components/MountPointContext';
|
|
8
|
+
import { buildAccountQueryById } from '../helpers/queries';
|
|
7
9
|
export var ViewerModal = function ViewerModal() {
|
|
10
|
+
var _accountResult$data;
|
|
11
|
+
|
|
8
12
|
var _useParams = useParams(),
|
|
9
13
|
accountId = _useParams.accountId,
|
|
10
14
|
folderToSaveId = _useParams.folderToSaveId,
|
|
11
15
|
fileIndex = _useParams.fileIndex;
|
|
12
16
|
|
|
17
|
+
var buildAccountQuery = buildAccountQueryById(accountId);
|
|
18
|
+
var accountResult = useQuery(buildAccountQuery.definition, buildAccountQuery.options);
|
|
19
|
+
var sourceAccountIdentifier = models.account.getAccountName(accountResult.data);
|
|
20
|
+
var konnectorSlug = (_accountResult$data = accountResult.data) === null || _accountResult$data === void 0 ? void 0 : _accountResult$data.account_type;
|
|
21
|
+
if (!sourceAccountIdentifier || !konnectorSlug) return /*#__PURE__*/React.createElement(Overlay, null);
|
|
22
|
+
return /*#__PURE__*/React.createElement(ViewerModalContent, {
|
|
23
|
+
sourceAccountIdentifier: sourceAccountIdentifier,
|
|
24
|
+
folderToSaveId: folderToSaveId,
|
|
25
|
+
konnectorSlug: konnectorSlug,
|
|
26
|
+
accountId: accountId,
|
|
27
|
+
fileIndex: fileIndex
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
var ViewerModalContent = function ViewerModalContent(_ref) {
|
|
32
|
+
var sourceAccountIdentifier = _ref.sourceAccountIdentifier,
|
|
33
|
+
folderToSaveId = _ref.folderToSaveId,
|
|
34
|
+
konnectorSlug = _ref.konnectorSlug,
|
|
35
|
+
accountId = _ref.accountId,
|
|
36
|
+
fileIndex = _ref.fileIndex;
|
|
37
|
+
|
|
13
38
|
var _useContext = useContext(MountPointContext),
|
|
14
39
|
pushHistory = _useContext.pushHistory,
|
|
15
40
|
replaceHistory = _useContext.replaceHistory;
|
|
16
41
|
|
|
17
|
-
var _useDataCardFiles = useDataCardFiles(
|
|
42
|
+
var _useDataCardFiles = useDataCardFiles(sourceAccountIdentifier, folderToSaveId, konnectorSlug),
|
|
18
43
|
data = _useDataCardFiles.data,
|
|
19
44
|
fetchStatus = _useDataCardFiles.fetchStatus;
|
|
20
45
|
|
package/dist/helpers/queries.js
CHANGED
|
@@ -45,6 +45,25 @@ export var buildAccountQuery = function buildAccountQuery(_ref) {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Build an account query for the given konnector.
|
|
50
|
+
* ("getById" throws an error even if the query is not enabled)
|
|
51
|
+
* @param {string} accountId - io.cozy.accounts document's id
|
|
52
|
+
* @returns {object} - a query spec
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
export var buildAccountQueryById = function buildAccountQueryById(accountId) {
|
|
56
|
+
return {
|
|
57
|
+
definition: function definition() {
|
|
58
|
+
return Q('io.cozy.accounts').getById(accountId);
|
|
59
|
+
},
|
|
60
|
+
options: {
|
|
61
|
+
as: "io.cozy.accounts/".concat(accountId),
|
|
62
|
+
fetchPolicy: defaultFetchPolicy,
|
|
63
|
+
singleDocData: true
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
48
67
|
/**
|
|
49
68
|
*
|
|
50
69
|
* @param {string} accountId
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-harvest-lib",
|
|
3
|
-
"version": "22.5.
|
|
3
|
+
"version": "22.5.8",
|
|
4
4
|
"description": "Provides logic, modules and components for Cozy's harvest applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "Cozy",
|
|
@@ -107,5 +107,5 @@
|
|
|
107
107
|
"react-router-dom": ">=4.3.1"
|
|
108
108
|
},
|
|
109
109
|
"sideEffects": false,
|
|
110
|
-
"gitHead": "
|
|
110
|
+
"gitHead": "3b3ca64c85bea9c98061b1dac7c234b0b3fba508"
|
|
111
111
|
}
|
|
@@ -24,24 +24,6 @@ export const createAccount = async (client, konnector, attributes) => {
|
|
|
24
24
|
return data
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Build an account query for the given konnector.
|
|
29
|
-
* ("getById" throws an error even if the query is not enabled)
|
|
30
|
-
* @param {string} accountId - io.cozy.accounts document's id
|
|
31
|
-
* @returns {object} - a query spec
|
|
32
|
-
*/
|
|
33
|
-
export const buildAccountQueryById = accountId => {
|
|
34
|
-
return {
|
|
35
|
-
definition: () =>
|
|
36
|
-
Q(ACCOUNTS_DOCTYPE).where({
|
|
37
|
-
_id: accountId
|
|
38
|
-
}),
|
|
39
|
-
options: {
|
|
40
|
-
as: `${ACCOUNTS_DOCTYPE}/${accountId}`
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
27
|
export const createAccountQuerySpec = accountId => {
|
|
46
28
|
if (!accountId) {
|
|
47
29
|
throw new Error('createAccountQuerySpec called with undefined accountId')
|
|
@@ -1,16 +1,54 @@
|
|
|
1
1
|
import React, { useContext } from 'react'
|
|
2
2
|
import { useParams } from 'react-router-dom'
|
|
3
3
|
|
|
4
|
+
import { models, useQuery } from 'cozy-client'
|
|
4
5
|
import Viewer from 'cozy-ui/transpiled/react/Viewer'
|
|
5
6
|
import Overlay from 'cozy-ui/transpiled/react/deprecated/Overlay'
|
|
6
7
|
|
|
7
8
|
import { useDataCardFiles } from './useDataCardFiles'
|
|
8
9
|
import { MountPointContext } from '../components/MountPointContext'
|
|
10
|
+
import { buildAccountQueryById } from '../helpers/queries'
|
|
9
11
|
|
|
10
12
|
export const ViewerModal = () => {
|
|
11
13
|
const { accountId, folderToSaveId, fileIndex } = useParams()
|
|
14
|
+
|
|
15
|
+
const buildAccountQuery = buildAccountQueryById(accountId)
|
|
16
|
+
const accountResult = useQuery(
|
|
17
|
+
buildAccountQuery.definition,
|
|
18
|
+
buildAccountQuery.options
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
const sourceAccountIdentifier = models.account.getAccountName(
|
|
22
|
+
accountResult.data
|
|
23
|
+
)
|
|
24
|
+
const konnectorSlug = accountResult.data?.account_type
|
|
25
|
+
|
|
26
|
+
if (!sourceAccountIdentifier || !konnectorSlug) return <Overlay />
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<ViewerModalContent
|
|
30
|
+
sourceAccountIdentifier={sourceAccountIdentifier}
|
|
31
|
+
folderToSaveId={folderToSaveId}
|
|
32
|
+
konnectorSlug={konnectorSlug}
|
|
33
|
+
accountId={accountId}
|
|
34
|
+
fileIndex={fileIndex}
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const ViewerModalContent = ({
|
|
40
|
+
sourceAccountIdentifier,
|
|
41
|
+
folderToSaveId,
|
|
42
|
+
konnectorSlug,
|
|
43
|
+
accountId,
|
|
44
|
+
fileIndex
|
|
45
|
+
}) => {
|
|
12
46
|
const { pushHistory, replaceHistory } = useContext(MountPointContext)
|
|
13
|
-
const { data, fetchStatus } = useDataCardFiles(
|
|
47
|
+
const { data, fetchStatus } = useDataCardFiles(
|
|
48
|
+
sourceAccountIdentifier,
|
|
49
|
+
folderToSaveId,
|
|
50
|
+
konnectorSlug
|
|
51
|
+
)
|
|
14
52
|
const handleCloseViewer = () => replaceHistory(`/accounts/${accountId}`)
|
|
15
53
|
const handleFileChange = (_file, newIndex) =>
|
|
16
54
|
pushHistory(`/viewer/${accountId}/${folderToSaveId}/${newIndex}`)
|
package/src/helpers/queries.js
CHANGED
|
@@ -38,6 +38,24 @@ export const buildAccountQuery = ({ slug, sourceAccountIdentifier }) => ({
|
|
|
38
38
|
fetchPolicy: defaultFetchPolicy
|
|
39
39
|
}
|
|
40
40
|
})
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Build an account query for the given konnector.
|
|
44
|
+
* ("getById" throws an error even if the query is not enabled)
|
|
45
|
+
* @param {string} accountId - io.cozy.accounts document's id
|
|
46
|
+
* @returns {object} - a query spec
|
|
47
|
+
*/
|
|
48
|
+
export const buildAccountQueryById = accountId => {
|
|
49
|
+
return {
|
|
50
|
+
definition: () => Q('io.cozy.accounts').getById(accountId),
|
|
51
|
+
options: {
|
|
52
|
+
as: `io.cozy.accounts/${accountId}`,
|
|
53
|
+
fetchPolicy: defaultFetchPolicy,
|
|
54
|
+
singleDocData: true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
41
59
|
/**
|
|
42
60
|
*
|
|
43
61
|
* @param {string} accountId
|