From 8e0605aae63581d804bb7c68487a25e78347a76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romaric=20Philog=C3=A8ne?= Date: Sat, 16 Dec 2023 16:34:13 +0100 Subject: [PATCH] wip: add frontend dynamic fields for service catalog --- backend/examples/config.yaml | 60 ++-- backend/src/yaml_config.rs | 1 + frontend/src/components/SelfService.tsx | 22 +- frontend/src/components/SelfServiceCard.tsx | 1 - .../src/components/SelfServiceSideOver.tsx | 305 ------------------ .../src/components/SelfServiceSlideOver.tsx | 118 +++++++ .../self-service-fields/BooleanField.tsx | 63 ++++ .../self-service-fields/TextField.tsx | 38 +++ .../self-service-fields/TextareaField.tsx | 32 ++ 9 files changed, 305 insertions(+), 335 deletions(-) delete mode 100644 frontend/src/components/SelfServiceSideOver.tsx create mode 100644 frontend/src/components/SelfServiceSlideOver.tsx create mode 100644 frontend/src/components/self-service-fields/BooleanField.tsx create mode 100644 frontend/src/components/self-service-fields/TextField.tsx create mode 100644 frontend/src/components/self-service-fields/TextareaField.tsx diff --git a/backend/examples/config.yaml b/backend/examples/config.yaml index 075e18c..98b0b36 100644 --- a/backend/examples/config.yaml +++ b/backend/examples/config.yaml @@ -4,18 +4,34 @@ catalogs: description: Default catalog services: - slug: new-testing-environment - name: new testing environment - description: spin up a testing environment - icon: https://example.com/icon.png + name: New Testing Environment + description: spin up a temporary testing environment + icon: target fields: - - slug: environment-name - title: environment name + - slug: name + title: Name description: provide a name for your environment placeholder: testing-123 - type: string + type: text default: testing-123 required: true - autocomplete-fetcher: ./your-script.py + - slug: description + title: Description + description: provide a description for your environment - what's good for? + type: textarea + - slug: ttl + title: TTL + description: Time to live for your environment (in hours) + placeholder: 24 + type: number + default: 24 + required: true + - slug: seed + title: Seed + description: Do you want to seed your environment with some data? + placeholder: 24 + type: boolean + default: true validate: - command: - bash @@ -38,16 +54,16 @@ catalogs: - bash - post-validation-script-3.sh # AND finally this one output-model: string (optional) # model name - - slug: new-testing-environment-2 - name: new testing environment 2 - description: spin up a testing environment 2 - icon: https://example.com/icon.png + - slug: shutdown-testing-environment + name: Shutdown Testing Environment + description: shutdown a temporary testing environment + icon: trash fields: - slug: environment-name title: environment name description: provide a name for your environment placeholder: testing-123 - type: string + type: text default: testing-123 required: true autocomplete-fetcher: ./your-script.py @@ -80,55 +96,55 @@ catalogs: - slug: another-service name: another service description: another service - icon: https://example.com/icon.png + icon: target fields: - slug: field-1 title: field 1 description: field 1 placeholder: field 1 - type: string + type: text default: field 1 required: true - slug: field-2 title: field 2 description: field 2 placeholder: field 2 - type: string + type: text default: field 2 required: true - slug: field-3 title: field 3 description: field 3 placeholder: field 3 - type: string + type: text default: field 3 required: true - slug: field-4 title: field 4 description: field 4 placeholder: field 4 - type: string + type: text default: field 4 required: true - slug: field-5 title: field 5 description: field 5 placeholder: field 5 - type: string + type: text default: field 5 required: true - slug: field-6 title: field 6 description: field 6 placeholder: field 6 - type: string + type: text default: field 6 required: true - slug: field-7 title: field 7 description: field 7 placeholder: field 7 - type: string + type: text default: field 7 required: true - slug: field-8 @@ -142,14 +158,14 @@ catalogs: title: field 9 description: field 9 placeholder: field 9 - type: string + type: text default: field 9 required: true - slug: field-10 title: field 10 description: field 10 placeholder: field 10 - type: string + type: text models: - name: string description: string (optional) diff --git a/backend/src/yaml_config.rs b/backend/src/yaml_config.rs index 950dcb6..ce31c06 100644 --- a/backend/src/yaml_config.rs +++ b/backend/src/yaml_config.rs @@ -22,6 +22,7 @@ pub struct CatalogServiceYamlConfig { pub slug: String, pub name: String, pub description: Option, + pub icon: Option, pub fields: Option>, pub validate: Option>, pub post_validate: Option>, diff --git a/frontend/src/components/SelfService.tsx b/frontend/src/components/SelfService.tsx index 1fc7d2d..0aa0584 100644 --- a/frontend/src/components/SelfService.tsx +++ b/frontend/src/components/SelfService.tsx @@ -1,15 +1,27 @@ import EmptyState from "@/components/EmptyState.tsx"; import SelfServiceCard from "@/components/SelfServiceCard.tsx"; import {TargetIcon} from "lucide-react"; -import SelfServiceSideOver from "@/components/SelfServiceSideOver.tsx"; +import SelfServiceSlideOver from "@/components/SelfServiceSlideOver.tsx"; import {useState} from "react"; import {Transition} from "@headlessui/react"; +import {TrashIcon} from "@heroicons/react/24/outline"; interface Props { catalogSlug: string services: any[] } +function getIcon(icon?: string): JSX.Element { + switch (icon?.toLowerCase()) { + case 'target': + return