mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 07:12:46 +01:00
feat: enum custom field (#1090)
This commit is contained in:
9
Makefile
9
Makefile
@@ -48,6 +48,15 @@ dev:
|
|||||||
go run . fake-data
|
go run . fake-data
|
||||||
go run . serve
|
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
|
.PHONY: dev-ui
|
||||||
serve-ui:
|
serve-ui:
|
||||||
cd ui && bun dev --port 3000
|
cd ui && bun dev --port 3000
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ func ticketRecords(dao *daos.Dao, users, types []*models.Record, count int) []*m
|
|||||||
record.Set("description", fakeTicketDescription())
|
record.Set("description", fakeTicketDescription())
|
||||||
record.Set("open", gofakeit.Bool())
|
record.Set("open", gofakeit.Bool())
|
||||||
record.Set("schema", `{"type":"object","properties":{"tlp":{"title":"TLP","type":"string"}}}`)
|
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())
|
record.Set("owner", random(users).GetId())
|
||||||
|
|
||||||
records = append(records, record)
|
records = append(records, record)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/pocketbase/dbx"
|
"github.com/pocketbase/dbx"
|
||||||
"github.com/pocketbase/pocketbase/daos"
|
"github.com/pocketbase/pocketbase/daos"
|
||||||
"github.com/pocketbase/pocketbase/models"
|
"github.com/pocketbase/pocketbase/models"
|
||||||
@@ -33,7 +35,16 @@ func typeRecords(dao *daos.Dao) []*models.Record {
|
|||||||
record.Set("singular", "Incident")
|
record.Set("singular", "Incident")
|
||||||
record.Set("plural", "Incidents")
|
record.Set("plural", "Incidents")
|
||||||
record.Set("icon", "Flame")
|
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)
|
records = append(records, record)
|
||||||
|
|
||||||
@@ -42,9 +53,24 @@ func typeRecords(dao *daos.Dao) []*models.Record {
|
|||||||
record.Set("singular", "Alert")
|
record.Set("singular", "Alert")
|
||||||
record.Set("plural", "Alerts")
|
record.Set("plural", "Alerts")
|
||||||
record.Set("icon", "AlertTriangle")
|
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)
|
records = append(records, record)
|
||||||
|
|
||||||
return records
|
return records
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func s(m map[string]any) string {
|
||||||
|
b, _ := json.Marshal(m) //nolint:errchkjson
|
||||||
|
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"build-only": "vite build",
|
"build-only": "vite build",
|
||||||
"type-check": "vue-tsc --build --force",
|
"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/"
|
"format": "prettier --write src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
|
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue
|
||||||
|
} from '@/components/ui/select'
|
||||||
|
|
||||||
import { onMounted, ref, watch } from 'vue'
|
import { onMounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
@@ -34,6 +42,26 @@ watch(
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-for="(property, key) in schema.properties" :key="key">
|
<div v-for="(property, key) in schema.properties" :key="key">
|
||||||
|
<FormField v-if="property.enum" :name="key" v-slot="{ componentField }" v-model="formdata[key]">
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel :for="key" class="text-right">
|
||||||
|
{{ property.title }}
|
||||||
|
</FormLabel>
|
||||||
|
<Select :id="key" class="col-span-3" v-bind="componentField">
|
||||||
|
<SelectTrigger class="font-medium">
|
||||||
|
<SelectValue :placeholder="'Select a ' + property.title" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectGroup>
|
||||||
|
<SelectItem v-for="option in property.enum" :key="option" :value="option">
|
||||||
|
{{ option }}
|
||||||
|
</SelectItem>
|
||||||
|
</SelectGroup>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
</FormField>
|
||||||
<FormField
|
<FormField
|
||||||
v-if="property.type === 'string'"
|
v-if="property.type === 'string'"
|
||||||
:name="key"
|
:name="key"
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ export interface JSONSchema {
|
|||||||
title: string
|
title: string
|
||||||
type: string
|
type: string
|
||||||
description?: string
|
description?: string
|
||||||
|
enum?: Array<string>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
required?: Array<string>
|
required?: Array<string>
|
||||||
|
|||||||
Reference in New Issue
Block a user