igrek8 / dynamic-inputs

vscode dynamic inputs
MIT License
4 stars 2 forks source link

Single selection doesn't work #2

Closed fireplusteam closed 5 months ago

fireplusteam commented 5 months ago

With a single selection configuration, it returns always undefined value after selection

"quickPickOptions": {
                    "canPickMany": false

only works with "canPickMany": true

Full example:

{
            "id": "myDestinationDevice",
            "type": "command",
            // first try to read from the disk or select again
            "command": "dynamic-inputs.read",
            "args": {
                "command": "bash",
                // a script which prints JSON array to stdout as the last line
                "args": [
                    "${workspaceFolder}/.vscode/populate_devices.sh"
                ],
                "envFile": "${workspaceFolder}/.vscode/.env",
                "cwd": "${workspaceFolder}",
                // memoize the selection for the future
                "var": "myDestinationDevice",
                // map options to values
                "unwrap": "$[*].value",
                "serializer": "plain",
                "quickPickOptions": {
                    "canPickMany": true, // should be false, but it's not working for some reason
                    //"ignoreFocusOut": true,
                    "placeHolder": "Please select Device",
                    "title": "Device"
                }
            }
        }

and here's the command:

{
            "label": "iOS: Select Destination Device",
            "type": "shell",
            "command": ".vscode/update_enviroment.sh",
            "args": [
                "-destinationDevice",
                "${input:myDestinationDevice}"
            ],
            "problemMatcher": [], 
            "dependsOn":["iOS: Validate Enviroment"],
            "group": "none"
        },
Mac OS: Version 14.1.2 , 
vs code 
Version: 1.85.2 (Universal)
Commit: 8b3775030ed1a69b13e4f4c628c612102e30a681
Date: 2024-01-18T06:40:32.531Z (1 wk ago)
Electron: 25.9.7
ElectronBuildId: 26354273
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.1.0
igrek8 commented 5 months ago

Hello @fireplusteam.

It looks like your unwrap resolves to undefined. Can you test $[*].value against the output of populate_devices.sh in https://jsonpath.com?

Could you please include the code in populate_devices.sh?

It'd be great if you could format the code using backticks.

igrek8 commented 5 months ago

For example:

fireplusteam commented 5 months ago

for me it's always undefined when I put json like following as a last line with simply echo and "canPickMany": false:

[{"label": "A"}, {"label": "B"}, {"label": "C"}]

or

[{"label": "A", "value": "id_A"}, {"label": "B", "value": "id_B"}, {"label": "C", "value": "id_C"}]

However when "canPickMany": true, it works fine

though it works fine for and "canPickMany": false

["A", "B", "C"]
igrek8 commented 5 months ago

Case 1

Make sure your shell uses echo.

echo '[{"label": "A"}, {"label": "B"}, {"label": "C"}]'

Given that each array item has only the key label you need to change unwrap to $.label.

fireplusteam commented 5 months ago

thanks, but I tried with

[{"label": "A", "value": "id_A"}, {"label": "B", "value": "id_B"}, {"label": "C", "value": "id_C"}]

and results is the same

igrek8 commented 5 months ago

@fireplusteam when you set canPickMany: false then the selection will always be an object. Therefore, to resolve your value you need to use "unwrap": "$.value".

I will add this to README.md once I have time.

fireplusteam commented 5 months ago

nevermind, if looks like "picked" along with "label" and "value" causing the issue in single selection mode, delete that field and now it started to work, thanks for help

fireplusteam commented 5 months ago

also could you please try for this json:

[{"label": "platform=iOS,name=Any iOS Device", "value": "id=dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder"}, {"label": "platform=iOS Simulator,name=Any iOS Simulator Device", "value": "id=dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPad (9th generation)", "value": "id=C80E09F5-559F-42C3-B91D-07870AD4370F"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPad (10th generation)", "value": "id=FFB22846-49E2-4F0D-BEDE-AA31BFB0050E"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPad (10th generation)", "value": "id=C2ED231E-D475-474C-963C-0E915641F8F0"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPad Air (5th generation)", "value": "id=F845681D-86CB-4DA9-BA1E-B738542E509F"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPad Air (5th generation)", "value": "id=E5E6D840-FA17-41DC-B788-7AD72195A905"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPad Air (5th generation)", "value": "id=3953B358-24D2-42C6-9655-7928C4046F5C"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPad Pro (9.7-inch)", "value": "id=46946292-055E-4178-AB3C-9E1D239A6A4F"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPad Pro (11-inch) (3rd generation)", "value": "id=68FD95F8-2F78-4FCB-9860-2767EA1F0264"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPad Pro (11-inch) (4th generation)", "value": "id=43612C74-00DF-4838-B6AF-8B51E7DAD4D4"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPad Pro (11-inch) (4th generation)", "value": "id=20C16DEE-FE17-47E2-BF7F-9F01D316CD23"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPad Pro (12.9-inch) (5th generation)", "value": "id=7892D349-BE22-427D-9B6D-FA8A5B9EDA45"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPad Pro (12.9-inch) (6th generation)", "value": "id=372767A6-7118-411F-878E-48BAD8834AD8"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPad Pro (12.9-inch) (6th generation)", "value": "id=5CF53B23-4E21-4B07-9F51-4229F2DA45CB"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPad mini (6th generation)", "value": "id=D1CB2172-92A5-460E-A832-402BB8BC3AB8"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPad mini (6th generation)", "value": "id=C445BE57-07F9-4095-9EA0-682148AAF9D6"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPad mini (6th generation)", "value": "id=D2723714-09C2-4620-9827-EAEF3379D590"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPhone 13", "value": "id=BA69A637-C37C-48C1-95AD-D42B0C1C2659"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPhone 13 Pro", "value": "id=2E86DBEC-5F3B-472E-B53E-A5B94E2C4DE3"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPhone 13 Pro Max", "value": "id=3ED6CE6C-C8FF-49EA-8DEB-EF8851484C38"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPhone 13 mini", "value": "id=CD733481-101D-4312-9E1A-0E3D1385ADAA"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPhone 14", "value": "id=38F1ADC1-9EBA-4E51-9A6C-910E0F4FB820"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPhone 14 Plus", "value": "id=1E668B8A-B2E6-47BA-8B91-5D0806B09F14"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPhone 14 Pro", "value": "id=80ECCC45-4E57-4A50-BE40-C138CFFFB212"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPhone 14 Pro Max", "value": "id=89CC8E97-060D-45DF-8149-AE1F7A9DE836"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPhone 15", "value": "id=86FFF701-E3A7-4F0C-BDF4-0829F596D857"}, {"label": "$(notebook-state-success) platform=iOS Simulator,OS=17.0.1,name=iPhone 15 Plus", "value": "id=AF218F9F-1883-4F45-91BB-2FFBD816F2F4"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPhone 15 Pro", "value": "id=F2A846F1-67D1-407E-87F0-7E08451C4F62"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPhone 15 Pro Max", "value": "id=5F1C1F36-52BB-4799-95CF-CFF49AC85BCE"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPhone SE (3rd generation)", "value": "id=44054A71-0BDA-443A-8911-867506820126"}, {"label": "platform=iOS Simulator,OS=16.1,name=iPhone SE (3rd generation)", "value": "id=5BF394CF-44D6-415C-A8C3-854B259EFFF6"}, {"label": "platform=iOS Simulator,OS=17.0.1,name=iPhone SE (3rd generation)", "value": "id=7E592EB1-4FEE-4C41-91FC-0568C44DD8FB"}, {"label": "platform=iOS Simulator,OS=15.4,name=iPod touch (7th generation)", "value": "id=DDD80D80-2426-49A8-89AB-222C28E570FE"}]

looks like for that json, it reports always undefined even though https://jsonpath.com/ reports ok for $[*].value

igrek8 commented 5 months ago

https://github.com/igrek8/dynamic-inputs/assets/7078731/958708eb-77ca-4509-b563-309ccfd10781

igrek8 commented 5 months ago

@fireplusteam if the issue has been resolved, you can close the PR.

fireplusteam commented 5 months ago

The PR is closed, thanks