Skip to content

Commit

Permalink
Added dummy UI schema and fromtend implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
iberdinsky-skilld committed Mar 27, 2024
1 parent b5f2466 commit d9b6564
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 44 deletions.
12 changes: 10 additions & 2 deletions client/src/pages/actions/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { Edit } from '@refinedev/mui'
import type { IChangeEvent } from '@rjsf/core'
import { withTheme } from '@rjsf/core'
import { Theme } from '@rjsf/mui'
import type { RJSFSchema } from '@rjsf/utils'
import type { RJSFSchema, UiSchema } from '@rjsf/utils'
import validator from '@rjsf/validator-ajv8'
import type { FC } from 'react'

// @todo move to types
interface IActionData extends BaseRecord {
jsonschema: RJSFSchema
uischema: UiSchema
}

interface IRunInfo extends BaseRecord {
Expand Down Expand Up @@ -68,6 +69,8 @@ export const ActionShow: FC<IResourceComponentsProps> = () => {

const jsonschema = queryResult?.data?.data?.jsonschema

const uischema = queryResult?.data?.data?.uischema || {}

if (jsonschema) {
// @todo I actually don't know for the moment how to overcome error
// "no schema with key or ref" produced when schema is defined.
Expand Down Expand Up @@ -110,7 +113,12 @@ export const ActionShow: FC<IResourceComponentsProps> = () => {
<Edit isLoading={isFetching}>
<ActionRunningState isLoading={isFetchingRunning} list={running} />
{jsonschema && (
<Form schema={jsonschema} validator={validator} onSubmit={onSubmit} />
<Form
schema={jsonschema}
uiSchema={uischema}
validator={validator}
onSubmit={onSubmit}
/>
)}
</Edit>
)
Expand Down
10 changes: 10 additions & 0 deletions example/rjsf/actions/arrays/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
action:
title: RJSF Example of Arrays
description: RJSF Arrays arguments
image: alpine:latest
command: ["sh", "-c", "for i in $(seq 60); do echo $$i; sleep 1; done"]
arguments:
- name: optarr
title: Array
description: Some additional info for option
type: array
7 changes: 1 addition & 6 deletions example/rjsf/actions/enumeration/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,4 @@ action:
- name: radio
title: Radio
type: string
enum: [ Ola, Hello, Bonjour, Buongiorno, GutenTag ]
- name: buttonGroup
type: string
enum: [ Ola, Hello, Bonjour, Buongiorno, GutenTag ]
default: Ola
description: With default value set
enum: [ Ola, Hello, Bonjour, Buongiorno, GutenTag ]
7 changes: 3 additions & 4 deletions example/rjsf/actions/enumeration/ui-schema.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
uiSchema:
buttonGroup:
'ui:widget': button
radio:
'ui:widget': radio
arguments:
radio:
'ui:widget': radio
9 changes: 5 additions & 4 deletions example/rjsf/actions/numbers/ui-schema.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
uiSchema:
range:
'ui:widget': range
rangeConstrained:
'ui:widget': range
arguments:
range:
'ui:widget': range
rangeConstrained:
'ui:widget': range
11 changes: 6 additions & 5 deletions example/rjsf/actions/strings/ui-schema.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
uiSchema:
textArea:
'ui:widget': textarea
'ui:placeholder': This is a placeholder
color:
'ui:widget': color
arguments:
textArea:
'ui:widget': textarea
'ui:placeholder': This is a placeholder
color:
'ui:widget': color
27 changes: 27 additions & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,38 @@ func apiActionFull(baseURL string, a *action.Action) ActionFull {
jsonschema := a.JSONSchema()
jsonschema.ID = fmt.Sprintf("%s/actions/%s/schema.json", baseURL, url.QueryEscape(a.ID))
def := a.ActionDef()

// TODO: parse this optional ui-schema.yaml in same dir with action.yaml
// example/rjsf/actions/enumeration/ui-schema.yaml
// https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema
// Here currently all ui-schema.yaml files merged toghether.
dummyUiSchema := map[string]interface{}{
"arguments": map[string]interface{}{
"range": map[string]interface{}{
"ui:widget": "range",
},
"rangeConstrained": map[string]interface{}{
"ui:widget": "range",
},
"textArea": map[string]interface{}{
"ui:widget": "textarea",
"ui:placeholder": "This is a placeholder",
},
"color": map[string]interface{}{
"ui:widget": "color",
},
"radio": map[string]interface{}{
"ui:widget": "radio",
},
},
}

return ActionFull{
ID: a.ID,
Title: def.Title,
Description: def.Description,
JSONSchema: jsonschema,
UISchema: &dummyUiSchema,
}
}

Expand Down
48 changes: 25 additions & 23 deletions server/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ components:
x-go-type: "jsonschema.Schema"
x-go-type-import:
path: "github.com/launchrctl/launchr/pkg/jsonschema"
uischema:
type: object
x-go-name: "UISchema"
x-go-type: "map[string]interface{}"
ActionRunParams:
allOf:
- type: object
Expand Down

0 comments on commit d9b6564

Please sign in to comment.