@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/dist/Profiles/Profiles.d.ts.map +1 -1
- package/dist/index.es.js +67 -2
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +67 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Profiles/Profiles.tsx +106 -0
package/dist/index.js
CHANGED
|
@@ -612,6 +612,68 @@ const Profiles = ({ match }) => {
|
|
|
612
612
|
history.replace(`/profiles`);
|
|
613
613
|
}
|
|
614
614
|
};
|
|
615
|
+
const handleExportProfileClick = () => {
|
|
616
|
+
const activeProfileIndex = profiles.findIndex((env) => env.id === (selectedProfile === null || selectedProfile === void 0 ? void 0 : selectedProfile.id));
|
|
617
|
+
if (activeProfileIndex !== -1 && selectedProfile !== undefined) {
|
|
618
|
+
const fileDownloadLink = document.createElement('a');
|
|
619
|
+
fileDownloadLink.href = URL.createObjectURL(new Blob([JSON.stringify(selectedProfile, null, 2)], {
|
|
620
|
+
type: 'application/json',
|
|
621
|
+
}));
|
|
622
|
+
fileDownloadLink.setAttribute('download', `fe-samples-${selectedProfile.name}.json`);
|
|
623
|
+
document.body.appendChild(fileDownloadLink);
|
|
624
|
+
fileDownloadLink.click();
|
|
625
|
+
document.body.removeChild(fileDownloadLink);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
const handleImportProfileClick = () => {
|
|
629
|
+
var _a, _b;
|
|
630
|
+
(_a = document.getElementById('fileInput')) === null || _a === void 0 ? void 0 : _a.click();
|
|
631
|
+
// Event listener for file input change
|
|
632
|
+
(_b = document
|
|
633
|
+
.getElementById('fileInput')) === null || _b === void 0 ? void 0 : _b.addEventListener('change', function (event) {
|
|
634
|
+
var _a;
|
|
635
|
+
if (event && event.target) {
|
|
636
|
+
const inputElement = event.target;
|
|
637
|
+
// Handle the selected file
|
|
638
|
+
if (inputElement) {
|
|
639
|
+
const file = (_a = inputElement.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
640
|
+
if (file) {
|
|
641
|
+
const reader = new FileReader();
|
|
642
|
+
reader.onload = function (e) {
|
|
643
|
+
var _a;
|
|
644
|
+
const fileContent = (_a = e.target) === null || _a === void 0 ? void 0 : _a.result;
|
|
645
|
+
// Save file content to local storage
|
|
646
|
+
saveToLocalStorage(fileContent);
|
|
647
|
+
// Reset the file input value to clear it
|
|
648
|
+
inputElement.value = '';
|
|
649
|
+
};
|
|
650
|
+
reader.readAsText(file);
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
console.error(`[importProfile]: Please select a file.`);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
};
|
|
659
|
+
const saveToLocalStorage = (fileContent) => {
|
|
660
|
+
const importedProfile = JSON.parse(fileContent);
|
|
661
|
+
const profileAlreadyExists = profiles.find((profile) => profile.id === (importedProfile === null || importedProfile === void 0 ? void 0 : importedProfile.id));
|
|
662
|
+
if (profileAlreadyExists === undefined) {
|
|
663
|
+
// Add new data to the profiles array
|
|
664
|
+
profiles.push(importedProfile);
|
|
665
|
+
setProfiles([...profiles]);
|
|
666
|
+
saveAllProfiles(profiles);
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
const existProfileIndex = profiles.findIndex((profile) => profile.id === (importedProfile === null || importedProfile === void 0 ? void 0 : importedProfile.id));
|
|
670
|
+
if (existProfileIndex !== -1) {
|
|
671
|
+
profiles[existProfileIndex] = importedProfile;
|
|
672
|
+
setProfiles([...profiles]);
|
|
673
|
+
saveAllProfiles(profiles);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
};
|
|
615
677
|
/**
|
|
616
678
|
* A common input changed handler used for all top-level profile fields (i.e. URLs)
|
|
617
679
|
*/
|
|
@@ -684,7 +746,9 @@ const Profiles = ({ match }) => {
|
|
|
684
746
|
React__default["default"].createElement(semanticUiReact.Dropdown, { "data-test-id": "new-profile-dropdown", text: "New Profile", icon: "dropdown", labeled: true, button: true, floating: true, className: "icon blue", pointing: "top" },
|
|
685
747
|
React__default["default"].createElement(semanticUiReact.Dropdown.Menu, null,
|
|
686
748
|
React__default["default"].createElement(semanticUiReact.Dropdown.Item, { "data-test-id": "new-profile:local", onClick: handleNewProfileClick('local') }, "Local Profile"),
|
|
687
|
-
React__default["default"].createElement(semanticUiReact.Dropdown.Item, { "data-test-id": "new-profile:production", onClick: handleNewProfileClick('production') }, "Production Profile")
|
|
749
|
+
React__default["default"].createElement(semanticUiReact.Dropdown.Item, { "data-test-id": "new-profile:production", onClick: handleNewProfileClick('production') }, "Production Profile"),
|
|
750
|
+
React__default["default"].createElement(semanticUiReact.Dropdown.Item, { "data-test-id": "import-from-file", onClick: handleImportProfileClick }, "Import Profile From File"))),
|
|
751
|
+
React__default["default"].createElement("input", { id: "fileInput", type: "file", accept: ".json", hidden: true }),
|
|
688
752
|
React__default["default"].createElement(semanticUiReact.Button, { basic: true, "data-test-id": "scenarios-button", floated: "right", color: "blue", as: reactRouterDom.Link, to: `/` }, "Scenarios"),
|
|
689
753
|
React__default["default"].createElement(semanticUiReact.Divider, null),
|
|
690
754
|
React__default["default"].createElement(semanticUiReact.List, { link: true }, profiles.map((profile) => {
|
|
@@ -698,7 +762,8 @@ const Profiles = ({ match }) => {
|
|
|
698
762
|
React__default["default"].createElement(semanticUiReact.Header, null, selectedProfile === null || selectedProfile === void 0 ? void 0 :
|
|
699
763
|
selectedProfile.name,
|
|
700
764
|
React__default["default"].createElement(semanticUiReact.Button, { "data-test-id": "save-profile-button", color: "blue", floated: "right", content: "Save", onClick: handleSaveProfileClick }),
|
|
701
|
-
React__default["default"].createElement(semanticUiReact.Button, { basic: true, color: "blue", floated: "right", content: "Delete", onClick: handleDeleteProfileClick })
|
|
765
|
+
React__default["default"].createElement(semanticUiReact.Button, { basic: true, color: "blue", floated: "right", content: "Delete", onClick: handleDeleteProfileClick }),
|
|
766
|
+
React__default["default"].createElement(semanticUiReact.Button, { basic: true, color: "blue", floated: "right", content: "Export", onClick: handleExportProfileClick })),
|
|
702
767
|
React__default["default"].createElement(semanticUiReact.Form, null,
|
|
703
768
|
React__default["default"].createElement(semanticUiReact.Form.Input, { width: 4, label: "Profile Name", name: "name", value: selectedProfile === null || selectedProfile === void 0 ? void 0 : selectedProfile.name, onChange: handleInputChange })),
|
|
704
769
|
React__default["default"].createElement(semanticUiReact.Divider, null),
|