Skip to content

Commit 9e840df

Browse files
authoredMar 20, 2025
Merge pull request #870 from silk-framework/fix/uriPatternEditor-CMEM-6461
Fix: URI pattern input issues
2 parents 5fa70ef + db0bfcc commit 9e840df

File tree

2 files changed

+49
-40
lines changed

2 files changed

+49
-40
lines changed
 

‎workspace/src/app/views/pages/MappingEditor/HierarchicalMapping/containers/MappingRule/ObjectRule/ObjectRuleForm.tsx

+48-39
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export const ObjectRuleForm = (props: IProps) => {
9999
uriPatternSuggestions.filter((p) => p.value !== (modifiedValues() as any).pattern).map((p) => [p.value, p])
100100
).values()
101101
);
102+
const currentUriPatterns = React.useRef<IUriPattern[]>([])
103+
currentUriPatterns.current = distinctUriPatterns
102104

103105
useEffect(() => {
104106
const { id, scrollIntoView } = props;
@@ -272,6 +274,46 @@ export const ObjectRuleForm = (props: IProps) => {
272274
return validationResult;
273275
};
274276

277+
const uriPatternSelector = React.useMemo(() => {
278+
return currentUriPatterns.current.length > 0 ? (
279+
<>
280+
<Spacing vertical={true} size={"tiny"}/>
281+
<Button
282+
data-test-id="object-rule-form-uri-pattern-selection-btn"
283+
elevated={true}
284+
tooltip={`Choose URI pattern from ${currentUriPatterns.current.length} existing URI pattern/s.`}
285+
onClick={() => setShowUriPatternModal(true)}
286+
>
287+
Choose
288+
</Button>
289+
</>
290+
) : undefined
291+
}, [uriPatternSuggestions.length > 0]);
292+
293+
const uriPatternComponent = React.useMemo(() =>
294+
<CodeAutocompleteField
295+
id={"uri-pattern-auto-suggestion"}
296+
label="URI pattern"
297+
initialValue={initialUriPattern}
298+
clearIconText={"Clear URI pattern"}
299+
validationErrorText={"The entered URI pattern is invalid."}
300+
onChange={(value) => {
301+
handleChangeValue("pattern", value);
302+
}}
303+
fetchSuggestions={(input, cursorPosition) =>
304+
fetchUriPatternAutoCompletions(
305+
parentId ? parentId : "root",
306+
input,
307+
cursorPosition,
308+
modifiedValues().sourceProperty
309+
)
310+
}
311+
onFocusChange={setUriPatternInputHasFocus}
312+
checkInput={checkUriPattern}
313+
rightElement={uriPatternSelector}
314+
reInitOnInitialValueChange={true}
315+
/>, [initialUriPattern, uriPatternSelector])
316+
275317
if (loading) {
276318
return <Spinner />;
277319
}
@@ -378,44 +420,7 @@ export const ObjectRuleForm = (props: IProps) => {
378420
</FieldItem>
379421
);
380422
} else {
381-
patternInput = (
382-
<CodeAutocompleteField
383-
id={"uri-pattern-auto-suggestion"}
384-
label="URI pattern"
385-
initialValue={initialUriPattern}
386-
clearIconText={"Clear URI pattern"}
387-
validationErrorText={"The entered URI pattern is invalid."}
388-
onChange={(value) => {
389-
handleChangeValue("pattern", value);
390-
}}
391-
fetchSuggestions={(input, cursorPosition) =>
392-
fetchUriPatternAutoCompletions(
393-
parentId ? parentId : "root",
394-
input,
395-
cursorPosition,
396-
modifiedValues().sourceProperty
397-
)
398-
}
399-
onFocusChange={setUriPatternInputHasFocus}
400-
checkInput={checkUriPattern}
401-
rightElement={
402-
distinctUriPatterns.length > 0 ? (
403-
<>
404-
<Spacing vertical={true} size={"tiny"} />
405-
<Button
406-
data-test-id="object-rule-form-uri-pattern-selection-btn"
407-
elevated={true}
408-
tooltip={`Choose URI pattern from ${distinctUriPatterns.length} existing URI pattern/s.`}
409-
onClick={() => setShowUriPatternModal(true)}
410-
>
411-
Choose
412-
</Button>
413-
</>
414-
) : undefined
415-
}
416-
reInitOnInitialValueChange={true}
417-
/>
418-
);
423+
patternInput = uriPatternComponent
419424
}
420425
} else {
421426
patternInput = (
@@ -501,7 +506,11 @@ export const ObjectRuleForm = (props: IProps) => {
501506
onClose={() => setShowUriPatternModal(false)}
502507
uriPatterns={distinctUriPatterns}
503508
onSelect={(uriPattern) => {
504-
setInitialUriPattern(uriPattern.value);
509+
// Necessary if the URI pattern has been changed and the selected URI pattern is the initial pattern
510+
if(initialUriPattern === uriPattern.value) {
511+
setInitialUriPattern("");
512+
}
513+
setTimeout(() => setInitialUriPattern(uriPattern.value), 0);
505514
handleChangeValue("pattern", uriPattern.value);
506515
}}
507516
/>

0 commit comments

Comments
 (0)
Please sign in to comment.