Skip to content

Commit a678dba

Browse files
authored
Merge branch 'master' into refactor/package_json
2 parents 07c6012 + 471611a commit a678dba

File tree

21 files changed

+1570
-140
lines changed

21 files changed

+1570
-140
lines changed

assets/css/sdkStyles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ input[readonly]+svg {
5959
#flowContainerBanner {
6060
padding: 10px 0;
6161
}
62+
63+
.search-form > div {
64+
margin: 0 !important;
65+
padding: 0 !important;
66+
}
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+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const SKIP_CACHE_KEY = '';
2+
3+
export function getMappedKey(key) {
4+
const mappedKey = PCore.getEnvironmentInfo().getKeyMapping(key);
5+
if (!mappedKey) {
6+
return key;
7+
}
8+
return mappedKey;
9+
}
10+
11+
const getComponentStateKey = (getPConnect, propertyName: string) => {
12+
const pConnect = getPConnect();
13+
const caseID = `.${getMappedKey('pyID')}`; // Enhance this later when use-case arrives for data objects using S&S.
14+
const resolvedCaseID = pConnect.getValue(caseID);
15+
16+
if (!resolvedCaseID) {
17+
return SKIP_CACHE_KEY;
18+
}
19+
20+
return `Search-${resolvedCaseID}-${pConnect.getPageReference()}-${propertyName}-${pConnect.getCurrentView()}`;
21+
};
22+
23+
const getComponentStateOptions = getPConnect => {
24+
return { clearOnCancelForContext: getPConnect().getContextName() };
25+
};
26+
27+
interface SearchCategory {
28+
// tabId of search category selected
29+
selectedCategory: string;
30+
}
31+
32+
interface SearchGroup {
33+
// searchFields can be any object based on what fields are authored.
34+
searchFields: unknown;
35+
activeGroupId: string;
36+
}
37+
38+
const setComponentCache = ({
39+
cacheKey,
40+
state,
41+
options
42+
}: {
43+
cacheKey: string;
44+
state: SearchCategory | SearchGroup;
45+
options: ReturnType<typeof getComponentStateOptions>;
46+
}) => {
47+
if (cacheKey !== SKIP_CACHE_KEY) {
48+
(PCore.getNavigationUtils() as any).setComponentCache(cacheKey, state, options);
49+
}
50+
};
51+
52+
const componentCachePersistUtils = {
53+
getComponentStateKey,
54+
getComponentStateOptions,
55+
setComponentCache
56+
};
57+
58+
export default componentCachePersistUtils;

0 commit comments

Comments
 (0)