diff --git a/README.md b/README.md index 21d2f63..c299324 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Please note that this script does not cover everything, see below for a list of - `ui_slider` - converted to Dashboard 2.0's `ui-slider` - `ui_text_input` - converted to Dashboard 2.0's `ui-text-input` - `.tooltip` is not supported +- `ui_toast` - converted to Dashboard 2.0's `ui-notification` - `ui_numeric` - converted to Dashboard 2.0's `ui-numeric-input` ### Config Nodes @@ -38,7 +39,6 @@ Please note that this script does not cover everything, see below for a list of - `ui_gauge` - [link](https://github.com/FlowFuse/node-red-dashboard-2-migration/issues/26) - `ui_chart` - [link](https://github.com/FlowFuse/node-red-dashboard-2-migration/issues/27) - `ui_audio` - [link](https://github.com/FlowFuse/node-red-dashboard-2-migration/issues/28) -- `ui_toast` - [link](https://github.com/FlowFuse/node-red-dashboard-2-migration/issues/29) - `ui_control` - [link](https://github.com/FlowFuse/node-red-dashboard-2-migration/issues/30) - `ui_template` - [link](https://github.com/FlowFuse/node-red-dashboard-2-migration/issues/31) diff --git a/tests/flows/basic-layout-after.json b/tests/flows/basic-layout-after.json index cc1e8a5..461db3f 100644 --- a/tests/flows/basic-layout-after.json +++ b/tests/flows/basic-layout-after.json @@ -231,38 +231,60 @@ ] }, { - "id": "940a12ce19bf2212", - "type": "ui-number-input", - "z": "94d6d107f1742efb", - "name": "", - "label": "numeric", - "tooltip": "", - "group": "f663864dda246564", - "order": 13, - "width": 0, - "height": 0, - "passthru": true, - "topic": "topic", - "topicType": "msg", - "min": 0, - "max": 10, - "step": 1, - "className": "", - "x": 320, - "y": 440, - "wires": [ - [ - - ] - ], - "sendOnBlur": true, - "sendOnEnter": true, - "clearable": false, - "icon": "", - "iconPosition": "left", - "iconInnerPosition": "inside", - "spinner": "default" - }, + "id": "c147bc430094baf8", + "type": "ui-notification", + "z": "94d6d107f1742efb", + "ui": "0996ab6125fd4a4b", + "position": "center center", + "colorDefault": true, + "color": null, + "displayTime": "3", + "showCountdown": false, + "outputs": 1, + "allowDismiss": true, + "dismissText": "", + "allowConfirm": true, + "confirmText": "OK", + "raw": false, + "className": "", + "name": "", + "x": 350, + "y": 400, + "wires": [ + [] + ] + }, + { + "id": "940a12ce19bf2212", + "type": "ui-number-input", + "z": "94d6d107f1742efb", + "name": "", + "label": "numeric", + "tooltip": "", + "group": "f663864dda246564", + "order": 13, + "width": 0, + "height": 0, + "passthru": true, + "topic": "topic", + "topicType": "msg", + "min": 0, + "max": 10, + "step": 1, + "className": "", + "x": 320, + "y": 440, + "wires": [ + [] + ], + "sendOnBlur": true, + "sendOnEnter": true, + "clearable": false, + "icon": "", + "iconPosition": "left", + "iconInnerPosition": "inside", + "spinner": "default" + }, { "id": "856a31bba370e7fc", "type": "ui-group", diff --git a/tests/flows/basic-layout-before.json b/tests/flows/basic-layout-before.json index 1c7797f..8338e7e 100644 --- a/tests/flows/basic-layout-before.json +++ b/tests/flows/basic-layout-before.json @@ -223,6 +223,25 @@ [] ] }, + { + "id": "73ce8707dab7de0a", + "type": "ui_toast", + "z": "94d6d107f1742efb", + "position": "prompt", + "displayTime": "3", + "highlight": "", + "sendall": true, + "outputs": 1, + "ok": "OK", + "cancel": "Cancel", + "raw": false, + "className": "", + "topic": "", + "name": "", + "x": 350, + "y": 400, + "wires": [] + }, { "id": "b52c292d531874a6", "type": "ui_numeric", diff --git a/tests/index.js b/tests/index.js index 028d30b..b7fe23c 100644 --- a/tests/index.js +++ b/tests/index.js @@ -204,11 +204,23 @@ describe('Dashboard Migration Script', function () { } }) }) - + + describe('UI Notification', function () { + const input = utils.getByType(migratedFlow, 'ui-notification')[0] + const input1 = utils.getByType(basicLayoutAfter, 'ui-notification')[0] + const excludeFromChecks = ['id', 'group'] + Object.keys(input).forEach((prop) => { + if (!excludeFromChecks.includes(prop)) { + it('should set ' + prop + ' correctly ', function () { + input[prop].should.eql(input1[prop]) + }) + } + }) + }) + describe('UI Number Input', function () { const input = utils.getByType(migratedFlow, 'ui-number-input')[0] const input1 = utils.getByType(basicLayoutAfter, 'ui-number-input')[0] - const excludeFromChecks = ['id', 'group'] Object.keys(input).forEach((prop) => { if (!excludeFromChecks.includes(prop)) { @@ -218,7 +230,7 @@ describe('Dashboard Migration Script', function () { } }) }) - + describe('Unsupported UI Nodes:', function () { it('should should be disabled in the NR Editor', function () { const template0 = utils.getByType(migratedFlow, 'ui_template')[0] diff --git a/transformers/index.js b/transformers/index.js index 8f39fef..1e6f487 100644 --- a/transformers/index.js +++ b/transformers/index.js @@ -8,5 +8,6 @@ module.exports = { uiSwitch: require('./nodes/ui-switch'), uiText: require('./nodes/ui-text'), uiTextInput: require('./nodes/ui-text-input'), + uiNotification: require('./nodes/ui-notification') uiNumeric: require('./nodes/ui-numeric') } diff --git a/transformers/map.json b/transformers/map.json index 9a1a789..3e25589 100644 --- a/transformers/map.json +++ b/transformers/map.json @@ -8,5 +8,6 @@ "ui_switch": "uiSwitch", "ui_text": "uiText", "ui_text_input": "uiTextInput", + "ui_toast": "uiNotification" "ui_numeric": "uiNumeric" } diff --git a/transformers/nodes/ui-notification.js b/transformers/nodes/ui-notification.js new file mode 100644 index 0000000..4085960 --- /dev/null +++ b/transformers/nodes/ui-notification.js @@ -0,0 +1,37 @@ +module.exports = function (node, baseId, themeId) { + node.type = 'ui-notification' + + // update properties + if (node.position === 'dialog' || node.position === 'prompt') { + node.position = 'center center' + node.allowConfirm = true + node.allowDismiss = true + node.confirmText = node.ok + node.dismissText = node.cancel + } else { + node.allowConfirm = false + node.allowDismiss = false + node.confirmText = node.ok + node.dismissText = node.cancel + } + if (node.highlight !== '') { + node.colorDefault = false + node.color = node.highlight + } else { + node.colorDefault = true + node.color = null + } + + // new properties + + node.ui = baseId + node.showCountdown = false + + // remove properties + // NONE + delete node.highlight + delete node.topic + delete node.sendall + + return node +}