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 support for tabulator getSelectedData function #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhangmx
Copy link

@zhangmx zhangmx commented Mar 10, 2023

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

Some Tabulator method not return promise like 'getSelectedData', and I realy need the data return from getSelectedData.

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run grunt to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 10, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: zhangmx / name: Flyman (bb379a2)

@dceejay
Copy link
Member

dceejay commented Mar 10, 2023

Do you have an example flow that shows/tests how this works ?

Thanks

@zhangmx
Copy link
Author

zhangmx commented Mar 10, 2023

Do you have an example flow that shows/tests how this works ?

Thanks

This is DEMO edited from example of 2 Richer table. Previously, this example could not get the return value of the getSelectedData function.Sorry I'm new to node-red and don't know how to write a unit test for this change.I have manually verified 7 sample codes in the project, except for 'ui-table Copy & Paste' (sorry I didn't understand how this example works). Also you can check my node-red-practice project

[
    {
        "id": "b7dff285.69049",
        "type": "inject",
        "z": "1285e099664f8de3",
        "name": "",
        "props": [
            {
                "p": "payload",
                "v": "[{\"Name\":\"<b>Yokoi</b>\",\"Age\":\"30\",\"Color\":\"lime\",\"Prog\":70,\"Star\":\"3\"},{\"Name\":\"<i>DCJ</i>\",\"Age\":\"50\",\"Color\":\"dodgerblue\",\"Prog\":\"45\",\"Star\":2,\"Pass\":false,\"web\":\"\"},{\"Name\":\"Nick\",\"Age\":\"40\",\"Color\":\"darkred\",\"Prog\":95,\"Star\":\"5\",\"Pass\":true,\"web\":\"http://nodered.org\"},{\"Name\":\"Oli\"}]",
                "vt": "json"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"Name\":\"<b>Yokoi</b>\",\"Age\":\"30\",\"Color\":\"lime\",\"Prog\":70,\"Star\":\"3\"},{\"Name\":\"<i>DCJ</i>\",\"Age\":\"50\",\"Color\":\"dodgerblue\",\"Prog\":\"45\",\"Star\":2,\"Pass\":false,\"web\":\"\"},{\"Name\":\"Nick\",\"Age\":\"40\",\"Color\":\"darkred\",\"Prog\":95,\"Star\":\"5\",\"Pass\":true,\"web\":\"http://nodered.org\"},{\"Name\":\"Oli\"}]",
        "payloadType": "json",
        "x": 190,
        "y": 220,
        "wires": [
            [
                "7d48e13.90ee22"
            ]
        ]
    },
    {
        "id": "cb53cb76.5fd0d8",
        "type": "inject",
        "z": "1285e099664f8de3",
        "name": "",
        "props": [
            {
                "p": "payload",
                "v": "[{\"Name\":\"<b>Yokoi</b>\",\"Age\":\"30\",\"Color\":\"lime\",\"Prog\":20,\"Star\":\"1\"},{\"Name\":\"<i>DCJ</i>\",\"Age\":\"50\",\"Color\":\"dodgerblue\",\"Prog\":\"80\",\"Star\":4,\"Pass\":true,\"web\":\"\"},{\"Name\":\"Nick\",\"Age\":\"40\",\"Color\":\"red\",\"Prog\":90,\"Star\":\"5\",\"Pass\":true,\"web\":\"http://nodered.org\"},{\"Name\":\"Oli\"}]",
                "vt": "json"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"Name\":\"<b>Yokoi</b>\",\"Age\":\"30\",\"Color\":\"lime\",\"Prog\":20,\"Star\":\"1\"},{\"Name\":\"<i>DCJ</i>\",\"Age\":\"50\",\"Color\":\"dodgerblue\",\"Prog\":\"80\",\"Star\":4,\"Pass\":true,\"web\":\"\"},{\"Name\":\"Nick\",\"Age\":\"40\",\"Color\":\"red\",\"Prog\":90,\"Star\":\"5\",\"Pass\":true,\"web\":\"http://nodered.org\"},{\"Name\":\"Oli\"}]",
        "payloadType": "json",
        "x": 190,
        "y": 260,
        "wires": [
            [
                "7d48e13.90ee22"
            ]
        ]
    },
    {
        "id": "7d48e13.90ee22",
        "type": "ui_table",
        "z": "1285e099664f8de3",
        "group": "571a38b1.5e3638",
        "name": "People",
        "order": 1,
        "width": "8",
        "height": "5",
        "columns": [
            {
                "field": "Name",
                "title": "Who",
                "width": "",
                "align": "left",
                "formatter": "html",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "Age",
                "title": "Age",
                "width": "40",
                "align": "center",
                "formatter": "plaintext",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "Color",
                "title": "",
                "width": "5%",
                "align": "left",
                "formatter": "color",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "Star",
                "title": "%",
                "width": "100",
                "align": "left",
                "formatter": "star",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "Pass",
                "title": "",
                "width": "5%",
                "align": "center",
                "formatter": "tickCross",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "Prog",
                "title": "",
                "width": "80",
                "align": "left",
                "formatter": "progress",
                "formatterParams": {
                    "target": "_blank"
                }
            },
            {
                "field": "web",
                "title": "URL",
                "width": "",
                "align": "left",
                "formatter": "link",
                "formatterParams": {
                    "target": "_blank"
                }
            }
        ],
        "outputs": 1,
        "cts": true,
        "x": 660,
        "y": 220,
        "wires": [
            [
                "41e82408528a8563"
            ]
        ]
    },
    {
        "id": "bada4241cd727c4c",
        "type": "function",
        "z": "1285e099664f8de3",
        "name": "getSelectedData",
        "func": "msg.payload={\n    command:\"getSelectedData\",\n    arguments: [],\n    returnPromise: true\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 434,
        "y": 340,
        "wires": [
            [
                "7d48e13.90ee22"
            ]
        ],
        "info": "# deleteRow(row / [rows])\n\n`row=singleId`\n\nor\n\n`row=[array of IDs]` // seems there is a bug/issue in tabulator\n\ndelete a single the row with an id in the middle from 1 to lastId, hope it exists.\n\nWill fail on the second hit if you inject this two times because the id wad deleteted on the first"
    },
    {
        "id": "5986ac8dcafb9ec6",
        "type": "inject",
        "z": "1285e099664f8de3",
        "name": "getSelectedRows",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 340,
        "wires": [
            [
                "bada4241cd727c4c"
            ]
        ]
    },
    {
        "id": "b6c6a086d09a0f62",
        "type": "comment",
        "z": "1285e099664f8de3",
        "name": "Rich table",
        "info": "",
        "x": 180,
        "y": 140,
        "wires": []
    },
    {
        "id": "cde1b7dff14c3bef",
        "type": "inject",
        "z": "1285e099664f8de3",
        "name": "clearData",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 300,
        "wires": [
            [
                "e5e684ef22f2dbb2"
            ]
        ]
    },
    {
        "id": "e5e684ef22f2dbb2",
        "type": "function",
        "z": "1285e099664f8de3",
        "name": "clearData",
        "func": "\nmsg.payload={\n    command:\"clearData\",\n    arguments: [],\n    returnPromise: true\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 280,
        "wires": [
            [
                "7d48e13.90ee22"
            ]
        ],
        "info": "# clear data\n\nunfortunately this command (currently) do not send a promise back! So we have to pass it directly to the table handler"
    },
    {
        "id": "41e82408528a8563",
        "type": "debug",
        "z": "1285e099664f8de3",
        "name": "data return from command",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 220,
        "wires": []
    },
    {
        "id": "3a570391f78b510c",
        "type": "inject",
        "z": "1285e099664f8de3",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 210,
        "y": 180,
        "wires": [
            [
                "a796b0823c216563"
            ]
        ]
    },
    {
        "id": "a796b0823c216563",
        "type": "change",
        "z": "1285e099664f8de3",
        "name": "ui_control",
        "rules": [
            {
                "t": "set",
                "p": "ui_control",
                "pt": "msg",
                "to": "{\"tabulator\":{\"selectable\":3,\"columns\":[{\"formatter\":\"rowSelection\",\"titleFormatter\":\"rowSelection\",\"align\":\"center\",\"headerSort\":false}]}}",
                "tot": "json"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 380,
        "y": 180,
        "wires": [
            [
                "7d48e13.90ee22"
            ]
        ]
    },
    {
        "id": "571a38b1.5e3638",
        "type": "ui_group",
        "name": "Richer Table",
        "tab": "29ec6908.552b36",
        "order": 1,
        "disp": true,
        "width": "12",
        "collapse": false,
        "className": ""
    },
    {
        "id": "29ec6908.552b36",
        "type": "ui_tab",
        "name": "Home",
        "icon": "track_changes",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

@zhangmx
Copy link
Author

zhangmx commented Mar 28, 2023

Need any other information or materials? When can branches be merged?

Do you have an example flow that shows/tests how this works ?

Thanks

@dceejay
Copy link
Member

dceejay commented Mar 28, 2023

When we get an hour off from the day job to review it properly.

@zhangmx
Copy link
Author

zhangmx commented Mar 28, 2023

Thank you @dceejay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants