From b2ef61ea0a391ccc1eb978e539e366d90edbeda7 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Thu, 4 Apr 2024 16:36:21 +0200 Subject: [PATCH] feat: add Resource type descriptions to the select box (#3091) This should clarify that Resource is a safe for using private keys inside them. image ## Steps for reproduction 1. create a variable 2. hover over type options ## Code Review - [ ] hi @TrySound , I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env.example` and the `builder/env-check.js` if mandatory --- .../settings-panel/variable-popover.tsx | 79 +++++++++++-------- .../design-system/src/components/select.tsx | 55 +++++++------ 2 files changed, 79 insertions(+), 55 deletions(-) diff --git a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx index 86d95203f8..c2a9850b2a 100644 --- a/apps/builder/app/builder/features/settings-panel/variable-popover.tsx +++ b/apps/builder/app/builder/features/settings-panel/variable-popover.tsx @@ -28,7 +28,6 @@ import { ProBadge, ScrollArea, Select, - SelectItem, Switch, TextArea, Tooltip, @@ -48,7 +47,6 @@ import { invalidateResource, } from "~/shared/nano-states"; import { serverSyncStore } from "~/shared/sync"; -import { humanizeString } from "~/shared/string-utils"; import { useField, type Field, @@ -390,40 +388,57 @@ const VariablePanel = forwardRef< } return "string"; }); - const typeOptions: VariableType[] = [ - "string", - "number", - "boolean", - "json", - "resource", - ]; - const getTypeLabel = (value: VariableType) => - value === "json" ? "JSON" : humanizeString(value); + + const typeOptions: Map< + VariableType, + { label: ReactNode; description: string } + > = new Map([ + ["string", { label: "String", description: "Any alphanumeric text." }], + [ + "number", + { + label: "Number", + description: "Any number, can be used in math expressions.", + }, + ], + [ + "boolean", + { label: "Boolean", description: "A boolean is a true/false switch." }, + ], + ["json", { label: "JSON", description: "Any JSON value" }], + [ + "resource", + { + label: ( + + Resource + {allowDynamicData === false && Pro} + + ), + description: + "A Resource is a configuration for secure data fetching. You can safely use secrets in any field.", + }, + ], + ]); const typeFieldElement = ( - + - - options={typeOptions} - getLabel={getTypeLabel} + + /> ); diff --git a/packages/design-system/src/components/select.tsx b/packages/design-system/src/components/select.tsx index f52e622136..92605459d7 100644 --- a/packages/design-system/src/components/select.tsx +++ b/packages/design-system/src/components/select.tsx @@ -138,13 +138,16 @@ export type SelectProps