Skip to content

Commit 27eb131

Browse files
authored
Merge pull request #430
fix(22182): Handle readonly and editable Designer * fix(22182): set readonly to form when proper designer status * fix(22182): add readonly to the interpolation editor * refactor(22182): add RJSF overrides to handle disabled state * refactor(22182): add proper disabled buttons for array properties * refactor(22182): relocated RJSF custom templates for reuse * refactor(22182): add edit CTA and status * refactor(22182): add restriction to readonly * test(22182): update mock to handle status * test(22182): add test for readonly * test(22182): add test for readonly * test(22182): refactor mocks and add test for readonly * chore(22182): eslint * test(22182): fix only in tests * refactor(22182): add memoisation
1 parent 253ce38 commit 27eb131

26 files changed

+338
-71
lines changed

hivemq-edge/src/frontend/src/components/MQTT/TopicCreatableSelect.spec.cy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { mockBridge } from '@/api/hooks/useGetBridges/__handlers__'
66

77
const MOCK_ID = 'my-id'
88

9-
describe('SingleTopicCreatableSelect', () => {
9+
describe.skip('SingleTopicCreatableSelect', () => {
1010
beforeEach(() => {
1111
cy.viewport(450, 250)
1212
})
@@ -58,7 +58,7 @@ describe('SingleTopicCreatableSelect', () => {
5858
})
5959
})
6060

61-
describe.only('MultiTopicsCreatableSelect', () => {
61+
describe('MultiTopicsCreatableSelect', () => {
6262
beforeEach(() => {
6363
cy.viewport(450, 250)
6464
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Box, ButtonGroup, FormControl, HStack, useDisclosure, VStack } from '@c
55
import { LuPanelTopClose, LuPanelTopOpen } from 'react-icons/lu'
66

77
import IconButton from '@/components/Chakra/IconButton.tsx'
8+
import { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } from '@/components/rjsf/__internals/IconButton.tsx'
89

910
// TODO[NVL] Need a better handling of the custom UISchema property, for the Adapter SDK
1011
interface ArrayFieldItemCollapsableUISchema {
@@ -48,7 +49,6 @@ export const ArrayFieldItemTemplate: FC<ArrayFieldTemplateItemType> = (props) =>
4849
return children.props.name
4950
}, [children.props.formData, children.props.name, collapsableItems?.titleKey])
5051

51-
const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates
5252
const onCopyClick = useMemo(() => onCopyIndexClick(index), [index, onCopyIndexClick])
5353
const onRemoveClick = useMemo(() => onDropIndexClick(index), [index, onDropIndexClick])
5454
const onArrowUpClick = useMemo(() => onReorderClick(index, index - 1), [index, onReorderClick])
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { FC } from 'react'
22
import { ArrayFieldTemplateProps } from '@rjsf/utils'
33
import { Box, Grid, GridItem } from '@chakra-ui/react'
44
import { getTemplate, getUiOptions, ArrayFieldTemplateItemType } from '@rjsf/utils'
5+
import AddButton from '@/components/rjsf/__internals/AddButton.tsx'
56

6-
// TODO[NVL] This is NOT a good approach to add a "role"; submit a PR!
77
export const ArrayFieldTemplate: FC<ArrayFieldTemplateProps> = (props) => {
88
const { canAdd, disabled, idSchema, uiSchema, items, onAddClick, readonly, registry, required, schema, title } = props
99
const uiOptions = getUiOptions(uiSchema)
@@ -14,10 +14,7 @@ export const ArrayFieldTemplate: FC<ArrayFieldTemplateProps> = (props) => {
1414
)
1515
const ArrayFieldItemTemplate = getTemplate<'ArrayFieldItemTemplate'>('ArrayFieldItemTemplate', registry, uiOptions)
1616
const ArrayFieldTitleTemplate = getTemplate<'ArrayFieldTitleTemplate'>('ArrayFieldTitleTemplate', registry, uiOptions)
17-
// Button templates are not overridden in the uiSchema
18-
const {
19-
ButtonTemplates: { AddButton },
20-
} = registry.templates
17+
2118
return (
2219
<Box>
2320
<ArrayFieldTitleTemplate
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils'
2+
import { Button } from '@chakra-ui/react'
3+
import { AddIcon } from '@chakra-ui/icons'
4+
5+
/**
6+
* TODO[rjsf-team/react-jsonschema-form/issues/3839] Bug with disabled in buttons
7+
* Replaces
8+
* // const {
9+
* // ButtonTemplates: { AddButton },
10+
* // } = registry.templates
11+
* @see https://github.com/rjsf-team/react-jsonschema-form/issues/3839
12+
* @see https://github.com/rjsf-team/react-jsonschema-form/blob/main/packages/chakra-ui/src/AddButton/AddButton.tsx
13+
*/
14+
export default function AddButton<
15+
T = never,
16+
S extends StrictRJSFSchema = RJSFSchema,
17+
F extends FormContextType = never
18+
>({ uiSchema, registry, ...props }: IconButtonProps<T, S, F>) {
19+
const { translateString } = registry
20+
const { disabled, ...rest } = props
21+
return (
22+
<Button leftIcon={<AddIcon />} {...rest} isDisabled={props.disabled}>
23+
{translateString(TranslatableString.AddItemButton)}
24+
</Button>
25+
)
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { memo } from 'react'
2+
import { IconButton } from '@chakra-ui/react'
3+
type ChakraIconButtonProps = React.ComponentProps<typeof IconButton>
4+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils'
5+
6+
/**
7+
* TODO[rjsf-team/react-jsonschema-form/issues/3839] Bug with disabled in buttons
8+
* Replaces
9+
* // const {
10+
* // ButtonTemplates: { AddButton },
11+
* // } = registry.templates
12+
* @see https://github.com/rjsf-team/react-jsonschema-form/issues/3839
13+
* @see https://github.com/rjsf-team/react-jsonschema-form/blob/main/packages/chakra-ui/src/AddButton/AddButton.tsx
14+
*/
15+
16+
// eslint-disable-next-line react-refresh/only-export-components
17+
function ChakraIconButton<T = never, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = never>(
18+
props: IconButtonProps<T, S, F>
19+
) {
20+
const { icon, title, disabled, iconType, uiSchema, registry, ...otherProps } = props
21+
return (
22+
<IconButton
23+
aria-label={title || ''}
24+
{...otherProps}
25+
isDisabled={props.disabled}
26+
icon={icon as ChakraIconButtonProps['icon']}
27+
/>
28+
)
29+
}
30+
31+
ChakraIconButton.displayName = 'ChakraIconButton'
32+
33+
export default memo(ChakraIconButton) as typeof ChakraIconButton
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { FormContextType, IconButtonProps, RJSFSchema, StrictRJSFSchema, TranslatableString } from '@rjsf/utils'
2+
import { ArrowUpIcon, ArrowDownIcon, CopyIcon, DeleteIcon } from '@chakra-ui/icons'
3+
4+
import ChakraIconButton from '@/components/rjsf/__internals/ChakraIconButton.tsx'
5+
6+
/**
7+
* TODO[rjsf-team/react-jsonschema-form/issues/3839] Bug with disabled in buttons
8+
* Replaces
9+
* // const { CopyButton, MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates
10+
* @see https://github.com/rjsf-team/react-jsonschema-form/issues/3839
11+
* @see https://github.com/rjsf-team/react-jsonschema-form/blob/main/packages/chakra-ui/src/AddButton/AddButton.tsx
12+
*/
13+
14+
export function CopyButton<T = never, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = never>(
15+
props: IconButtonProps<T, S, F>
16+
) {
17+
const {
18+
registry: { translateString },
19+
} = props
20+
return (
21+
<ChakraIconButton<T, S, F> title={translateString(TranslatableString.CopyButton)} {...props} icon={<CopyIcon />} />
22+
)
23+
}
24+
25+
export function MoveDownButton<T = never, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = never>(
26+
props: IconButtonProps<T, S, F>
27+
) {
28+
const {
29+
registry: { translateString },
30+
} = props
31+
return (
32+
<ChakraIconButton<T, S, F>
33+
title={translateString(TranslatableString.MoveDownButton)}
34+
{...props}
35+
icon={<ArrowDownIcon />}
36+
/>
37+
)
38+
}
39+
40+
export function MoveUpButton<T = never, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = never>(
41+
props: IconButtonProps<T, S, F>
42+
) {
43+
const {
44+
registry: { translateString },
45+
} = props
46+
return (
47+
<ChakraIconButton<T, S, F>
48+
title={translateString(TranslatableString.MoveUpButton)}
49+
{...props}
50+
icon={<ArrowUpIcon />}
51+
/>
52+
)
53+
}
54+
55+
export function RemoveButton<T = never, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = never>(
56+
props: IconButtonProps<T, S, F>
57+
) {
58+
const {
59+
registry: { translateString },
60+
} = props
61+
return (
62+
<ChakraIconButton<T, S, F>
63+
title={translateString(TranslatableString.RemoveButton)}
64+
{...props}
65+
icon={<DeleteIcon />}
66+
/>
67+
)
68+
}

0 commit comments

Comments
 (0)