@axinom/mosaic-fe-samples-host 0.14.0-rc.7 → 0.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axinom/mosaic-fe-samples-host",
3
- "version": "0.14.0-rc.7",
3
+ "version": "0.14.0",
4
4
  "description": "The host application, React components and hooks used when developing fe-sample scenarios",
5
5
  "author": "Axinom",
6
6
  "license": "PROPRIETARY",
@@ -83,5 +83,5 @@
83
83
  "publishConfig": {
84
84
  "access": "public"
85
85
  },
86
- "gitHead": "cd9cccfc54ca4179d9cfba424f99e30e455cbd48"
86
+ "gitHead": "ba7e5a51c2203d2ae44fa62461e0a66eadaa80f4"
87
87
  }
@@ -136,6 +136,91 @@ export const Profiles: React.FC<ProfileProps> = ({ match }) => {
136
136
  }
137
137
  };
138
138
 
139
+ const handleExportProfileClick = () => {
140
+ const activeProfileIndex = profiles.findIndex(
141
+ (env) => env.id === selectedProfile?.id,
142
+ );
143
+
144
+ if (activeProfileIndex !== -1 && selectedProfile !== undefined) {
145
+ const fileDownloadLink = document.createElement('a');
146
+ fileDownloadLink.href = URL.createObjectURL(
147
+ new Blob([JSON.stringify(selectedProfile, null, 2)], {
148
+ type: 'application/json',
149
+ }),
150
+ );
151
+ fileDownloadLink.setAttribute(
152
+ 'download',
153
+ `fe-samples-${selectedProfile.name}.json`,
154
+ );
155
+ document.body.appendChild(fileDownloadLink);
156
+ fileDownloadLink.click();
157
+ document.body.removeChild(fileDownloadLink);
158
+ }
159
+ };
160
+
161
+ const handleImportProfileClick = () => {
162
+ document.getElementById('fileInput')?.click();
163
+
164
+ // Event listener for file input change
165
+ document
166
+ .getElementById('fileInput')
167
+ ?.addEventListener('change', function (event) {
168
+ if (event && event.target) {
169
+ const inputElement = event.target as HTMLInputElement;
170
+
171
+ // Handle the selected file
172
+ if (inputElement) {
173
+ const file = inputElement.files?.[0];
174
+
175
+ if (file) {
176
+ const reader = new FileReader();
177
+
178
+ reader.onload = function (e) {
179
+ const fileContent = e.target?.result;
180
+
181
+ // Save file content to local storage
182
+ saveToLocalStorage(fileContent);
183
+
184
+ // Reset the file input value to clear it
185
+ inputElement.value = '';
186
+ };
187
+
188
+ reader.readAsText(file);
189
+ } else {
190
+ console.error(`[importProfile]: Please select a file.`);
191
+ }
192
+ }
193
+ }
194
+ });
195
+ };
196
+
197
+ const saveToLocalStorage = (fileContent: any) => {
198
+ const importedProfile = JSON.parse(fileContent);
199
+
200
+ const profileAlreadyExists = profiles.find(
201
+ (profile) => profile.id === importedProfile?.id,
202
+ );
203
+
204
+ if (profileAlreadyExists === undefined) {
205
+ // Add new data to the profiles array
206
+ profiles.push(importedProfile);
207
+
208
+ setProfiles([...profiles]);
209
+ saveAllProfiles(profiles);
210
+ } else {
211
+ const existProfileIndex = profiles.findIndex(
212
+ (profile) => profile.id === importedProfile?.id,
213
+ );
214
+
215
+ if (existProfileIndex !== -1) {
216
+ profiles[existProfileIndex] = importedProfile;
217
+
218
+ setProfiles([...profiles]);
219
+ saveAllProfiles(profiles);
220
+ }
221
+ }
222
+ };
223
+
139
224
  /**
140
225
  * A common input changed handler used for all top-level profile fields (i.e. URLs)
141
226
  */
@@ -254,9 +339,23 @@ export const Profiles: React.FC<ProfileProps> = ({ match }) => {
254
339
  >
255
340
  Production Profile
256
341
  </Dropdown.Item>
342
+ <Dropdown.Item
343
+ data-test-id="import-from-file"
344
+ onClick={handleImportProfileClick}
345
+ >
346
+ Import Profile From File
347
+ </Dropdown.Item>
257
348
  </Dropdown.Menu>
258
349
  </Dropdown>
259
350
 
351
+ {/* Invisible file input */}
352
+ <input
353
+ id="fileInput"
354
+ type="file"
355
+ accept=".json"
356
+ hidden={true}
357
+ ></input>
358
+
260
359
  <Button
261
360
  basic
262
361
  data-test-id="scenarios-button"
@@ -312,6 +411,13 @@ export const Profiles: React.FC<ProfileProps> = ({ match }) => {
312
411
  content="Delete"
313
412
  onClick={handleDeleteProfileClick}
314
413
  />
414
+ <Button
415
+ basic
416
+ color="blue"
417
+ floated="right"
418
+ content="Export"
419
+ onClick={handleExportProfileClick}
420
+ />
315
421
  </Header>
316
422
 
317
423
  <Form>