From 26a701c4410736c6af763c0155573f8795fdd846 Mon Sep 17 00:00:00 2001 From: TonProtofy Date: Tue, 12 Nov 2024 20:35:59 +0100 Subject: [PATCH] Adds select input type to Action component for dynamic option selection --- packages/protodevice/src/Subsystem.tsx | 45 ++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/packages/protodevice/src/Subsystem.tsx b/packages/protodevice/src/Subsystem.tsx index 7b3d16fda..63e3f7e52 100644 --- a/packages/protodevice/src/Subsystem.tsx +++ b/packages/protodevice/src/Subsystem.tsx @@ -1,9 +1,9 @@ import React, { useState } from "react"; -import { XStack, YStack, Text, Paragraph, Button, Input, Spinner, Switch, useToastController } from '@my/ui'; +import { XStack, YStack, Text, Paragraph, Button, Input, Spinner, Switch, useToastController, Select } from '@my/ui'; import { ContainerLarge } from 'protolib/components/Container'; import { Tinted } from 'protolib/components/Tinted'; import { Chip } from 'protolib/components/Chip'; -import { Megaphone, MegaphoneOff } from "@tamagui/lucide-icons" +import { Megaphone, MegaphoneOff, ChevronDown, Check } from "@tamagui/lucide-icons" import { useMqttState, useSubscription } from 'protolib/lib/mqtt'; import { useFetch } from 'protolib/lib/useFetch' import { DeviceSubsystemMonitor, getPeripheralTopic } from 'protolib/bundles/devices/devices/devicesSchemas'; @@ -111,6 +111,8 @@ const Action = ({ deviceName, action }) => { var type if (action?.payload?.value) { type = "button" + } else if (Array.isArray(action?.payload)) { + type = "select" } else if (action?.payload?.type != "json-schema") { type = "input" } @@ -146,6 +148,45 @@ const Action = ({ deviceName, action }) => { Send + case "select": + const [selectedOption, setSelectedOption] = useState(action.payload[0].value); + const payloadOptions = Array.isArray(action.payload.value) ? action.payload.value : []; + + console.log("🤖 ~ Action ~ selectedOption:", selectedOption) + + return + {action.label ?? action.name} + + + default: return {action.label ?? action.name}