@hopara/iframe 0.2.2 → 0.2.4

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 CHANGED
@@ -1,15 +1,12 @@
1
1
  # Hopara Iframe Client
2
- The Hopara Iframe Client enables you to embed an Hopara App on your web site.
2
+ This package provides an iframe to add [Hopara](https://hopara.io) visualizations to your project.
3
3
 
4
4
  # Installing
5
- Using npm:
6
- ```shell
7
- $ npm install @hopara/iframe
8
- ```
5
+ You can install it as a NPM module or using Hopara CDN directly:
9
6
 
10
- Using yarn:
7
+ As a module:
11
8
  ```shell
12
- $ yarn add @hopara/iframe
9
+ $ npm install @hopara/iframe
13
10
  ```
14
11
 
15
12
  Using Hopara CDN:
@@ -17,8 +14,11 @@ Using Hopara CDN:
17
14
  <script src="https://statics.hopara.app/embedded/latest/client.js"></script>
18
15
  ```
19
16
 
17
+ ## Authentication
18
+ The iframe requires a valid `accessToken`. Use the `Auth API` to fetch it, as explained in our [integration guide](https://docs.hopara.app/docs/integration-guide/authentication-integration.html)
19
+
20
20
  # Example
21
- ### React
21
+ ### Node.JS
22
22
  ```js
23
23
  import React from 'react'
24
24
  import Hopara from 'hopara'
@@ -73,10 +73,10 @@ Hopara.init(config)
73
73
  // The app id
74
74
  app: string
75
75
 
76
- // The accessToken fetched from the auth API
76
+ // The accessToken provided by auth API
77
77
  accessToken: string
78
78
 
79
- // Overwrites the data at render time
79
+ // Overwrites data at rendering time
80
80
  dataLoaders: DataLoader[] | undefined
81
81
 
82
82
  // Provides a custom ways to update data
@@ -89,4 +89,123 @@ Hopara.init(config)
89
89
  initialRow: InitialRow | undefined
90
90
  }
91
91
  ```
92
- for more information about the initialization props go to our [@hopara/react](https://www.npmjs.com/package/@hopara/react) module
92
+
93
+ ### Data Loader
94
+ By default Hopara will load the same visualization and data as seen as in hopara.app. You can use the data loader prop to provide a custom way to load the data.
95
+
96
+ ```typescript
97
+ type DataLoader = {
98
+ // query name
99
+ name: string
100
+
101
+ // data source name
102
+ source: string
103
+
104
+ // callback to be used on data load
105
+ loader: (filterSet: {limit: number, offset:number, filters: any[]}) => Promise<Record<string, any>[]>
106
+ }
107
+ ```
108
+
109
+
110
+ #### Example
111
+
112
+ ```javascript
113
+ const customDataLoaders = [{
114
+ name: 'queryName',
115
+ source: 'dataSourceName',
116
+ loader: () => {
117
+ return [
118
+ {
119
+ id: 1,
120
+ name: 'Eiffel Tower',
121
+ country: 'France',
122
+ longitude: 48.85845461500544,
123
+ latitude: 2.294467845588995
124
+ },
125
+ {
126
+ id: 2,
127
+ name: 'Liberty Statue',
128
+ country: 'USA',
129
+ longitude: 40.68815550804761,
130
+ latitude: -74.02620077137483
131
+ },
132
+ {
133
+ id: 3,
134
+ name: 'Great Wall of China',
135
+ country: 'China',
136
+ longitude: 40.43211592595951,
137
+ latitude: 116.57040708445938,
138
+ }
139
+ ]
140
+ }
141
+ }]
142
+
143
+ Hopara.init({
144
+ app: 'my-hopara-app',
145
+ accessToken: 'my-hopara-token',
146
+ targetElementId: 'my-target-element',
147
+ dataLoaders: customDataLoaders,
148
+ })
149
+ ```
150
+
151
+ ### Data Updater
152
+ By default Hopara will update the visualization in the same database configured in hopara.app. You can use the data updater prop to provide a custom way to update the data.
153
+
154
+ The data updater is called when placing objetcs in a visualization and when resizing images.
155
+
156
+ ```typescript
157
+ type DataUpdater = {
158
+ // query name
159
+ name: string
160
+
161
+ // data source name
162
+ source: string
163
+
164
+ // callback to be used on data update
165
+ updater: (updatedRow: Record<string, any>, originalRow: Record<string, any>, diff: Partial<Record<string, any>>) => Promise<void>
166
+ }
167
+ ```
168
+
169
+ ```jsx
170
+ const customDataUpdaters = [{
171
+ name: 'queryName',
172
+ source: 'dataSourceName',
173
+ updater: (newRow) => {
174
+ const rowIndex = dataInMemory.findIndex((row) => row.id === newRow.id)
175
+ dataInMemory[rowIndex] = newRow
176
+ }
177
+ }]
178
+
179
+
180
+ Hopara.init({
181
+ app: 'my-hopara-app',
182
+ accessToken: 'my-hopara-token',
183
+ targetElementId: 'my-target-element',
184
+ dataUpdaters: customDataUpdaters,
185
+ })
186
+ ```
187
+
188
+ ### Initial Position
189
+ The initial position prop overrides the initial position of the visualization.
190
+
191
+ ```typescript
192
+ type InitialPosition = {
193
+ latitude: number | undefined
194
+ longitude: number | undefined
195
+ x: number | undefined
196
+ y: number | undefined
197
+ z: number | undefined
198
+ zoom: number | undefined
199
+ bearing: number | undefined
200
+ }
201
+ ```
202
+
203
+ ### Initial Row
204
+ The initial row prop centers the visualization around a specific row (e.g. asset, facility).
205
+
206
+ ```typescript
207
+ type InitialRow = {
208
+ entityId: string
209
+ rowId: string
210
+ }
211
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hopara/iframe",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "main": "build/client.js",
5
5
  "scripts": {
6
6
  "start": "ESLINT_NO_DEV_ERRORS=true react-app-rewired start",
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "devDependencies": {
29
29
  "@babel/register": "^7.15.3",
30
- "@hopara/react": "^0.2.2",
31
- "@hopara/system-test": "^0.2.2",
30
+ "@hopara/react": "^0.2.4",
31
+ "@hopara/system-test": "^0.2.4",
32
32
  "babel-loader": "8.1.0",
33
33
  "customize-cra": "^1.0.0",
34
34
  "react": "^18.2.0",
@@ -19,16 +19,35 @@ module.exports = {
19
19
  browser.setWindowSize(1280, 800)
20
20
  .url('http://localhost:3456/')
21
21
  .execute(() => {
22
- window.postMessage({
23
- app: 'circle',
24
- tenant: 'hopara.io',
25
- accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJ0ZW5hbnRzIjpbImhvcGFyYS5pbyJdLCJzY29wZSI6InJvdzp3cml0ZSJ9.qJwSd1EUmiVX5NrgelVQdn9MDbdVNq4GGjzHPQlDQ1A',
26
- targetElementId: 'embedded-target-element',
27
- __hopara__eventType__: 'init'
28
- }, '*')
22
+ window.postMessage({
23
+ app: 'circle',
24
+ tenant: 'hopara.io',
25
+ accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJ0ZW5hbnRzIjpbImhvcGFyYS5pbyJdLCJzY29wZSI6InJvdzp3cml0ZSJ9.qJwSd1EUmiVX5NrgelVQdn9MDbdVNq4GGjzHPQlDQ1A',
26
+ targetElementId: 'embedded-target-element',
27
+ __hopara__eventType__: 'init'
28
+ }, '*')
29
29
  })
30
30
  .pause(waitTime())
31
31
  .waitForElementVisible('#deckgl-overlay')
32
32
  .assert.compareScreenshot('circle-layer.png', mismatchPercentage)
33
33
  },
34
+ 'Circle Layer With Entites': (browser) => {
35
+ mockServer.get('/app/circle').thenReply(200, JSON.stringify(responses.app.circleWithEntities))
36
+ mockServer.get('/view/queryName/row').thenReply(200, JSON.stringify(responses.geo.circle))
37
+
38
+ browser.setWindowSize(1280, 800)
39
+ .url('http://localhost:3456/')
40
+ .execute(() => {
41
+ window.postMessage({
42
+ app: 'circle',
43
+ tenant: 'hopara.io',
44
+ accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJ0ZW5hbnRzIjpbImhvcGFyYS5pbyJdLCJzY29wZSI6InJvdzp3cml0ZSJ9.qJwSd1EUmiVX5NrgelVQdn9MDbdVNq4GGjzHPQlDQ1A',
45
+ targetElementId: 'embedded-target-element',
46
+ __hopara__eventType__: 'init'
47
+ }, '*')
48
+ })
49
+ .pause(waitTime())
50
+ .waitForElementVisible('#deckgl-overlay')
51
+ .assert.compareScreenshot('circle-layer-with-entities.png', mismatchPercentage)
52
+ },
34
53
  }