Skip to content

Commit bb7dab5

Browse files
authored
CY-1560 - Add function for getting node status icon (#12)
* Added function for getting node status icon (CY-1560) * Improved no SSH key error message * Updated JS API documentation * Improved JS API documentation verification
1 parent d8d3bad commit bb7dab5

File tree

10 files changed

+169
-26
lines changed

10 files changed

+169
-26
lines changed

ci/verify-docs.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
git diff --exit-code ./src/README.md
5+
EXIT_CODE=$?
6+
7+
if [ "$EXIT_CODE" != "0" ]; then
8+
echo "ERROR: JS API documentation not up-to-date with the source code. Follow these steps:"
9+
echo " - verify if 'documentation.yml' configuration is up-to-date with the 'src' folder content,"
10+
echo " - run 'npm run docs',"
11+
echo " - check output 'src/README.md' file,"
12+
echo " - commit updated 'src/README.md' file."
13+
exit 1
14+
fi;

documentation.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
toc:
2+
- name: consts
3+
description: |
4+
Common constants.
5+
children:
6+
- nodeStatuses
27
- name: icons
38
description: |
49
Icons API intends to provide helper functions to access icons defined within [cloudify](#fonts) font.
510
children:
11+
- getEventIcon
612
- getNodeIcon
13+
- getNodeStatusIcon
14+

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"test:coverage": "jest test --coverage",
3939
"test:docs": "npm run docs && npm run verify:docs",
4040
"test:only": "jest test",
41-
"verify:docs": "git diff --exit-code ./src/README.md || echo Run `npm run docs` and commit updated `src/README.md` file."
41+
"verify:docs": "sh ci/verify-docs.sh"
4242
},
4343
"repository": {
4444
"type": "git",

scripts/upload-package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ uploadPackage() {
3737

3838
# SSH key check
3939
if [ ! -f "${SSH_KEY_PATH}" ]; then
40-
echo "ERROR: SSH key to Cloudify Manager - '${SSH_KEY_PATH}' - not found.";
40+
echo "ERROR: SSH key to Cloudify Manager (SSH_KEY_PATH variable) - '${SSH_KEY_PATH}' - not found.";
4141
((ERROR_CODE++))
4242
fi
4343

src/README.md

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,86 @@
22

33
### Table of Contents
44

5-
- [icons][1]
6-
- [getNodeIcon][2]
7-
- [Parameters][3]
5+
- [consts][1]
6+
- [nodeStatuses][2]
7+
- [icons][3]
8+
- [getEventIcon][4]
9+
- [Parameters][5]
10+
- [getNodeIcon][6]
11+
- [Parameters][7]
12+
- [getNodeStatusIcon][8]
13+
- [Parameters][9]
14+
15+
## consts
16+
17+
Common constants.
18+
19+
20+
### nodeStatuses
21+
22+
Node statuses constants.
23+
24+
Type: [string][10]
825

926
## icons
1027

11-
Icons API intends to provide helper functions to access icons defined within [cloudify][4] font.
28+
Icons API intends to provide helper functions to access icons defined within [cloudify][11] font.
29+
1230

31+
### getEventIcon
32+
33+
Get event type icon character to be used with cloudify font.
34+
35+
#### Parameters
36+
37+
- `eventType` **[string][10]** event type, eg. "workflow_started" or "task_received".
38+
39+
Returns **[string][10]** character from cloudify font
1340

1441
### getNodeIcon
1542

1643
Get node type icon character to be used with cloudify font.
1744

1845
#### Parameters
1946

20-
- `hierarchy` **([string][5] \| [Array][6]<[string][5]>)** node type hierarchy, from the most specific to the most generic,
47+
- `hierarchy` **([string][10] \| [Array][12]<[string][10]>)** node type hierarchy, from the most specific to the most generic,
2148
can be single string (eg. "cloudify.nodes.Root")
2249
or array of strings (eg. ["cloudify.nodes.CloudifyManager", "cloudify.nodes.SoftwareComponent", "cloudify.nodes.Root"]).
2350

24-
Returns **[string][5]** character from cloudify font
51+
Returns **[string][10]** character from cloudify font
52+
53+
### getNodeStatusIcon
54+
55+
Get node status icon character to be used with cloudify font.
56+
57+
#### Parameters
58+
59+
- `nodeStatus` **[nodeStatuses][13]** node status value.
60+
61+
Returns **[string][10]** character from cloudify font or empty string for not [nodeStatuses][2] value
62+
63+
[1]: #consts
64+
65+
[2]: #nodestatuses
66+
67+
[3]: #icons
68+
69+
[4]: #geteventicon
70+
71+
[5]: #parameters
72+
73+
[6]: #getnodeicon
74+
75+
[7]: #parameters-1
2576

26-
[1]: #icons
77+
[8]: #getnodestatusicon
2778

28-
[2]: #getnodeicon
79+
[9]: #parameters-2
2980

30-
[3]: #parameters
81+
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
3182

32-
[4]: #fonts
83+
[11]: #fonts
3384

34-
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
85+
[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
3586

36-
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
87+
[13]: #nodestatuses

src/consts.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Node statuses constants.
3+
* @enum {string}
4+
*/
5+
export const nodeStatuses = {
6+
UNINITIALIZED: 'uninitialized',
7+
LOADING: 'loading',
8+
DONE: 'done',
9+
ALERT: 'alert',
10+
FAILED: 'failed'
11+
};
12+
13+
export default { nodeStatuses };

src/icons.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { nodeStatuses } from './consts';
2+
13
/**
24
* Get node type icon character to be used with cloudify font.
35
*
@@ -7,7 +9,7 @@
79
*
810
* @returns {string} character from cloudify font
911
*/
10-
function getNodeIcon(hierarchy) {
12+
export function getNodeIcon(hierarchy) {
1113
const nodeTypeToChar = {
1214
'cloudify.nodes.ApplicationModule': '\ue616',
1315
'cloudify.nodes.ApplicationServer': '\ue61e',
@@ -40,14 +42,34 @@ function getNodeIcon(hierarchy) {
4042
return knownType ? nodeTypeToChar[knownType] : nodeTypeToChar[defaultNodeType];
4143
}
4244

45+
/**
46+
* Get node status icon character to be used with cloudify font.
47+
*
48+
* @param {nodeStatuses} nodeStatus - node status value.
49+
*
50+
* @returns {string} character from cloudify font or empty string for not {@link nodeStatuses} value
51+
*/
52+
export function getNodeStatusIcon(nodeStatus) {
53+
const nodeStatusToChar = {
54+
[nodeStatuses.ALERT]: '\ue629',
55+
[nodeStatuses.DONE]: '\ue62a',
56+
[nodeStatuses.FAILED]: '\ue62b',
57+
[nodeStatuses.LOADING]: '\ue630'
58+
};
59+
const defaultChar = '';
60+
const knownType = !!nodeStatusToChar[nodeStatus];
61+
62+
return knownType ? nodeStatusToChar[nodeStatus] : defaultChar;
63+
}
64+
4365
/**
4466
* Get event type icon character to be used with cloudify font.
4567
*
4668
* @param {string} eventType - event type, eg. "workflow_started" or "task_received".
4769
*
4870
* @returns {string} character from cloudify font
4971
*/
50-
function getEventIcon(eventType) {
72+
export function getEventIcon(eventType) {
5173
const eventTypeToChar = {
5274
policy_failed: '\ue605',
5375
policy_success: '\ue606',
@@ -75,5 +97,6 @@ function getEventIcon(eventType) {
7597

7698
export default {
7799
getEventIcon,
78-
getNodeIcon
100+
getNodeIcon,
101+
getNodeStatusIcon
79102
};

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
// eslint-disable-next-line import/prefer-default-export
22
export { default as icons } from './icons'; // to re-export default
3+
export { default as consts } from './consts'; // to re-export default

test/consts.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { nodeStatuses } from '../src/consts';
2+
3+
describe('nodeStatuses', () => {
4+
test('getting alert state', () => {
5+
expect(nodeStatuses.ALERT).toBe('alert');
6+
});
7+
8+
test('getting done state', () => {
9+
expect(nodeStatuses.DONE).toBe('done');
10+
});
11+
12+
test('getting failed state', () => {
13+
expect(nodeStatuses.FAILED).toBe('failed');
14+
});
15+
16+
test('getting loading state', () => {
17+
expect(nodeStatuses.LOADING).toBe('loading');
18+
});
19+
});

test/icons.test.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
1-
import icons from '../src/icons';
1+
import { getEventIcon, getNodeIcon, getNodeStatusIcon } from '../src/icons';
22

33
describe('getNodeIcon', () => {
44
test('handles empty string', () => {
5-
expect(icons.getNodeIcon('')).toBe('\ue616');
5+
expect(getNodeIcon('')).toBe('\ue616');
66
});
77

88
test('handles string', () => {
9-
expect(icons.getNodeIcon('cloudify.nodes.Compute')).toBe('\ue61b');
9+
expect(getNodeIcon('cloudify.nodes.Compute')).toBe('\ue61b');
1010
});
1111

1212
test('handles empty array', () => {
13-
expect(icons.getNodeIcon([])).toBe('\ue616');
13+
expect(getNodeIcon([])).toBe('\ue616');
1414
});
1515

1616
test('handles array', () => {
17-
expect(icons.getNodeIcon(['cloudify.nodes.Compute', 'cloudify.nodes.Root'])).toBe('\ue61b');
17+
expect(getNodeIcon(['cloudify.nodes.Compute', 'cloudify.nodes.Root'])).toBe('\ue61b');
1818
});
1919

2020
test('handles invalid input', () => {
21-
expect(icons.getNodeIcon(555)).toBe('\ue616');
21+
expect(getNodeIcon(555)).toBe('\ue616');
22+
});
23+
});
24+
25+
describe('getNodeStatusIcon', () => {
26+
test('handles empty string', () => {
27+
expect(getNodeStatusIcon('')).toBe('');
28+
});
29+
30+
test('handles string', () => {
31+
expect(getNodeStatusIcon('alert')).toBe('\ue629');
32+
});
33+
34+
test('handles invalid input', () => {
35+
expect(getNodeStatusIcon('abcd')).toBe('');
2236
});
2337
});
2438

2539
describe('getEventIcon', () => {
2640
test('handles empty string', () => {
27-
expect(icons.getEventIcon('')).toBe('\ue60a');
41+
expect(getEventIcon('')).toBe('\ue60a');
2842
});
2943

3044
test('handles string', () => {
31-
expect(icons.getEventIcon('task_succeeded')).toBe('\ue60b');
45+
expect(getEventIcon('task_succeeded')).toBe('\ue60b');
3246
});
3347

3448
test('handles invalid input', () => {
35-
expect(icons.getEventIcon(555)).toBe('\ue60a');
49+
expect(getEventIcon(555)).toBe('\ue60a');
3650
});
3751
});

0 commit comments

Comments
 (0)