Skip to content

Commit 996fa4a

Browse files
author
manasa
committed
Added playwrights to Advance search DataReference
1 parent 6322317 commit 996fa4a

File tree

16 files changed

+298
-264
lines changed

16 files changed

+298
-264
lines changed

packages/react-sdk-components/src/components/template/AdvancedSearch/SearchGroup/persistUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getComponentStateKey = (getPConnect, propertyName: string) => {
1414
return `Search-${resolvedCaseID}-${pConnect.getPageReference()}-${propertyName}-${pConnect.getCurrentView()}`;
1515
};
1616

17-
const getComponentStateOptions = (getPConnect) => {
17+
const getComponentStateOptions = getPConnect => {
1818
return { clearOnCancelForContext: getPConnect().getContextName() };
1919
};
2020

packages/react-sdk-components/src/components/template/AdvancedSearch/SearchGroups/hooks.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const listViewConstants = {
55
EVENTS: {
66
LIST_VIEW_READY: 'LIST_VIEW_READY'
77
}
8-
}
8+
};
99
/**
1010
* This hook registers a callback for the whenever list view component is ready
1111
* then makes a call to get the data using the search fields pre-filled with cache data.
@@ -32,10 +32,7 @@ export function useCacheWhenListViewReady(
3232
}
3333

3434
return () => {
35-
PCore.getPubSubUtils().unsubscribe(
36-
listViewConstants.EVENTS.LIST_VIEW_READY,
37-
`${searchSelectCacheKey}-listview-ready`
38-
);
35+
PCore.getPubSubUtils().unsubscribe(listViewConstants.EVENTS.LIST_VIEW_READY, `${searchSelectCacheKey}-listview-ready`);
3936
};
4037
}, []);
4138
}

packages/react-sdk-components/src/components/template/AdvancedSearch/SearchGroups/index.tsx

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import PropTypes from 'prop-types';
21
import 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

54
import PConnectHOC from '../../../../bridge/react_pconnect';
65
import TemplateContext from '../TemplateContext';
@@ -11,14 +10,9 @@ import { useCacheWhenListViewReady } from './hooks';
1110

1211
const 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>

packages/react-sdk-components/src/components/template/AdvancedSearch/SearchGroups/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function getCacheInfo(
1616
let initialActiveGroupId = groups.length ? groups[0].config.id : '';
1717

1818
let useCache = false;
19-
if (cache.activeGroupId && groups?.find((group) => group.config.id === cache.activeGroupId)) {
19+
if (cache.activeGroupId && groups?.find(group => group.config.id === cache.activeGroupId)) {
2020
initialActiveGroupId = cache.activeGroupId;
2121
useCache = true;
2222
}
@@ -25,5 +25,5 @@ export function getCacheInfo(
2525
}
2626

2727
export function isValidInput(input: { [s: string]: unknown }) {
28-
return Object.values(input).some((value) => !isEmpty(value));
28+
return Object.values(input).some(value => !isEmpty(value));
2929
}

packages/react-sdk-components/src/components/template/AdvancedSearch/index.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ import SearchGroups from './SearchGroups';
77

88
export default function AdvancedSearch(props) {
99
const { getPConnect, targetObjectClass, localeReference } = props;
10-
//@ts-ignore
11-
const { dataReferenceConfigToChild, isCreateNewReferenceEnabled, disableStartingFieldsForReference, pyID, searchSelectCacheKey
12-
} = useContext(DataReferenceAdvancedSearchContext);
1310

14-
const {
15-
selectionMode,
16-
value: singleSelectFieldValue,
17-
readonlyContextList: multiSelectField
18-
} = dataReferenceConfigToChild;
11+
const { dataReferenceConfigToChild, isCreateNewReferenceEnabled, disableStartingFieldsForReference, pyID, searchSelectCacheKey } = useContext(
12+
DataReferenceAdvancedSearchContext
13+
) as any;
14+
15+
const { selectionMode, value: singleSelectFieldValue, readonlyContextList: multiSelectField } = dataReferenceConfigToChild;
1916

2017
let isSelectionExist = false;
2118
const { MULTI } = PCore.getConstants().LIST_SELECTION_MODE;
@@ -33,8 +30,8 @@ export default function AdvancedSearch(props) {
3330

3431
const searchFieldsSet = new Set();
3532
const searchFields: any = [];
36-
rawViewMetadata.config.searchGroups.forEach((group) => {
37-
group.children.forEach((child) => {
33+
rawViewMetadata.config.searchGroups.forEach(group => {
34+
group.children.forEach(child => {
3835
if (!searchFieldsSet.has(child.config.value) && !child.config.validator) {
3936
searchFields.push(child);
4037
searchFieldsSet.add(child.config.value);

0 commit comments

Comments
 (0)