Skip to content

Commit e639b15

Browse files
fix(orchestrator): clarify ActiveText retrigger loading
1 parent 88ac11d commit e639b15

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator-form-widgets': patch
3+
---
4+
5+
Clarify ActiveText retrigger loading by showing a spinner with a wait message while dependencies resolve.

workspaces/orchestrator/plugins/orchestrator-form-widgets/src/utils/useFetchAndEvaluate.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,23 @@ export const useFetchAndEvaluate = (
3434
handleFetchEnded?: () => void,
3535
) => {
3636
const unitEvaluator = useTemplateUnitEvaluator();
37+
const hasFetchUrl = !!uiProps['fetch:url'];
38+
const hasRetrigger =
39+
Array.isArray(uiProps['fetch:retrigger']) &&
40+
uiProps['fetch:retrigger'].length > 0;
3741
const retrigger = useRetriggerEvaluate(
3842
unitEvaluator,
3943
formData,
4044
uiProps['fetch:retrigger'] as string[],
4145
);
46+
const retriggerSatisfied =
47+
!hasRetrigger ||
48+
(!!retrigger &&
49+
retrigger.every(
50+
value => value !== undefined && value !== null && value !== '',
51+
));
52+
const waitingForRetrigger =
53+
hasFetchUrl && hasRetrigger && !retriggerSatisfied;
4254
const {
4355
data,
4456
error: fetchError,
@@ -50,7 +62,7 @@ export const useFetchAndEvaluate = (
5062
useDebounce(
5163
() => {
5264
const evaluate = async () => {
53-
if (!retrigger || fetchLoading || fetchError) {
65+
if (!retrigger || fetchLoading || fetchError || waitingForRetrigger) {
5466
return;
5567
}
5668
try {
@@ -82,6 +94,7 @@ export const useFetchAndEvaluate = (
8294
retrigger,
8395
fetchError,
8496
fetchLoading,
97+
waitingForRetrigger,
8598
fieldId,
8699
data,
87100
formData,
@@ -108,6 +121,7 @@ export const useFetchAndEvaluate = (
108121
return {
109122
text: resultText,
110123
loading: completeLoading,
124+
waitingForRetrigger,
111125
error: error ?? fetchError,
112126
};
113127
};

workspaces/orchestrator/plugins/orchestrator-form-widgets/src/widgets/ActiveText.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { JSONSchema7 } from 'json-schema';
2121
import { UiProps } from '../uiPropTypes';
2222
import CircularProgress from '@mui/material/CircularProgress';
2323
import Box from '@mui/material/Box';
24+
import Typography from '@mui/material/Typography';
2425
import { ErrorText } from './ErrorText';
2526
import { OrchestratorFormContextProps } from '@red-hat-developer-hub/backstage-plugin-orchestrator-form-api';
2627
import { useFetchAndEvaluate } from '../utils';
@@ -37,7 +38,7 @@ export const ActiveText: Widget<
3738
const handleFetchStarted = formContext?.handleFetchStarted;
3839
const handleFetchEnded = formContext?.handleFetchEnded;
3940

40-
const { text, error, loading } = useFetchAndEvaluate(
41+
const { text, error, loading, waitingForRetrigger } = useFetchAndEvaluate(
4142
uiProps['ui:text'] ?? '',
4243
formData ?? {},
4344
uiProps,
@@ -59,13 +60,21 @@ export const ActiveText: Widget<
5960
return <ErrorText id={id} text={error} />;
6061
}
6162

62-
return (
63-
<Box data-testid={id}>
64-
{loading ? (
65-
<CircularProgress size={20} />
66-
) : (
67-
<MarkdownContent content={text || ''} />
68-
)}
69-
</Box>
70-
);
63+
let content: React.ReactNode;
64+
if (waitingForRetrigger) {
65+
content = (
66+
<Box display="flex" alignItems="center" gap={1}>
67+
<CircularProgress size={16} />
68+
<Typography variant="body2" color="textSecondary">
69+
Waiting for dependency values to resolve.
70+
</Typography>
71+
</Box>
72+
);
73+
} else if (loading) {
74+
content = <CircularProgress size={20} />;
75+
} else {
76+
content = <MarkdownContent content={text || ''} />;
77+
}
78+
79+
return <Box data-testid={id}>{content}</Box>;
7180
};

0 commit comments

Comments
 (0)