Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic alert #395

Merged
merged 41 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
21a80fc
First working implementation
jesusreal Feb 1, 2019
ee1a41d
Add example for alerts and refactor html for project details page
jesusreal Feb 4, 2019
8d2090c
Fix e2e tests
jesusreal Feb 4, 2019
266cc4f
Remove two pieces of unneeded code in e2e tests
jesusreal Feb 4, 2019
cb6c070
Add links and sanitation to alert text
jesusreal Feb 4, 2019
10a9781
More consistency among confirmation modal and alert implementations
jesusreal Feb 5, 2019
b396c1a
support relative paths in links
jesusreal Feb 5, 2019
098a1a0
remove time-to-live from initial alert implementation in luigi core
jesusreal Feb 5, 2019
3026048
Update luigi client docu for alert
jesusreal Feb 5, 2019
2758b6b
Sanitize also if alert contains no links
jesusreal Feb 5, 2019
a25d8a4
use overflow-wrap instead of word-wrap in confirmation modal component
jesusreal Feb 5, 2019
c847521
e2e tests for alert - in progress
jesusreal Feb 5, 2019
b48ffc3
improve implementation of links in modals
jesusreal Feb 5, 2019
ffc5964
write e2e tests for generic alert - final
jesusreal Feb 5, 2019
deb1146
Remove timeout for creation of click listeners
jesusreal Feb 6, 2019
a3bb8b1
Fix issue for alerts without links
jesusreal Feb 6, 2019
e48cf4d
Remove export of function, since it is not used outside
jesusreal Feb 6, 2019
c12f789
More consistency on luigi ux messages
jesusreal Feb 6, 2019
d6153b6
Make dismiss button in generic alert mandatory. It was optional before.
jesusreal Feb 6, 2019
62476c5
Explicitly update fiori-fundamentals dependency to latest and update …
jesusreal Feb 6, 2019
beef9d4
fix failing e2e test
jesusreal Feb 6, 2019
314d607
Fix info alert class by adding map for alert type
jesusreal Feb 6, 2019
3934a1c
Override background color for information alert to avoid transparency
jesusreal Feb 6, 2019
9ce0397
Update client/src/luigi-client.js
dariadomagala-sap Feb 6, 2019
c199087
Update core/src/Alert.html
dariadomagala-sap Feb 6, 2019
2bed735
Fixes for github ui commits
jesusreal Feb 6, 2019
2103205
Update Luigi client docu
jesusreal Feb 6, 2019
958532f
Fix default text not being displayed when not text field is provided
jesusreal Feb 6, 2019
e7fd6aa
Merge remote-tracking branch 'upstream/master' into add-generic-alert
jesusreal Feb 6, 2019
3b46a80
bring back time-to-live option for core alerts
jesusreal Feb 6, 2019
2dae7c3
Fix e2e tests after last change
jesusreal Feb 6, 2019
48d8e00
Remove default settings for alert and do not display alert if no text…
jesusreal Feb 6, 2019
7f3b8ea
Update luigi client docu
jesusreal Feb 6, 2019
052253d
small improvements in overview and project components in angular exam…
jesusreal Feb 7, 2019
331a30b
Update client/src/luigi-client.js
bszwarc Feb 7, 2019
169cdd3
Update client/src/luigi-client.js
bszwarc Feb 7, 2019
5aaad95
Update client/src/luigi-client.js
bszwarc Feb 7, 2019
82a0103
Update client/src/luigi-client.js
bszwarc Feb 7, 2019
144ce83
Update client/src/luigi-client.js
bszwarc Feb 7, 2019
2d1594e
Add loading indicator link to overview page
dariadomagala-sap Feb 7, 2019
59add8c
Update luigi client docu
jesusreal Feb 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 58 additions & 8 deletions client/src/luigi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ function luigiClientInit() {
data.confirmed ? promise.resolveFn() : promise.rejectFn();
delete promises.confirmationModal;
}

if ('luigi.ux.alert.hide' === e.data.msg) {
promises.alert.resolveFn();
delete promises.alert;
}
});

window.parent.postMessage({ msg: 'luigi.get-context' }, '*');
Expand Down Expand Up @@ -422,18 +427,18 @@ const LuigiClient = {
},
/**
* Shows a confirmation modal.
* @param {Object} content the content of the confirmation modal. If no value is provided for any of the fields, a default value is set for it.
* @param {string} content.header the content of the modal header
* @param {string} content.body the content of the modal body
* @param {string} content.buttonConfirm the label for the modal confirm button
* @param {string} content.buttonDismiss the label for the modal dismiss button
* @param {Object} settings the settings the confirmation modal. If no value is provided for any of the fields, a default value is set for it.
* @param {string} settings.header the content of the modal header
* @param {string} settings.body the content of the modal body
* @param {string} settings.buttonConfirm the label for the modal confirm button
* @param {string} settings.buttonDismiss the label for the modal dismiss button
* @returns {promise} which is resolved when accepting the confirmation modal and rejected when dismissing it.
*/
showConfirmationModal: function showConfirmationModal(content) {
showConfirmationModal: function showConfirmationModal(settings) {
window.parent.postMessage(
{
msg: 'luigi.ux.confirmation-modal-show',
data: { content }
msg: 'luigi.ux.confirmationModal.show',
data: { settings }
},
'*'
);
Expand All @@ -443,6 +448,51 @@ const LuigiClient = {
promises.confirmationModal.rejectFn = reject;
});
return promises.confirmationModal.promise;
},

/**
* Shows an alert.
* @param {Object} settings the settings for the alert
* @param {string} settings.text the content of the alert. To add a link to the content, you have to set up the link in the `links` object. The key(s) in the `links` object must be used in the text to reference the links, wrapped in curly brackets with no spaces. If you don't specify any text, the alert is not displayed.
* @param {('info'|'success'|'warning'|'error')} settings.type sets the type of the alert
* @param {Object} settings.links provides links data
* @param {Object} settings.links.LINK_KEY object containing the data for a particular link. To properly render the link in the alert message refer to the description of the **settings.text** parameter.
* @param {string} settings.links.LINK_KEY.text text which replaces the link identifier in the alert content
* @param {string} settings.links.LINK_KEY.url url to navigate when you click the link. Currently, only internal links are supported in the form of relative or absolute paths.
* @returns {promise} which is resolved when the alert is dismissed
* @example
* import LuigiClient from '@kyma-project/luigi-client';
* const settings = {
* text: Ut enim ad minim veniam, {goToHome} quis nostrud exercitation ullamco {relativePath} laboris nisi ut aliquip ex ea commodo consequat.
* Duis aute irure dolor {goToOtherProject},
* type: 'info',
* links: {
* goToHome: { text: 'homepage', url: '/overview' },
* goToOtherProject: { text: 'other project', url: '/projects/pr2' },
* relativePath: { text: 'relative hide side nav', url: 'hideSideNav' }
* }
* }
* LuigiClient
* .uxManager()
* .showAlert(settings)
* .then(() => {
* // Logic to execute when the alert is dismissed
* });

*/
showAlert: function showAlert(settings) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also add a possibility to hide the alert (for example if someone wants to hide it after the navigation).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will discuss it internally and provide the best solution to let the programmer of the microfrontend close the alert without the user explicitly clicking the dismiss button of the alert.

window.parent.postMessage(
{
msg: 'luigi.ux.alert.show',
data: { settings }
},
'*'
);
promises.alert = {};
promises.alert.promise = new Promise(resolve => {
promises.alert.resolveFn = resolve;
});
return promises.alert.promise;
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions core/examples/luigi-sample-angular/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ Cypress.Commands.add('goToUxManagerMethods', iframe => {

cy.expectPathToBe('/projects/pr1');

cy.wrap(iframe).should('contain', 'LuigiClient uxManager methods:');
cy.wrap(iframe).should('contain', 'LuigiClient uxManager methods');
});

Cypress.Commands.add('goToLinkManagerMethods', iframe => {
cy.wait(0);
cy.wrap(iframe)
.contains('linkManager()')
.click();

cy.expectPathToBe('/projects/pr2');

cy.wrap(iframe).should('contain', 'LuigiClient linkManager methods:');
cy.wrap(iframe).should('contain', 'LuigiClient linkManager methods');
});

Cypress.Commands.add('goToOverviewPage', () => {
Expand All @@ -42,7 +42,7 @@ Cypress.Commands.add('goToOverviewPage', () => {
.click();
});

export const isHashRoutingOn = () => {
const isHashRoutingOn = () => {
const appWindow = cy.state('window');
const { useHashRouting } =
appWindow && appWindow.Luigi && appWindow.Luigi.config
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isHashRoutingOn } from '../support/commands';
describe('Luigi client features', () => {
beforeEach(() => {
cy.visit('/');
Expand Down Expand Up @@ -178,143 +177,4 @@ describe('Luigi client features', () => {
cy.get('.fd-alert').should('not.exist');
});
});

describe('uxManager', () => {
it('backdrop', () => {
cy.wait(500);
cy.get('iframe').then($iframe => {
const $iframeBody = $iframe.contents().find('body');
cy.goToUxManagerMethods($iframeBody);
cy.wrap($iframeBody).should(
'not.contain',
'Lorem tipsum dolor sit amet'
);
cy.get('.fd-ui__overlay').should('not.exist');

//open modal with backdrop
cy.wrap($iframeBody)
.contains('Add backdrop')
.click();

cy.wrap($iframeBody).should('contain', 'Lorem tipsum dolor sit amet');
cy.get('.fd-ui__overlay').should('exist');
//close modal
cy.wrap($iframeBody)
.find('.fd-modal__footer')
.contains('Confirm')
.click();

cy.wrap($iframeBody).should(
'not.contain',
'Lorem tipsum dolor sit amet'
);
cy.get('.fd-ui__overlay').should('not.exist');
});
});

it('confirmation modal', () => {
cy.get('iframe').then($iframe => {
const $iframeBody = $iframe.contents().find('body');

cy.goToUxManagerMethods($iframeBody);

cy.get('[data-cy=luigi-confirmation-modal]').should('not.be.visible');

cy.wrap($iframeBody)
.find('[data-cy=show-luigi-confirmation-modal]')
.click();
cy.get('[data-cy=luigi-confirmation-modal]').should('be.visible');

cy.get('[data-cy=luigi-modal-dismiss]').click();
cy.get('[data-cy=luigi-confirmation-modal]').should('not.be.visible');
cy.wrap($iframeBody)
.find('[data-cy=luigi-confirmation-modal-result]')
.contains('Confirmation modal has been dismissed');

cy.wrap($iframeBody)
.find('[data-cy=show-luigi-confirmation-modal]')
.click();
cy.get('[data-cy=luigi-confirmation-modal]').should('be.visible');

cy.get('[data-cy=luigi-modal-confirm]').click();
cy.get('[data-cy=luigi-confirmation-modal]').should('not.be.visible');
cy.wrap($iframeBody)
.find('[data-cy=luigi-confirmation-modal-result]')
.contains('Confirmation modal has been confirmed');
});
});

it('loading indicator', () => {
cy.get('.fd-shellbar')
.contains('External Page')
.click();

cy.get('.spinnerContainer .fd-spinner').should('exist');

cy.get('.spinnerContainer .fd-spinner').should('not.exist');

cy.wait(250);
cy.get('iframe').then($iframe => {
const $iframeBody = $iframe.contents().find('body');

// show loading indicator
cy.wrap($iframeBody)
.contains('Show loading indicator')
.click();

cy.get('.spinnerContainer .fd-spinner').should('exist');

// wait for programmatic hide of loading indicator
cy.get('.spinnerContainer .fd-spinner').should('not.exist');
});
});

it("Unsaved changes - shouldn't proceed when 'No' was pressed in modal", () => {
cy.get('iframe').then($iframe => {
const $iframeBody = $iframe.contents().find('body');

cy.wrap($iframeBody)
.find('[data-cy=toggle-dirty-state]')
.check();

cy.get('button')
.contains('Projects')
.click();

cy.get('[data-cy=luigi-confirmation-modal]').should('be.visible');

cy.expectPathToBe('/overview'); //the location is unchanged

cy.get('[data-cy=luigi-modal-dismiss]').click();

cy.get('[data-cy=luigi-confirmation-modal]').should('not.be.visible');

cy.expectPathToBe('/overview'); //the location is still unchanged after "No" clicked
});
});

it("Unsaved changes - should proceed when 'Yes' was pressed in modal", () => {
cy.get('iframe').then($iframe => {
const $iframeBody = $iframe.contents().find('body');

cy.wrap($iframeBody)
.find('[data-cy=toggle-dirty-state]')
.check();

cy.get('button')
.contains('Projects')
.click();

cy.get('[data-cy=luigi-confirmation-modal]').should('be.visible');

cy.expectPathToBe('/overview'); //the location is unchanged

cy.get('[data-cy=luigi-modal-confirm]').click();

cy.get('[data-cy=luigi-confirmation-modal]').should('not.be.visible');

cy.expectPathToBe('/projects'); //the location is changed after "Yes" clicked
});
});
});
});
Loading