From 8c51d8b448f42975aae98370d022bb28e50256e3 Mon Sep 17 00:00:00 2001
From: JohannesDoberer
Date: Tue, 2 Apr 2019 15:16:00 +0200
Subject: [PATCH] open microfrontend in modal (#446)
---
client/luigi-client.d.ts | 26 +-
client/src/luigi-client.js | 32 ++-
.../luigi-sample-angular/package-lock.json | 8 -
.../src/app/project/project.component.html | 32 ++-
core/package-lock.json | 55 +++--
core/src/App.html | 224 +++++++++++++-----
core/src/Modal.html | 139 +++++++++++
7 files changed, 422 insertions(+), 94 deletions(-)
create mode 100644 core/src/Modal.html
diff --git a/client/luigi-client.d.ts b/client/luigi-client.d.ts
index 75a7af3755..3b2c89cb97 100644
--- a/client/luigi-client.d.ts
+++ b/client/luigi-client.d.ts
@@ -16,6 +16,11 @@ export declare interface ConfirmationModalSettings {
buttonDismiss?: string;
}
+export declare interface ModalSettings {
+ title?: string;
+ size?: 'l' | 'm' | 's';
+}
+
export declare interface Context {
authData?: AuthData;
context?: { parentNavigationContext?: string[] };
@@ -149,12 +154,20 @@ export declare interface LinkManager {
* @param {string} path path to be navigated to
* @param {string} sessionId current Luigi **sessionId**
* @param {boolean} preserveView Preserve a view by setting it to `true`. It keeps the current view opened in the background and opens the new route in a new frame. Use the {@link #goBack goBack()} function to navigate back. You can use this feature across different levels. Preserved views are discarded as soon as the standard {@link #navigate navigate()} function is used instead of {@link #goBack goBack()}.
+ * @param {Object} modalSettings opens a microfrontend as a modal with possibility to specify a title and size
+ * @param {string} modalSettings.title modal title
+ * @param {string} modalSettings.size size of the modal (l=large 80% default, m=medium 60%, s=small 40%)
* @example
* LuigiClient.linkManager().navigate('/overview')
* LuigiClient.linkManager().navigate('users/groups/stakeholders')
* LuigiClient.linkManager().navigate('/settings', null, true) // preserve view
*/
- navigate: (path: string, sessionId?: string, preserveView?: boolean) => void;
+ navigate: (
+ path: string,
+ sessionId?: string,
+ preserveView?: boolean,
+ modalSettings?: ModalSettings
+ ) => void;
/**
* Checks if the path you can navigate to exists in the main application. For example, you can use this helper method conditionally to display a DOM element like a button.
@@ -182,6 +195,17 @@ export declare interface LinkManager {
* LuigiClient.linkManager.fromContext("currentTeam").withParams({foo: "bar"}).navigate("path")
*/
withParams: (nodeParams: NodeParams) => this;
+
+ /**
+ * Opens a microfrontend as a modal
+ * @param {string} path path to be navigated to
+ * @param {Object} modalSettings settings to customize the modal title and size
+ * @param {string} modalSettings.title modal title
+ * @param {string} modalSettings.size size of the modal (l=large 80% default, m=medium 60%, s=small 40%)
+ * @example
+ * LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
+ */
+ openAsModal: (nodepath: string, modalSettings?: ModalSettings) => void;
}
/**
diff --git a/client/src/luigi-client.js b/client/src/luigi-client.js
index 1efdc80130..986be0bd3b 100644
--- a/client/src/luigi-client.js
+++ b/client/src/luigi-client.js
@@ -250,12 +250,20 @@ const LuigiClient = {
* @param {string} path path to be navigated to
* @param {string} sessionId current Luigi **sessionId**
* @param {boolean} preserveView Preserve a view by setting it to `true`. It keeps the current view opened in the background and opens the new route in a new frame. Use the {@link #goBack goBack()} function to navigate back. You can use this feature across different levels. Preserved views are discarded as soon as the standard {@link #navigate navigate()} function is used instead of {@link #goBack goBack()}.
+ * @param {Object} modalSettings opens a microfrontend as a modal with possibility to specify a title and size
+ * @param {string} modalSettings.title modal title
+ * @param {string} modalSettings.size size of the modal (l=large 80% default, m=medium 60%, s=small 40%)
* @example
* LuigiClient.linkManager().navigate('/overview')
* LuigiClient.linkManager().navigate('users/groups/stakeholders')
* LuigiClient.linkManager().navigate('/settings', null, true) // preserve view
*/
- navigate: function navigate(path, sessionId, preserveView) {
+ navigate: function navigate(
+ path,
+ sessionId,
+ preserveView,
+ modalSettings
+ ) {
if (options.errorSkipNavigation) {
options.errorSkipNavigation = false;
return;
@@ -267,12 +275,24 @@ const LuigiClient = {
sessionId: sessionId,
params: Object.assign(options, {
link: path,
- relative: relativePath
+ relative: relativePath,
+ modal: modalSettings
})
};
window.parent.postMessage(navigationOpenMsg, '*');
},
-
+ /**
+ * Opens a microfrontend as a modal
+ * @param {string} path path to be navigated to
+ * @param {Object} modalSettings settings to customize the modal title and size
+ * @param {string} modalSettings.title modal title
+ * @param {string} modalSettings.size size of the modal (l=large 80% default, m=medium 60%, s=small 40%)
+ * @example
+ * LuigiClient.linkManager().openAsModal('projects/pr1/users', {title:'Users', size:'m'});
+ */
+ openAsModal: function(path, modalSettings) {
+ this.navigate(path, 0, true, modalSettings || {});
+ },
/**
* Sets the current navigation context to that of a specific parent node which has the {@link navigation-configuration.md navigationContext} field declared in the navigation configuration. This navigation context is then used by the `navigate` function.
* @param {string} navigationContext
@@ -374,7 +394,10 @@ const LuigiClient = {
* @returns {boolean} indicating if there is a preserved view you can return to.
*/
hasBack: function hasBack() {
- return Boolean(currentContext.internal.viewStackSize !== 0);
+ return (
+ !!currentContext.internal.modal ||
+ currentContext.internal.viewStackSize !== 0
+ );
},
/**
@@ -487,7 +510,6 @@ const LuigiClient = {
});
return promises.confirmationModal.promise;
},
-
/**
* Shows an alert.
* @param {Object} settings the settings for the alert
diff --git a/core/examples/luigi-sample-angular/package-lock.json b/core/examples/luigi-sample-angular/package-lock.json
index 7ba5d51b3a..da8218cf45 100644
--- a/core/examples/luigi-sample-angular/package-lock.json
+++ b/core/examples/luigi-sample-angular/package-lock.json
@@ -1836,14 +1836,6 @@
}
}
},
- "@kyma-project/luigi-client": {
- "version": "0.4.9",
- "resolved": "https://registry.npmjs.org/@kyma-project/luigi-client/-/luigi-client-0.4.9.tgz",
- "integrity": "sha512-nC6DN6Lm52Vvw8hPhMepRsqzqOujjgcMGDOqMi29ISr36ruA3tMfMSEmz+YnaeSy7bD4EBYJ4nZbPNiQDp0MLA=="
- },
- "@kyma-project/luigi-core": {
- "version": "0.4.10"
- },
"@ngtools/webpack": {
"version": "6.1.5",
"resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-6.1.5.tgz",
diff --git a/core/examples/luigi-sample-angular/src/app/project/project.component.html b/core/examples/luigi-sample-angular/src/app/project/project.component.html
index 46c5180910..325324a077 100644
--- a/core/examples/luigi-sample-angular/src/app/project/project.component.html
+++ b/core/examples/luigi-sample-angular/src/app/project/project.component.html
@@ -42,6 +42,7 @@ LuigiClient uxManager methods
Luigi confirmation modal has been {{ confirmationModalResult }}
+