Skip to content

Commit

Permalink
Merge branch 'main' into feat/job-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikbossart authored Sep 15, 2023
2 parents 4d633c5 + 7e5d333 commit 3598c15
Show file tree
Hide file tree
Showing 18 changed files with 345 additions and 176 deletions.
29 changes: 29 additions & 0 deletions e2e/tests/plugin-form-ReadOnlyPrimitives.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test } from '@playwright/test'

test('Read only primitives', async ({ page }) => {
await page.goto('http://localhost:3000/')
await page.getByText('plugins', { exact: true }).click()
await page.getByText('form').click()
await page.getByText('read_only_primitives').click()
await page.getByText('ReadOnlyPrimitives').click()

await expect(page.getByLabel('A required string')).not.toBeEditable()

await expect(
page.getByLabel('An optional string (optional)')
).not.toBeEditable()

await expect(page.getByLabel('A required number')).not.toBeEditable()

await expect(page.getByLabel('Numbers only (optional)')).not.toBeEditable()

await expect(page.getByLabel('Integer only (optional)')).not.toBeEditable()

await expect(
page.getByLabel('An optional checkbox (optional)')
).not.toBeEditable()

await expect(
page.getByLabel('A required checbox (e.g. for confirmation purposes)')
).not.toBeEditable()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "ReadOnlyPrimitives",
"type": "CORE:Blueprint",
"attributes": [
{
"name": "type",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
},
{
"name": "name",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "string"
},
{
"name": "stringOptional",
"type": "CORE:BlueprintAttribute",
"attributeType": "string",
"label": "An optional string",
"optional": true
},
{
"name": "stringRequired",
"type": "CORE:BlueprintAttribute",
"attributeType": "string",
"label": "A required string",
"optional": false
},
{
"name": "numberRequired",
"type": "CORE:BlueprintAttribute",
"attributeType": "number",
"label": "A required number",
"optional": false
},
{
"name": "numberOptional",
"type": "CORE:BlueprintAttribute",
"attributeType": "number",
"label": "Numbers only",
"optional": true
},
{
"name": "integer",
"type": "CORE:BlueprintAttribute",
"attributeType": "integer",
"label": "Integer only",
"optional": true
},
{
"name": "checkboxOptional",
"type": "CORE:BlueprintAttribute",
"attributeType": "boolean",
"label": "An optional checkbox",
"optional": true
},
{
"name": "checkboxRequired",
"type": "CORE:BlueprintAttribute",
"attributeType": "boolean",
"label": "A required checbox (e.g. for confirmation purposes)",
"optional": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"_id": "readOnlyPrimitives",
"name": "ReadOnlyPrimitives",
"type": "./blueprints/ReadOnlyPrimitives",
"stringRequired": "A required string",
"stringOptional": "an optional string",
"numberRequired": 2.34,
"numberOptional": 3.14,
"integer": 30,
"checkboxOptional": false,
"checkboxRequired": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
"showInline": false,
"uiRecipe": "defaultForm"
},
{
"name": "ceo",
"type": "PLUGINS:dm-core-plugins/form/fields/ObjectField",
"showInline": false,
"uiRecipe": "defaultForm"
},
{
"name": "trainee",
"type": "PLUGINS:dm-core-plugins/form/fields/ObjectField",
Expand All @@ -56,6 +62,11 @@
"name": "locations",
"type": "PLUGINS:dm-core-plugins/form/fields/ArrayField",
"showInline": true
},
{
"name": "customers",
"type": "PLUGINS:dm-core-plugins/form/fields/ArrayField",
"showInline": false
}
],
"fields": [
Expand All @@ -68,8 +79,7 @@
"customers",
"isBankrupt"
],
"readOnly": true,
"editToggle": true
"readOnly": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"initialUiRecipe": {
"name": "form",
"type": "CORE:UiRecipe",
"plugin": "@development-framework/dm-core-plugins/form"
"plugin": "@development-framework/dm-core-plugins/form",
"config": {
"type": "PLUGINS:dm-core-plugins/form/FormInput",
"readOnly": true
}
},
"uiRecipes": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"type": "CORE:RecipeLink",
"_blueprintPath_": "/plugins/form/read_only_primitives/blueprints/ReadOnlyPrimitives",
"initialUiRecipe": {
"name": "ViewSelector",
"type": "CORE:UiRecipe",
"plugin": "@development-framework/dm-core-plugins/view_selector",
"config": {
"type": "PLUGINS:dm-core-plugins/view_selector/ViewSelectorConfig",
"childTabsOnRender": true,
"asSidebar": false,
"items": [
{
"type": "PLUGINS:dm-core-plugins/view_selector/ViewSelectorItem",
"view": {
"type": "CORE:ReferenceViewConfig",
"recipe": "ReadOnly"
}
}
]
}
},
"uiRecipes": [
{
"name": "ReadOnly",
"type": "CORE:UiRecipe",
"plugin": "@development-framework/dm-core-plugins/form",
"category": "edit",
"config": {
"type": "PLUGINS:dm-core-plugins/form/FormInput",
"fields": [
"stringRequired",
"stringOptional",
"numberRequired",
"numberOptional",
"integer",
"checkboxOptional",
"checkboxRequired"
],
"readOnly": true
}
}
]
}
2 changes: 1 addition & 1 deletion example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dm-cli==1.1.0
dm-cli==1.1.1
16 changes: 13 additions & 3 deletions example/src/plugins/job-ui-single/pages/JobForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
EBlueprint,
EntityPickerButton,
EntityPickerDialog,
JobStatus,
Loading,
Stack,
Expand Down Expand Up @@ -36,6 +36,8 @@ export const JobForm = (props: {
started: 'Not started',
}
const [formData, setFormData] = useState<TJob>(defaultJobValues)
const [showJobRunnerModal, setShowJobRunnerModal] = useState<boolean>(false)
const [showInputModal, setShowInputModal] = useState<boolean>(false)
const {
blueprint: jobBlueprint,
isLoading: isBlueprintLoading,
Expand Down Expand Up @@ -73,7 +75,12 @@ export const JobForm = (props: {
return (
<>
<p>Pick job runner entity:</p>
<EntityPickerButton
<Button onClick={() => setShowJobRunnerModal(true)}>
Select
</Button>
<EntityPickerDialog
showModal={showJobRunnerModal}
setShowModal={setShowJobRunnerModal}
onChange={(address: string, entity?: TValidEntity) => {
setFormData({ ...formData, runner: entity })
}}
Expand All @@ -96,7 +103,10 @@ export const JobForm = (props: {
JSON.stringify(formData.applicationInput.address)}
</p>
</div>
<EntityPickerButton
<Button onClick={() => setShowInputModal(true)}>Select</Button>
<EntityPickerDialog
showModal={showInputModal}
setShowModal={setShowInputModal}
onChange={(address: string) => {
const linkReference: TLinkReference = {
type: EBlueprint.REFERENCE,
Expand Down
8 changes: 0 additions & 8 deletions packages/dm-core-plugins/blueprints/form/FormInput.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@
"optional": true,
"contained": true,
"default": false
},
{
"name": "editToggle",
"type": "dmss://system/SIMOS/BlueprintAttribute",
"attributeType": "boolean",
"optional": true,
"contained": true,
"default": false
}
]
}
24 changes: 4 additions & 20 deletions packages/dm-core-plugins/src/form/components/AttributeList.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { Stack, TAttribute, TBlueprint } from '@development-framework/dm-core'
import React, { useState } from 'react'
import { TAttribute, TBlueprint } from '@development-framework/dm-core'
import React from 'react'
import { AttributeField } from '../fields/AttributeField'
import { TConfig } from '../types'
import { Button } from '@equinor/eds-core-react'

export const AttributeList = (props: {
namePath: string
config: TConfig | undefined
blueprint: TBlueprint | undefined
}) => {
const { namePath, config, blueprint } = props

const [readOnly, setReadOnly] = useState<boolean | undefined>(
config?.readOnly
)
const toggleHandler = () => {
setReadOnly(!readOnly)
}

const prefix = namePath === '' ? `` : `${namePath}.`

const attributes = blueprint?.attributes ?? []
Expand All @@ -43,18 +34,11 @@ export const AttributeList = (props: {
namePath={`${prefix}${attribute.name}`}
attribute={attribute}
uiAttribute={uiAttribute}
readOnly={readOnly}
readOnly={config?.readOnly}
/>
</div>
)
})

return (
<Stack spacing={1}>
{config?.editToggle && (
<Button onClick={toggleHandler}>{readOnly ? 'Edit' : 'View'}</Button>
)}
{attributeFields}
</Stack>
)
return <>{attributeFields}</>
}
16 changes: 9 additions & 7 deletions packages/dm-core-plugins/src/form/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ export const Form = (props: TFormProps) => {
config={config}
blueprint={blueprint}
/>
<Button
type="submit"
data-testid="form-submit"
style={{ alignSelf: 'flex-start' }}
>
Submit
</Button>
{!config?.readOnly && (
<Button
type="submit"
data-testid="form-submit"
style={{ alignSelf: 'flex-start' }}
>
Submit
</Button>
)}
</Stack>
</form>
</RegistryProvider>
Expand Down
48 changes: 25 additions & 23 deletions packages/dm-core-plugins/src/form/fields/ArrayField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,34 @@ export default function ArrayField(props: TArrayFieldProps) {
readOnly={readOnly}
/>
</Stack>
<Button
disabled={readOnly}
variant="outlined"
type="button"
onClick={() => remove(index)}
>
Remove
</Button>
{!readOnly && (
<Button
variant="outlined"
type="button"
onClick={() => remove(index)}
>
Remove
</Button>
)}
</Stack>
)
})}
<Button
disabled={readOnly}
variant="outlined"
data-testid={`add-${namePath}`}
onClick={() => {
if (isPrimitiveType(type)) {
const defaultValue = isPrimitive(type) ? ' ' : {}
append(defaultValue)
} else {
handleAddObject()
}
}}
>
Add
</Button>
{!readOnly && (
<Button
variant="outlined"
data-testid={`add-${namePath}`}
onClick={() => {
if (isPrimitiveType(type)) {
const defaultValue = isPrimitive(type) ? ' ' : {}
append(defaultValue)
} else {
handleAddObject()
}
}}
>
Add
</Button>
)}
</Stack>
)
}
Loading

0 comments on commit 3598c15

Please sign in to comment.