Skip to content

Commit 539077c

Browse files
committed
feat: add support for bitnami chart hidden field
1 parent cf30e8a commit 539077c

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/Common/RJSF/Form.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const RJSFForm = (props: FormProps) => (
3939
...templates,
4040
...props.templates,
4141
}}
42+
formContext={props.formData}
4243
widgets={{ ...widgets, ...props.widgets }}
4344
translateString={translateString}
4445
/>

src/Common/RJSF/templates/ObjectFieldTemplate.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { ObjectFieldTemplateProps, canExpand, titleId } from '@rjsf/utils'
1818
import { JSONPath } from 'jsonpath-plus'
19+
import { convertJSONPointerToJSONPath } from '@Common/Helper'
1920
import { FieldRowWithLabel } from '../common/FieldRow'
2021
import { TitleField } from './TitleField'
2122
import { AddButton } from './ButtonTemplates'
@@ -33,6 +34,7 @@ const Field = ({
3334
schema,
3435
title,
3536
uiSchema,
37+
formContext,
3638
}: ObjectFieldTemplateProps<any, RJSFFormSchema, any>) => {
3739
const hasAdditionalProperties = !!schema.additionalProperties
3840

@@ -54,8 +56,19 @@ const Field = ({
5456
return true
5557
}
5658
try {
57-
const value = JSONPath({ path: hiddenSchemaProp.match, json: formData })?.[0]
58-
const isHidden = value === undefined || hiddenSchemaProp.condition === value
59+
if (!hiddenSchemaProp.path) {
60+
throw new Error('Empty path element')
61+
}
62+
let path = ''
63+
if (hiddenSchemaProp.path.match(/^\w+(\/\w+)*$/g) && hiddenSchemaProp.path.charAt(0) !== '/') {
64+
path = convertJSONPointerToJSONPath(`/${hiddenSchemaProp.path}`)
65+
}
66+
// NOTE: formContext is the formData passed to RJSFForm
67+
const value = JSONPath({
68+
path,
69+
json: formContext,
70+
})?.[0]
71+
const isHidden = value === undefined || hiddenSchemaProp.value === value
5972
return !isHidden
6073
} catch {
6174
return true

src/Common/RJSF/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { StrictRJSFSchema } from '@rjsf/utils'
2121
export type FormProps = Omit<ComponentProps<typeof RJSFForm>, 'validator'>
2222

2323
interface Hidden {
24-
condition: boolean
25-
match: string
24+
value: boolean
25+
path: string
2626
}
2727

2828
export interface RJSFFormSchema extends StrictRJSFSchema {

0 commit comments

Comments
 (0)