Skip to content

Commit

Permalink
fix(28713): fix default name when no ui:name given
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Dec 16, 2024
1 parent 0900452 commit 8716bf0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const ArrayFieldItemTemplate: FC<ArrayFieldTemplateItemType> = (props) =>
? children.props.formData[collapsableItems?.titleKey]
: undefined

return formatItemName(collapsableItems?.name as string, children.props.index, childrenFormData)
return formatItemName(collapsableItems?.name, children.props.index, childrenFormData)
}, [children.props.formData, children.props.index, collapsableItems?.name, collapsableItems?.titleKey])

useEffect(() => {
Expand Down Expand Up @@ -87,7 +87,7 @@ export const ArrayFieldItemTemplate: FC<ArrayFieldTemplateItemType> = (props) =>
// This is to override the hardcoded rendering of the item's indexed names
const childrenWithCustomTitle = {
...children,
props: { ...children.props, title: formatItemName(collapsableItems?.name as string, children.props.index) },
props: { ...children.props, title: formatItemName(collapsableItems?.name, children.props.index) },
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { formatItemName } from '@/components/rjsf/utils/array-items.utils.ts'

describe('formatItemName', () => {
it.each([
{
stub: undefined,
index: 1,
content: undefined,
result: 'item #1',
},
{
stub: 'item',
index: 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const FORMAT_INDEX_MARKER = '#'
const FORMAT_SEPARATOR = '-'

export const formatItemName = (stub: string, index: number, description?: string) => {
if (!description) return `${stub} ${FORMAT_INDEX_MARKER}${index}`
return `${stub} ${FORMAT_INDEX_MARKER}${index} ${FORMAT_SEPARATOR} ${description}`
import i18n from '@/config/i18n.config.ts'

export const formatItemName = (stub: string | undefined, index: number, description?: string) => {
const token = stub || i18n.t('rjsf.ArrayFieldItem.item', { ns: 'components' })
if (!description) return `${token} ${FORMAT_INDEX_MARKER}${index}`
return `${token} ${FORMAT_INDEX_MARKER}${index} ${FORMAT_SEPARATOR} ${description}`
}
1 change: 1 addition & 0 deletions hivemq-edge/src/frontend/src/locales/en/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
}
},
"ArrayFieldItem": {
"item": "item",
"Buttons": {
"expanded_true": "Collapse Item",
"expanded_false": "Expand Item"
Expand Down

0 comments on commit 8716bf0

Please sign in to comment.