Skip to content

Commit abd2acf

Browse files
author
manasa
committed
updated as per comments
1 parent 2ad7c74 commit abd2acf

File tree

5 files changed

+97
-101
lines changed

5 files changed

+97
-101
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { useContext, useState } from 'react';
2+
3+
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
4+
import DataReferenceAdvancedSearchContext from '../DataReference/DataReferenceAdvancedSearchContext';
5+
import { getFirstChildConfig } from '../DataReference/utils';
6+
7+
export default function AdvancedSearch(props) {
8+
const { getPConnect, targetObjectClass, localeReference } = props;
9+
const SearchGroups = getComponentFromMap('SearchGroups');
10+
const { dataReferenceConfigToChild, isCreateNewReferenceEnabled, disableStartingFieldsForReference, pyID, searchSelectCacheKey } = useContext(
11+
DataReferenceAdvancedSearchContext
12+
) as any;
13+
14+
const { selectionMode, value: singleSelectFieldValue, readonlyContextList: multiSelectField } = dataReferenceConfigToChild;
15+
16+
let isSelectionExist = false;
17+
const { MULTI } = PCore.getConstants().LIST_SELECTION_MODE;
18+
19+
if (selectionMode === MULTI) {
20+
isSelectionExist = getPConnect().getValue(multiSelectField)?.length || false;
21+
} else {
22+
isSelectionExist = getPConnect().getValue(singleSelectFieldValue) || false;
23+
}
24+
25+
const [showRecords, setShowRecords] = useState(isSelectionExist);
26+
27+
const pConn = getPConnect();
28+
const rawViewMetadata = pConn.getRawMetadata();
29+
30+
const searchFieldsSet = new Set();
31+
const searchFields: any = [];
32+
rawViewMetadata.config.searchGroups.forEach(group => {
33+
group.children.forEach(child => {
34+
if (!searchFieldsSet.has(child.config.value) && !child.config.validator) {
35+
searchFields.push(child);
36+
searchFieldsSet.add(child.config.value);
37+
}
38+
});
39+
});
40+
41+
const firstChildPConnect = getPConnect().getChildren()[0].getPConnect;
42+
const [firstChildMeta] = rawViewMetadata.children;
43+
44+
const localizedVal = PCore.getLocaleUtils().getLocaleValue;
45+
// @ts-ignore
46+
const cache = PCore.getNavigationUtils().getComponentCache(searchSelectCacheKey) ?? {};
47+
48+
const editableFieldComp = firstChildPConnect().createComponent({
49+
type: firstChildMeta.type,
50+
config: {
51+
...getFirstChildConfig({
52+
firstChildMeta,
53+
getPConnect,
54+
rawViewMetadata,
55+
contextClass: targetObjectClass,
56+
dataReferenceConfigToChild,
57+
isCreateNewReferenceEnabled,
58+
disableStartingFieldsForReference,
59+
pyID
60+
}),
61+
searchFields,
62+
showRecords,
63+
label: localizedVal('Search results', 'DataReference'),
64+
searchSelectCacheKey,
65+
cache
66+
}
67+
});
68+
69+
const { selectionList, dataRelationshipContext } = editableFieldComp.props.getPConnect().getConfigProps();
70+
const editableField = selectionMode === MULTI ? selectionList.substring(1) : dataRelationshipContext;
71+
72+
const searchGroupsProps = {
73+
getPConnect,
74+
editableField,
75+
localeReference,
76+
setShowRecords,
77+
searchSelectCacheKey,
78+
cache
79+
};
80+
81+
return (
82+
<>
83+
<SearchGroups {...searchGroupsProps} />
84+
{editableFieldComp}
85+
</>
86+
);
87+
}

packages/react-sdk-components/src/components/template/AdvancedSearch/SearchGroup/config.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

100644100755
File mode changed.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "AdvancedSearch",
3+
"label": "Advanced search",
4+
"type": "Template",
5+
"icon": "AdvancedSearch.svg",
6+
"subtype": "SEARCH",
7+
"hideTemplateEdit": true,
8+
"properties": []
9+
}
Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1 @@
1-
import { useContext, useState } from 'react';
2-
3-
import DataReferenceAdvancedSearchContext from '../DataReference/DataReferenceAdvancedSearchContext';
4-
import { getFirstChildConfig } from '../DataReference/utils';
5-
6-
import SearchGroups from './SearchGroups';
7-
8-
export default function AdvancedSearch(props) {
9-
const { getPConnect, targetObjectClass, localeReference } = props;
10-
11-
const { dataReferenceConfigToChild, isCreateNewReferenceEnabled, disableStartingFieldsForReference, pyID, searchSelectCacheKey } = useContext(
12-
DataReferenceAdvancedSearchContext
13-
) as any;
14-
15-
const { selectionMode, value: singleSelectFieldValue, readonlyContextList: multiSelectField } = dataReferenceConfigToChild;
16-
17-
let isSelectionExist = false;
18-
const { MULTI } = PCore.getConstants().LIST_SELECTION_MODE;
19-
20-
if (selectionMode === MULTI) {
21-
isSelectionExist = getPConnect().getValue(multiSelectField)?.length || false;
22-
} else {
23-
isSelectionExist = getPConnect().getValue(singleSelectFieldValue) || false;
24-
}
25-
26-
const [showRecords, setShowRecords] = useState(isSelectionExist);
27-
28-
const pConn = getPConnect();
29-
const rawViewMetadata = pConn.getRawMetadata();
30-
31-
const searchFieldsSet = new Set();
32-
const searchFields: any = [];
33-
rawViewMetadata.config.searchGroups.forEach(group => {
34-
group.children.forEach(child => {
35-
if (!searchFieldsSet.has(child.config.value) && !child.config.validator) {
36-
searchFields.push(child);
37-
searchFieldsSet.add(child.config.value);
38-
}
39-
});
40-
});
41-
42-
const firstChildPConnect = getPConnect().getChildren()[0].getPConnect;
43-
const [firstChildMeta] = rawViewMetadata.children;
44-
45-
const localizedVal = PCore.getLocaleUtils().getLocaleValue;
46-
// @ts-ignore
47-
const cache = PCore.getNavigationUtils().getComponentCache(searchSelectCacheKey) ?? {};
48-
49-
const editableFieldComp = firstChildPConnect().createComponent({
50-
type: firstChildMeta.type,
51-
config: {
52-
...getFirstChildConfig({
53-
firstChildMeta,
54-
getPConnect,
55-
rawViewMetadata,
56-
contextClass: targetObjectClass,
57-
dataReferenceConfigToChild,
58-
isCreateNewReferenceEnabled,
59-
disableStartingFieldsForReference,
60-
pyID
61-
}),
62-
searchFields,
63-
showRecords,
64-
label: localizedVal('Search results', 'DataReference'),
65-
searchSelectCacheKey,
66-
cache
67-
}
68-
});
69-
70-
const { selectionList, dataRelationshipContext } = editableFieldComp.props.getPConnect().getConfigProps();
71-
const editableField = selectionMode === MULTI ? selectionList.substring(1) : dataRelationshipContext;
72-
73-
const searchGroupsProps = {
74-
getPConnect,
75-
editableField,
76-
localeReference,
77-
setShowRecords,
78-
searchSelectCacheKey,
79-
cache
80-
};
81-
82-
return (
83-
<>
84-
<SearchGroups {...searchGroupsProps} />
85-
{editableFieldComp}
86-
</>
87-
);
88-
}
1+
export { default } from './AdvancedSearch';

0 commit comments

Comments
 (0)