Skip to content

Commit

Permalink
fix(core): fix notice to support type (#375)
Browse files Browse the repository at this point in the history
Co-authored-by: Wasuwat Limsuparhat <[email protected]>
  • Loading branch information
Theeraphat-Sorasetsakul and wsuwt authored Jun 28, 2022
1 parent ccd76a0 commit cd41db3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
20 changes: 20 additions & 0 deletions packages/core/__snapshots__/TestDeprecationNotice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `TestDeprecationNotice`

#### `Test generate simple message`

```html
Deprecation notice:
test

```

#### `Test generate message with url`

```html
Deprecation notice:
test

url

```

4 changes: 2 additions & 2 deletions packages/core/__snapshots__/TestWarningNotice.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#### `Test generate simple message`

```html
Information notice:
Warning notice:
test

```

#### `Test generate message with url`

```html
Information notice:
Warning notice:
test

url
Expand Down
2 changes: 1 addition & 1 deletion packages/core/__test__/notices/DeprecationNotice.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@refinitiv-ui/test-helpers';
import { DeprecationNotice } from '../../lib/notices/DeprecationNotice';

describe('TestWarningNotice', () => {
describe('TestDeprecationNotice', () => {
let originFunc;
let shownMessage = '';
let callCount = 0;
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/notices/DeprecationNotice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { WarningNotice } from './WarningNotice.js';
import { MESSAGE_TYPE } from './constants.js';

/**
* **Deprecation Notice**\
* Used to show deprecation warnings in the console.
*/
export class DeprecationNotice extends WarningNotice {
protected type = 'Deprecation';
constructor (message: string, supportURL?: string, type = MESSAGE_TYPE.DEPRECATION) {
super(message, supportURL, type);
}
}
12 changes: 5 additions & 7 deletions packages/core/src/notices/Notice.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MESSAGE_TYPE } from './constants.js';

const generateMessage = (type: string, message: string, supportURL?: string): string =>
`${type} notice:\n${!supportURL ? message : `${message}\n\n${supportURL}\n`}`;

Expand All @@ -13,11 +15,6 @@ export class Notice {
*/
public shown = false;

/**
* Type of notice
*/
protected type = 'Information';

/**
* The message to be used for the
* warning notice.
Expand All @@ -28,9 +25,10 @@ export class Notice {
* Create a warning notice to show in the console.
* @param message Warning message to show in the console
* @param supportURL Support URL to show additional information
* @param type Type of Notice to show at top of message
*/
constructor (message: string, supportURL?: string) {
this.message = generateMessage(this.type, message, supportURL);
constructor (message: string, supportURL?: string, type = MESSAGE_TYPE.NOTICE) {
this.message = generateMessage(type, message, supportURL);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/notices/WarningNotice.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Notice } from './Notice.js';
import { MESSAGE_TYPE } from './constants.js';

/**
* **Warning Notice**\
* Used to show warning notices in the console.
*/
export class WarningNotice extends Notice {

protected type = 'Warning';
constructor (message: string, supportURL?: string, type = MESSAGE_TYPE.WARNING) {
super(message, supportURL, type);
}

public show (): void {
/* eslint-disable-next-line no-console */
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/notices/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum MESSAGE_TYPE {
NOTICE = 'Information',
DEPRECATION = 'Deprecation',
WARNING = 'Warning'
}

0 comments on commit cd41db3

Please sign in to comment.