From 800e0e6cf94e72252fcbd37114499c04bcf33bc9 Mon Sep 17 00:00:00 2001 From: Tim Raderschad Date: Sun, 9 Mar 2025 14:13:12 +0100 Subject: [PATCH] feat(devtools): enhance UI/UX components and update package versions --- apps/web/CHANGELOG.md | 8 + apps/web/package.json | 2 +- packages/devtools/.storybook/main.ts | 3 + packages/devtools/CHANGELOG.md | 6 + packages/devtools/package.json | 2 +- packages/devtools/src/Devtools.stories.ts | 10 +- packages/devtools/src/Devtools.svelte | 528 +++++++++++++----- .../src/components/ChevronIcon.svelte | 33 ++ packages/devtools/src/components/Input.svelte | 63 ++- packages/devtools/src/components/Modal.svelte | 168 ++++-- .../devtools/src/components/Select.svelte | 116 ++-- .../devtools/src/components/Switch.svelte | 134 +++-- packages/devtools/src/lib/storage.ts | 26 + 13 files changed, 825 insertions(+), 274 deletions(-) create mode 100644 packages/devtools/src/components/ChevronIcon.svelte diff --git a/apps/web/CHANGELOG.md b/apps/web/CHANGELOG.md index 0855b9db..ca9f591c 100644 --- a/apps/web/CHANGELOG.md +++ b/apps/web/CHANGELOG.md @@ -1,5 +1,13 @@ # web +## 0.2.42 + +### Patch Changes + +- Updated dependencies + - @tryabby/devtools@8.0.2 + - @tryabby/next@7.0.1 + ## 0.2.41 ### Patch Changes diff --git a/apps/web/package.json b/apps/web/package.json index 1079ec65..3015892b 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,6 +1,6 @@ { "name": "web", - "version": "0.2.41", + "version": "0.2.42", "private": true, "scripts": { "prebuild": "pnpm run db:generate", diff --git a/packages/devtools/.storybook/main.ts b/packages/devtools/.storybook/main.ts index c132c45d..318b77c7 100644 --- a/packages/devtools/.storybook/main.ts +++ b/packages/devtools/.storybook/main.ts @@ -1,5 +1,8 @@ import type { StorybookConfig } from "@storybook/svelte-vite"; const config: StorybookConfig = { + core: { + disableTelemetry: true, + }, stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx|svelte)"], addons: [ "@storybook/addon-links", diff --git a/packages/devtools/CHANGELOG.md b/packages/devtools/CHANGELOG.md index 9bcdf2cc..b7d5450f 100644 --- a/packages/devtools/CHANGELOG.md +++ b/packages/devtools/CHANGELOG.md @@ -1,5 +1,11 @@ # @tryabby/devtools +## 8.0.2 + +### Patch Changes + +- improve ui/ux + ## 8.0.1 ### Patch Changes diff --git a/packages/devtools/package.json b/packages/devtools/package.json index 9dee2a50..2d2c45c4 100644 --- a/packages/devtools/package.json +++ b/packages/devtools/package.json @@ -1,6 +1,6 @@ { "name": "@tryabby/devtools", - "version": "8.0.1", + "version": "8.0.2", "type": "module", "files": ["dist"], "main": "dist/index.umd.cjs", diff --git a/packages/devtools/src/Devtools.stories.ts b/packages/devtools/src/Devtools.stories.ts index 4750f4ea..b840e446 100644 --- a/packages/devtools/src/Devtools.stories.ts +++ b/packages/devtools/src/Devtools.stories.ts @@ -9,13 +9,13 @@ const abbyMock = { subscribe: () => () => {}, getProjectData: () => ({ flags: { - "flag-1": true, - "flag-2": false, + "flag-1": { value: true }, + "flag-2": { value: false }, }, remoteConfig: { - "config-1": "string-value", - "config-2": 42, - "config-3": { type: "object/json" }, + "config-1": { value: "string-value" }, + "config-2": { value: 42 }, + "config-3": { value: { type: "object/json" } }, }, tests: { "test-1": { selectedVariant: "A", variants: ["A", "B"] }, diff --git a/packages/devtools/src/Devtools.svelte b/packages/devtools/src/Devtools.svelte index 1e36c2d1..4960f9ea 100644 --- a/packages/devtools/src/Devtools.svelte +++ b/packages/devtools/src/Devtools.svelte @@ -9,9 +9,16 @@ import { quintInOut } from "svelte/easing"; import { crossfade } from "svelte/transition"; + import { slide } from "svelte/transition"; import Input from "./components/Input.svelte"; import Modal from "./components/Modal.svelte"; - import { getShowDevtools, setShowDevtools } from "./lib/storage"; + import { + getSections, + getShowDevtools, + setShowDevtools, + setSections, + } from "./lib/storage"; + import ChevronIcon from "./components/ChevronIcon.svelte"; export let position: | "top-left" @@ -26,6 +33,17 @@ export let abby: Abby; let show = false; + // Track open/closed state of each section + let openSections = { + flags: true, + remoteConfig: true, + tests: true, + }; + + const toggleSection = (section) => { + openSections[section] = !openSections[section]; + setSections(openSections); + }; const onToggleVisibility = () => { show = !show; @@ -49,6 +67,9 @@ // hacky way to sync props <> state onMount(async () => { const { hasStoredValue, showDevtools } = getShowDevtools(); + const savedSections = getSections(); + + openSections = savedSections; if (hasStoredValue) { show = showDevtools; @@ -68,11 +89,19 @@ const { flags, tests, remoteConfig } = abby?.getProjectData() ?? {}; const [send, receive] = crossfade({ - duration: 200, + duration: 300, easing: quintInOut, }); const key = "devtools"; + + const flagsEntries = Object.entries(flags || {}); + const remoteConfigEntries = Object.entries(remoteConfig || {}); + const testsEntries = Object.entries(tests || {}); + + $: { + console.log(remoteConfigEntries); + } {#if show} @@ -95,89 +124,187 @@ >

Abby Devtools

-
- Env: {abby.getConfig().currentEnvironment} +
+ Environment: + {abby.getConfig().currentEnvironment} +

-

Flags:

- {#each Object.entries(flags) as [flagName, flagValue]} - { - window.postMessage( - { type: "abby:update-flag", flagName, newValue }, - "*" - ); - abby.updateFlag(flagName, newValue); - }} - /> - {/each} +
+ + + {#if openSections.flags} +
+
+ {#if flagsEntries.length > 0} + {#each flagsEntries as [flagName, flagValue]} + { + window.postMessage( + { type: "abby:update-flag", flagName, newValue }, + "*" + ); + abby.updateFlag(flagName, newValue); + }} + /> + {/each} + {:else} +
+

No feature flags found

+

+ Add feature flags in your Abby configuration +

+
+ {/if} +
+
+ {/if} +

-

Remote Config:

- {#each Object.entries(remoteConfig) as [remoteConfigName, remoteConfigValue]} - {#if typeof remoteConfigValue.value === "string" || typeof remoteConfigValue.value === "number"} - { - window.postMessage( - { type: "abby:update-flag", remoteConfigName, newValue }, - "*" - ); - abby.updateRemoteConfig(remoteConfigName, newValue); - }} - /> - {:else if typeof remoteConfigValue.value === "object"} -
-

{remoteConfigName}

- { - window.postMessage( - { type: "abby:update-flag", remoteConfigName, newValue }, - "*" - ); - abby.updateRemoteConfig(remoteConfigName, newValue); - }} - /> + +
+ + + {#if openSections.remoteConfig} +
+
+ {#if remoteConfigEntries.length > 0} + {#each remoteConfigEntries as [remoteConfigName, remoteConfigValue]} + {#if typeof remoteConfigValue.value === "string" || typeof remoteConfigValue.value === "number"} + { + window.postMessage( + { + type: "abby:update-flag", + remoteConfigName, + newValue, + }, + "*" + ); + abby.updateRemoteConfig(remoteConfigName, newValue); + }} + /> + {:else if typeof remoteConfigValue.value === "object"} +
+

{remoteConfigName}

+ { + window.postMessage( + { + type: "abby:update-flag", + remoteConfigName, + newValue, + }, + "*" + ); + abby.updateRemoteConfig(remoteConfigName, newValue); + }} + /> +
+ {/if} + {/each} + {:else} +
+

No remote configs found

+

+ Add remote configs in your Abby configuration +

+
+ {/if} +
{/if} - {/each} +

-

A/B Tests:

- {#each Object.entries(tests) as [testName, { selectedVariant, variants }]} - ({ + label: v, + value: v, + }))} + onChange={(newValue) => { + window.postMessage( + { type: "abby:select-variant", testName, newValue }, + "*" + ); + abby.updateLocalVariant(testName, newValue); + }} + /> + {/each} + {:else} +
+

No A/B tests found

+

Add A/B tests in your Abby configuration

+
+ {/if} +
+
+ {/if} + + + {#if flagsEntries.length === 0 && remoteConfigEntries.length === 0 && testsEntries.length === 0} +
+
+

No flags, remote configs, or A/B tests found.

+

+ Make sure you have defined them in your Abby configuration. +

+
+ {/if} {:else} {/if} diff --git a/packages/devtools/src/components/ChevronIcon.svelte b/packages/devtools/src/components/ChevronIcon.svelte new file mode 100644 index 00000000..22ca0811 --- /dev/null +++ b/packages/devtools/src/components/ChevronIcon.svelte @@ -0,0 +1,33 @@ + + +
+ + + +
+ + diff --git a/packages/devtools/src/components/Input.svelte b/packages/devtools/src/components/Input.svelte index fdf54b20..ef58ce74 100644 --- a/packages/devtools/src/components/Input.svelte +++ b/packages/devtools/src/components/Input.svelte @@ -6,8 +6,13 @@ export let id: string; -