1- import PropTypes from 'prop-types' ;
21import React , { createElement , useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
3- import { Button , Grid , Select , MenuItem , Box , Typography } from '@mui/material' ;
2+ import { Button , Grid , Select , MenuItem , Box } from '@mui/material' ;
43
54import PConnectHOC from '../../../../bridge/react_pconnect' ;
65import TemplateContext from '../TemplateContext' ;
@@ -11,14 +10,9 @@ import { useCacheWhenListViewReady } from './hooks';
1110
1211const PComponent = PConnectHOC ( ) ;
1312
14- export const initializeSearchFields = (
15- searchFields ,
16- getPConnect ,
17- referenceListClassID ,
18- searchFieldRestoreValues = { }
19- ) => {
13+ export const initializeSearchFields = ( searchFields , getPConnect , referenceListClassID , searchFieldRestoreValues = { } ) => {
2014 const filtersProperties = { } ;
21- searchFields . forEach ( ( field ) => {
15+ searchFields . forEach ( field => {
2216 let val = '' ;
2317 const { value, defaultValue = '' } = field . config ;
2418 const propPath = PCore . getAnnotationUtils ( ) . getPropertyName ( value ) ;
@@ -41,7 +35,7 @@ export const initializeSearchFields = (
4135 if ( valueSplit . length ) {
4236 let path = '' ;
4337 let currentClassID = referenceListClassID ;
44- valueSplit . forEach ( ( item ) => {
38+ valueSplit . forEach ( item => {
4539 path = path . length ? `${ path } .${ item } ` : item ;
4640 currentClassID = ( PCore . getMetadataUtils ( ) . getPropertyMetadata ( item , currentClassID ) as any ) . pageClass ;
4741 if ( currentClassID ) {
@@ -53,13 +47,13 @@ export const initializeSearchFields = (
5347 return filtersProperties ;
5448} ;
5549
56- const flattenObj = ( obj ) => {
50+ const flattenObj = obj => {
5751 const result = { } ;
58- Object . keys ( obj ) . forEach ( ( key ) => {
52+ Object . keys ( obj ) . forEach ( key => {
5953 if ( ! [ 'context_data' , 'pageInstructions' ] . includes ( key ) ) {
6054 if ( typeof obj [ key ] === 'object' && ! Array . isArray ( obj [ key ] ) ) {
6155 const temp = flattenObj ( obj [ key ] ) ;
62- Object . keys ( temp ) . forEach ( ( nestedKey ) => {
56+ Object . keys ( temp ) . forEach ( nestedKey => {
6357 result [ `${ key } .${ nestedKey } ` ] = temp [ nestedKey ] ;
6458 } ) ;
6559 } else {
@@ -86,16 +80,16 @@ export default function SearchGroups(props) {
8680 const viewName = getPConnect ( ) . getCurrentView ( ) ;
8781
8882 const rawGroupsConfig = getPConnect ( ) . getRawConfigProps ( ) . searchGroups ;
89- const activeGroupIndex = groups . findIndex ( ( group ) => group . config . id === activeGroupId ) ;
83+ const activeGroupIndex = groups . findIndex ( group => group . config . id === activeGroupId ) ;
9084 const { children : searchFieldsChildren = [ ] } = activeGroupIndex !== - 1 ? rawGroupsConfig [ activeGroupIndex ] : { } ;
91- const searchFields = searchFieldsChildren . map ( ( field ) => ( {
85+ const searchFields = searchFieldsChildren . map ( field => ( {
9286 ...field ,
9387 config : { ...field . config , isSearchField : true }
9488 } ) ) ;
9589
9690 const searchByRef = useRef ( null ) ;
9791 const searchFieldsRef = useRef ( null ) ;
98- const isValidatorField = searchFields . some ( ( field ) => field . config . validator ) ;
92+ const isValidatorField = searchFields . some ( field => field . config . validator ) ;
9993 const { classID : referenceListClassID } = PCore . getMetadataUtils ( ) . getDataPageMetadata ( referenceList ) as any ;
10094
10195 const initialSearchFields = useMemo (
@@ -139,20 +133,13 @@ export default function SearchGroups(props) {
139133 includeDisabledFields : true
140134 } ) ;
141135
142- if (
143- Object . keys ( cache . searchFields ?? { } ) . length > 0 &&
144- Object . keys ( changes ) . length === 1
145- ) {
136+ if ( Object . keys ( cache . searchFields ?? { } ) . length > 0 && Object . keys ( changes ) . length === 1 ) {
146137 changes = cache . searchFields ;
147138 }
148139
149140 const formValues = flattenObj ( changes ) ;
150141
151- if (
152- ! PCore . isDeepEqual ( previousFormValues , formValues ) &&
153- PCore . getFormUtils ( ) . isFormValid ( transientItemID ) &&
154- isValidInput ( formValues )
155- ) {
142+ if ( ! PCore . isDeepEqual ( previousFormValues , formValues ) && PCore . getFormUtils ( ) . isFormValid ( transientItemID ) && isValidInput ( formValues ) ) {
156143 if ( isValidatorField ) {
157144 // @ts -ignore
158145 PCore . getMessageManager ( ) . clearContextMessages ( { context : transientItemID } ) ;
@@ -189,13 +176,8 @@ export default function SearchGroups(props) {
189176
190177 const searchDropdown = groups . length > 1 && (
191178 < Grid container spacing = { 2 } >
192- < Select
193- value = { activeGroupId }
194- onChange = { ( e ) => setActiveGroupId ( e . target . value ) }
195- ref = { searchByRef }
196- fullWidth
197- >
198- { groups . map ( ( group ) => (
179+ < Select value = { activeGroupId } onChange = { e => setActiveGroupId ( e . target . value ) } ref = { searchByRef } fullWidth >
180+ { groups . map ( group => (
199181 < MenuItem key = { group . config . id } value = { group . config . id } >
200182 { group . config . label }
201183 </ MenuItem >
@@ -205,11 +187,11 @@ export default function SearchGroups(props) {
205187 ) ;
206188
207189 const actionButtons = (
208- < Box display = " flex" gap = { 2 } >
209- < Button variant = " outlined" onClick = { resetFilterData } >
190+ < Box display = ' flex' gap = { 2 } >
191+ < Button variant = ' outlined' onClick = { resetFilterData } >
210192 { localizedVal ( 'Reset' , 'SimpleTable' ) }
211193 </ Button >
212- < Button variant = " contained" onClick = { getFilterData } >
194+ < Button variant = ' contained' onClick = { getFilterData } >
213195 { localizedVal ( 'Search' , 'SimpleTable' ) }
214196 </ Button >
215197 </ Box >
@@ -255,8 +237,9 @@ export default function SearchGroups(props) {
255237 const childrenToRender = [ searchDropdown , searchFieldsViewComp , actionButtons ] ;
256238
257239 return (
258- < Box display = " flex" flexDirection = " column" gap = { 2 } >
240+ < Box display = ' flex' flexDirection = ' column' gap = { 2 } >
259241 { childrenToRender . map ( ( child , index ) => (
242+ // eslint-disable-next-line react/no-array-index-key
260243 < React . Fragment key = { index } > { child } </ React . Fragment >
261244 ) ) }
262245 </ Box >
0 commit comments