From b929100d308279957c57b49e804e4f8634b33a17 Mon Sep 17 00:00:00 2001 From: Jonas Plum Date: Sat, 3 Aug 2024 13:43:41 +0200 Subject: [PATCH] feat: enum custom field (#1090) --- Makefile | 9 ++++++ fakedata/records.go | 2 +- migrations/3_defaultdata.go | 30 +++++++++++++++++-- ui/package.json | 2 +- .../components/form/JSONSchemaFormFields.vue | 28 +++++++++++++++++ ui/src/lib/types.ts | 1 + 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index cbc206f..5bf7490 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,15 @@ dev: go run . fake-data go run . serve +.PHONY: dev-10000 +dev-10000: + @echo "Running..." + rm -rf catalyst_data + go run . admin create admin@catalyst-soar.com 1234567890 + go run . set-feature-flags dev + go run . fake-data --users 100 --tickets 10000 + go run . serve + .PHONY: dev-ui serve-ui: cd ui && bun dev --port 3000 diff --git a/fakedata/records.go b/fakedata/records.go index 1b9489a..d006ce7 100644 --- a/fakedata/records.go +++ b/fakedata/records.go @@ -128,7 +128,7 @@ func ticketRecords(dao *daos.Dao, users, types []*models.Record, count int) []*m record.Set("description", fakeTicketDescription()) record.Set("open", gofakeit.Bool()) record.Set("schema", `{"type":"object","properties":{"tlp":{"title":"TLP","type":"string"}}}`) - record.Set("state", `{"tlp":"AMBER"}`) + record.Set("state", `{"severity":"Medium"}`) record.Set("owner", random(users).GetId()) records = append(records, record) diff --git a/migrations/3_defaultdata.go b/migrations/3_defaultdata.go index 2a2ac87..dfdddd5 100644 --- a/migrations/3_defaultdata.go +++ b/migrations/3_defaultdata.go @@ -1,6 +1,8 @@ package migrations import ( + "encoding/json" + "github.com/pocketbase/dbx" "github.com/pocketbase/pocketbase/daos" "github.com/pocketbase/pocketbase/models" @@ -33,7 +35,16 @@ func typeRecords(dao *daos.Dao) []*models.Record { record.Set("singular", "Incident") record.Set("plural", "Incidents") record.Set("icon", "Flame") - record.Set("schema", `{"type":"object","properties":{"tlp":{"title":"TLP","type":"string"}}}`) + record.Set("schema", s(map[string]any{ + "type": "object", + "properties": map[string]any{ + "severity": map[string]any{ + "title": "Severity", + "enum": []string{"Low", "Medium", "High"}, + }, + }, + "required": []string{"severity"}, + })) records = append(records, record) @@ -42,9 +53,24 @@ func typeRecords(dao *daos.Dao) []*models.Record { record.Set("singular", "Alert") record.Set("plural", "Alerts") record.Set("icon", "AlertTriangle") - record.Set("schema", `{"type":"object","properties":{"severity":{"title":"Severity","type":"string"}},"required": ["severity"]}`) + record.Set("schema", s(map[string]any{ + "type": "object", + "properties": map[string]any{ + "severity": map[string]any{ + "title": "Severity", + "enum": []string{"Low", "Medium", "High"}, + }, + }, + "required": []string{"severity"}, + })) records = append(records, record) return records } + +func s(m map[string]any) string { + b, _ := json.Marshal(m) //nolint:errchkjson + + return string(b) +} diff --git a/ui/package.json b/ui/package.json index 7399420..22c3920 100644 --- a/ui/package.json +++ b/ui/package.json @@ -9,7 +9,7 @@ "preview": "vite preview", "build-only": "vite build", "type-check": "vue-tsc --build --force", - "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", + "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path ../.gitignore", "format": "prettier --write src/" }, "dependencies": { diff --git a/ui/src/components/form/JSONSchemaFormFields.vue b/ui/src/components/form/JSONSchemaFormFields.vue index 651380e..d909659 100644 --- a/ui/src/components/form/JSONSchemaFormFields.vue +++ b/ui/src/components/form/JSONSchemaFormFields.vue @@ -2,6 +2,14 @@ import { Checkbox } from '@/components/ui/checkbox' import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form' import { Input } from '@/components/ui/input' +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select' import { onMounted, ref, watch } from 'vue' @@ -34,6 +42,26 @@ watch(