Skip to content

Commit a55161d

Browse files
committed
fix: use deepEquals from rjsf utils
1 parent 47de87e commit a55161d

File tree

4 files changed

+15
-30
lines changed

4 files changed

+15
-30
lines changed

src/Common/Helper.tsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import moment from 'moment'
2323
import { useLocation } from 'react-router-dom'
2424
import { toast } from 'react-toastify'
2525
import YAML from 'yaml'
26+
import { deepEquals } from '@rjsf/utils'
2627
import { ERROR_EMPTY_SCREEN, SortingOrder, EXCLUDED_FALSY_VALUES, DISCORD_LINK, ZERO_TIME_STRING } from './Constants'
2728
import { ServerErrors } from './ServerError'
2829
import { toastAccessDenied } from './ToastBody'
@@ -816,28 +817,7 @@ export const compareObjectLength = (objA: any, objB: any): boolean => {
816817
* Return deep copy of the object
817818
*/
818819
export function deepEqual(configA: any, configB: any): boolean {
819-
try {
820-
if (configA === configB) {
821-
return true
822-
}
823-
if ((configA && !configB) || (!configA && configB) || !compareObjectLength(configA, configB)) {
824-
return false
825-
}
826-
let isEqual = true
827-
for (const idx in configA) {
828-
if (!isEqual) {
829-
break
830-
} else if (typeof configA[idx] === 'object' && typeof configB[idx] === 'object') {
831-
isEqual = deepEqual(configA[idx], configB[idx])
832-
} else if (configA[idx] !== configB[idx]) {
833-
isEqual = false
834-
}
835-
}
836-
return isEqual
837-
} catch (err) {
838-
showError(err)
839-
return true
840-
}
820+
return deepEquals(configA, configB)
841821
}
842822

843823
export function shallowEqual(objA, objB) {

src/Common/RJSF/templates/ObjectFieldTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ObjectFieldTemplateProps, canExpand, titleId } from '@rjsf/utils'
17+
import { ObjectFieldTemplateProps, canExpand, titleId, deepEquals } from '@rjsf/utils'
1818
import { JSONPath } from 'jsonpath-plus'
1919
import { convertJSONPointerToJSONPath } from '@Common/Helper'
2020
import { FieldRowWithLabel } from '../common/FieldRow'
@@ -69,7 +69,7 @@ const Field = ({
6969
path: convertJSONPointerToJSONPath(hiddenSchema.path),
7070
json: formContext,
7171
})?.[0]
72-
const isHidden = value === undefined || hiddenSchema.value === value
72+
const isHidden = value === undefined || deepEquals(hiddenSchema.value, value)
7373
return !isHidden
7474
} catch {
7575
return true

src/Common/RJSF/types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import { StrictRJSFSchema } from '@rjsf/utils'
2020

2121
export type FormProps = Omit<ComponentProps<typeof RJSFForm>, 'validator'>
2222

23+
export interface MetaHiddenType {
24+
value: any
25+
path: string
26+
}
27+
2328
export type HiddenType =
24-
| {
25-
value: any
26-
path: string
27-
}
29+
| MetaHiddenType
2830
| {
2931
condition: any
3032
value: string

src/Common/RJSF/utils.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { TranslatableString, englishStringTranslator } from '@rjsf/utils'
18-
import { HiddenType } from './types'
18+
import { HiddenType, MetaHiddenType } from './types'
1919

2020
/**
2121
* Override for the TranslatableString from RJSF
@@ -151,7 +151,10 @@ const conformPathToPointers = (path: string) => {
151151
return trimmedPath
152152
}
153153

154-
export const parseSchemaHiddenType = (hiddenSchema: HiddenType) => {
154+
export const parseSchemaHiddenType = (hiddenSchema: HiddenType): MetaHiddenType => {
155+
if (!hiddenSchema) {
156+
return null
157+
}
155158
if (typeof hiddenSchema === 'string') {
156159
return {
157160
value: false,

0 commit comments

Comments
 (0)