Skip to content

Commit

Permalink
Moved the default error prefix over to a label
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Mar 16, 2022
1 parent 1901e0b commit c7c7a7c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
<shortDescription>The title that is used on generic errors in standard Ortoo LWCs.</shortDescription>
<value>Error</value>
</labels>
<labels>
<fullName>ortoo_core_default_error_prefix</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>The default prefix that is presented on errors in LWCs.</shortDescription>
<value>Your action could not be completed: </value>
</labels>
<labels>
<fullName>ortoo_core_search_button_label</fullName>
<language>en_US</language>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('displayError', () => {
const dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0];

expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' );
expect( dispatchedEvent.detail.message ).toBe( 'Your action could not be completed: ' + error );
expect( dispatchedEvent.detail.message ).toBe( 'c.ortoo_core_default_error_prefix' + error );
expect( dispatchedEvent.detail.variant ).toBe( 'error' );
expect( dispatchedEvent.detail.mode ).toBe( 'sticky' );

Expand Down Expand Up @@ -58,7 +58,7 @@ describe('displayError', () => {
const dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0];

expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' );
expect( dispatchedEvent.detail.message ).toBe( 'Your action could not be completed: javascript error format' );
expect( dispatchedEvent.detail.message ).toBe( 'c.ortoo_core_default_error_prefixjavascript error format' );
expect( dispatchedEvent.detail.variant ).toBe( 'error' );
expect( dispatchedEvent.detail.mode ).toBe( 'sticky' );

Expand Down Expand Up @@ -89,7 +89,7 @@ describe('displayError', () => {
const dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0];

expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' );
expect( dispatchedEvent.detail.message ).toBe( 'Your action could not be completed: An error message in the body' );
expect( dispatchedEvent.detail.message ).toBe( 'c.ortoo_core_default_error_prefixAn error message in the body' );
expect( dispatchedEvent.detail.variant ).toBe( 'error' );
expect( dispatchedEvent.detail.mode ).toBe( 'sticky' );

Expand Down Expand Up @@ -149,7 +149,7 @@ describe('displayError', () => {
const dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0];

expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' );
expect( dispatchedEvent.detail.message ).toBe( 'Your action could not be completed: An error string' );
expect( dispatchedEvent.detail.message ).toBe( 'c.ortoo_core_default_error_prefixAn error string' );
expect( dispatchedEvent.detail.variant ).toBe( 'warning' );
expect( dispatchedEvent.detail.mode ).toBe( 'sticky' );

Expand Down Expand Up @@ -179,7 +179,7 @@ describe('displayError', () => {
const dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0];

expect( dispatchedEvent.detail.title ).toBe( options.title );
expect( dispatchedEvent.detail.message ).toBe( 'Your action could not be completed: ' + error );
expect( dispatchedEvent.detail.message ).toBe( 'c.ortoo_core_default_error_prefix' + error );
expect( dispatchedEvent.detail.variant ).toBe( 'error' );
expect( dispatchedEvent.detail.mode ).toBe( 'sticky' );

Expand Down Expand Up @@ -209,7 +209,7 @@ describe('displayError', () => {
const dispatchedEvent = objectToRunAgainst.dispatchEvent.mock.calls[0][0];

expect( dispatchedEvent.detail.title ).toBe( 'c.ortoo_core_error_title' );
expect( dispatchedEvent.detail.message ).toBe( 'Your action could not be completed: An error string' );
expect( dispatchedEvent.detail.message ).toBe( 'c.ortoo_core_default_error_prefixAn error string' );
expect( dispatchedEvent.detail.variant ).toBe( 'error' );
expect( dispatchedEvent.detail.mode ).toBe( 'pester' );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import ERROR_TITLE from '@salesforce/label/c.ortoo_core_error_title';
import DEFAULT_ERROR_PREFIX from '@salesforce/label/c.ortoo_core_default_error_prefix';

/**
* When bound to a Lightning Web Component, will render the given error object.
*/
const displayError = function( error, options ) {

const title = options?.title ? options.title : ERROR_TITLE;
const messagePrefix = options?.messagePrefix ? options.messagePrefix + ': ' : 'Your action could not be completed: '; // TODO: should be a label
const messagePrefix = options?.messagePrefix ? options.messagePrefix + ': ' : DEFAULT_ERROR_PREFIX;
const mode = options?.mode ? options.mode : 'sticky';
const variant = options?.variant ? options.variant : 'error';

Expand Down

0 comments on commit c7c7a7c

Please sign in to comment.