@integration-app/react 0.2.0 → 0.2.1
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 +49 -34
- package/dist/index.d.ts +24 -13
- package/dist/index.js +41 -26
- package/dist/index.js.map +1 -1
- package/dist/index.module.d.ts +24 -13
- package/dist/index.module.mjs +41 -27
- package/dist/index.module.mjs.map +1 -1
- package/dist/index.umd.d.ts +24 -13
- package/dist/index.umd.js +41 -26
- package/dist/index.umd.js.map +1 -1
- package/package.json +13 -9
- package/rollup.dts.config.mjs +21 -0
- package/src/contexts/integration-app-context.tsx +11 -2
- package/src/data-sources/useDataSourceInstances.ts +16 -0
- package/src/field-mappings/useFieldMappingInstance.ts +2 -2
- package/src/field-mappings/useFieldMappingInstances.ts +2 -2
- package/src/flows/useFlow.ts +7 -6
- package/src/flows/useFlowTemplate.ts +0 -0
- package/src/flows/useFlowTemplates.ts +0 -0
- package/src/hooks/useElement.tsx +41 -23
- package/src/index.tsx +2 -2
- package/rollup.config.mjs +0 -64
- /package/src/integrations/{useConnectionSpec.ts → useConnectorSpec.ts} +0 -0
package/src/hooks/useElement.tsx
CHANGED
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
ElementInstanceAccessor,
|
5
5
|
} from '@integration-app/sdk'
|
6
6
|
import { useEffect, useState } from 'react'
|
7
|
-
import { useIntegrationApp } from '
|
7
|
+
import { useIntegrationApp } from 'contexts/integration-app-context'
|
8
8
|
|
9
9
|
interface ElementHookResult<
|
10
10
|
ElementInterface,
|
@@ -88,6 +88,19 @@ export function useElement<
|
|
88
88
|
const [error, setError] = useState<Error>(null)
|
89
89
|
const [refreshCounter, setRefreshCounter] = useState(0)
|
90
90
|
|
91
|
+
function updateDataWith(newData) {
|
92
|
+
if (data !== undefined) {
|
93
|
+
setData({
|
94
|
+
...data,
|
95
|
+
...newData,
|
96
|
+
})
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
function replaceDataWith(newData) {
|
101
|
+
setData(newData)
|
102
|
+
}
|
103
|
+
|
91
104
|
const selector = (props as any)?.id
|
92
105
|
? (props as { id: string }).id
|
93
106
|
: (props as SelectorInterface)
|
@@ -99,7 +112,7 @@ export function useElement<
|
|
99
112
|
useEffect(() => {
|
100
113
|
setLoading(true)
|
101
114
|
setError(null)
|
102
|
-
if (integrationApp) {
|
115
|
+
if (integrationApp && selector) {
|
103
116
|
accessor
|
104
117
|
.get()
|
105
118
|
.then(setData)
|
@@ -112,16 +125,21 @@ export function useElement<
|
|
112
125
|
),
|
113
126
|
)
|
114
127
|
}
|
115
|
-
}, [
|
128
|
+
}, [
|
129
|
+
integrationApp,
|
130
|
+
JSON.stringify(selector),
|
131
|
+
JSON.stringify(props),
|
132
|
+
refreshCounter,
|
133
|
+
])
|
116
134
|
|
117
135
|
async function create(createData: CreateRequest) {
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
return
|
136
|
+
// Because `createData` do not contain all critical fields
|
137
|
+
// we do not update state with `createData` to avoid problem
|
138
|
+
// with missing critical fields like `id`
|
139
|
+
|
140
|
+
const returnedData = await accessor.create(createData)
|
141
|
+
replaceDataWith(returnedData)
|
142
|
+
return returnedData
|
125
143
|
}
|
126
144
|
|
127
145
|
function refresh() {
|
@@ -130,29 +148,29 @@ export function useElement<
|
|
130
148
|
|
131
149
|
async function patch(patch: UpdateRequest) {
|
132
150
|
if (typeof patch === 'object') {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
151
|
+
updateDataWith(patch ?? {})
|
152
|
+
|
153
|
+
// TODO: PL-3550
|
154
|
+
// PATCH could response with modified fields that do not exist in `patch`
|
155
|
+
// but this data could be outdated because of other methods calls
|
156
|
+
return accessor.patch(patch)
|
138
157
|
} else {
|
139
158
|
return data
|
140
159
|
}
|
141
160
|
}
|
142
161
|
|
143
162
|
async function put(putData: CreateRequest) {
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
return accessorGenerator(integrationApp)(selector).put(putData)
|
163
|
+
updateDataWith(putData)
|
164
|
+
|
165
|
+
// TODO: PL-3550
|
166
|
+
// PUT could response with modified fields that do not exist in `patch`
|
167
|
+
// but this data could be outdated because of other methods calls
|
168
|
+
return await accessor.put(putData)
|
151
169
|
}
|
152
170
|
|
153
171
|
async function archive() {
|
154
172
|
setData(null)
|
155
|
-
return
|
173
|
+
return accessor.archive()
|
156
174
|
}
|
157
175
|
|
158
176
|
return {
|
package/src/index.tsx
CHANGED
@@ -3,7 +3,7 @@ export {
|
|
3
3
|
IntegrationAppProvider,
|
4
4
|
} from './contexts/integration-app-context.js'
|
5
5
|
|
6
|
-
export { useConnectorSpec } from './integrations/
|
6
|
+
export { useConnectorSpec } from './integrations/useConnectorSpec.js'
|
7
7
|
export { useIntegration } from './integrations/useIntegration.js'
|
8
8
|
export { useIntegrations } from './integrations/useIntegrations.js'
|
9
9
|
export { useConnection } from './integrations/useConnection.js'
|
@@ -11,13 +11,13 @@ export { useConnections } from './integrations/useConnections.js'
|
|
11
11
|
|
12
12
|
export { useFieldMapping } from './field-mappings/useFieldMapping.js'
|
13
13
|
export { useFieldMappings } from './field-mappings/useFieldMappings.js'
|
14
|
-
|
15
14
|
export { useFieldMappingInstance } from './field-mappings/useFieldMappingInstance.js'
|
16
15
|
export { useFieldMappingInstances } from './field-mappings/useFieldMappingInstances.js'
|
17
16
|
|
18
17
|
export { useDataSource } from './data-sources/useDataSource.js'
|
19
18
|
export { useDataSources } from './data-sources/useDataSources.js'
|
20
19
|
export { useDataSourceInstance } from './data-sources/useDataSourceInstance.js'
|
20
|
+
export { useDataSourceInstances } from './data-sources/useDataSourceInstances.js'
|
21
21
|
export { useDataSourceInstanceCollection as useDataSourceCollection } from './data-sources/useDataSourceInstanceCollection.js'
|
22
22
|
export { useDataSourceInstanceLocations as useDataSourceLocations } from './data-sources/useDataSourceInstanceLocations.js'
|
23
23
|
export { useDataSourceEvents } from './data-sources/useDataSourceEvents.js'
|
package/rollup.config.mjs
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
// Compile TypeScript files
|
2
|
-
import typescript from '@rollup/plugin-typescript'
|
3
|
-
// Convert CommonJS modules to ES6, so they can be included in a Rollup bundle
|
4
|
-
import commonjs from '@rollup/plugin-commonjs'
|
5
|
-
// Locate modules using the Node resolution algorithm, for using third party modules in node_modules
|
6
|
-
import nodeResolve from '@rollup/plugin-node-resolve'
|
7
|
-
// Flat dts files into one
|
8
|
-
import dts from 'rollup-plugin-dts'
|
9
|
-
// Convert .json files to ES6 modules
|
10
|
-
import rollupJson from '@rollup/plugin-json'
|
11
|
-
|
12
|
-
const config = [
|
13
|
-
{
|
14
|
-
input: './src/index.tsx',
|
15
|
-
output: [
|
16
|
-
{
|
17
|
-
// CommonJS bundle
|
18
|
-
file: './dist/index.js',
|
19
|
-
format: 'cjs',
|
20
|
-
sourcemap: true,
|
21
|
-
},
|
22
|
-
{
|
23
|
-
// ESM bundle
|
24
|
-
file: './dist/index.module.mjs',
|
25
|
-
format: 'esm',
|
26
|
-
sourcemap: true,
|
27
|
-
},
|
28
|
-
{
|
29
|
-
// Universal Module Definition, works as `amd`, `cjs` and `iife` all in one
|
30
|
-
file: './dist/index.umd.js',
|
31
|
-
format: 'umd',
|
32
|
-
name: 'integrationAppReact',
|
33
|
-
sourcemap: true,
|
34
|
-
},
|
35
|
-
],
|
36
|
-
external: [/node_modules/, '@integration-app/sdk'],
|
37
|
-
plugins: [
|
38
|
-
typescript({
|
39
|
-
tsconfig: 'tsconfig.json',
|
40
|
-
}),
|
41
|
-
commonjs(),
|
42
|
-
nodeResolve({
|
43
|
-
browser: true,
|
44
|
-
}),
|
45
|
-
rollupJson(),
|
46
|
-
],
|
47
|
-
},
|
48
|
-
// Generate dts files for each bundle from *.d.ts files
|
49
|
-
{
|
50
|
-
input: './dist/dts/index.d.ts',
|
51
|
-
output: [
|
52
|
-
{ file: 'dist/index.d.ts', format: 'commonjs' },
|
53
|
-
{ file: 'dist/index.module.d.ts', format: 'es' },
|
54
|
-
{
|
55
|
-
file: 'dist/index.umd.d.ts',
|
56
|
-
format: 'umd',
|
57
|
-
name: 'integrationAppReact',
|
58
|
-
},
|
59
|
-
],
|
60
|
-
plugins: [dts()],
|
61
|
-
},
|
62
|
-
]
|
63
|
-
|
64
|
-
export default config
|
File without changes
|