Skip to content

Commit e0f2998

Browse files
committed
added
Signed-off-by: saimedhi <saimedhi@amazon.com>
1 parent dfefa8d commit e0f2998

File tree

3 files changed

+104
-40
lines changed

3 files changed

+104
-40
lines changed

public/pages/workflow_detail/tools/resources/resource_list_with_flyout.tsx

+22-15
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ import {
1616
EuiTitle,
1717
EuiIcon,
1818
EuiText,
19+
EuiEmptyPrompt,
20+
EuiLoadingSpinner,
1921
} from '@elastic/eui';
2022
import {
2123
Workflow,
2224
WorkflowResource,
2325
customStringify,
2426
} from '../../../../../common';
2527
import { fetchResourceData } from '../../../../utils';
26-
import { useAppDispatch } from '../../../../store';
28+
import { AppState, useAppDispatch } from '../../../../store';
2729
import { getDataSourceId } from '../../../../utils';
2830
import { columns } from './columns';
31+
import { useSelector } from 'react-redux';
2932

3033
interface ResourceListFlyoutProps {
3134
workflow?: Workflow;
@@ -39,6 +42,7 @@ export function ResourceListWithFlyout(props: ResourceListFlyoutProps) {
3942
const dispatch = useAppDispatch();
4043
const dataSourceId = getDataSourceId();
4144
const [resourceDetails, setResourceDetails] = useState<string | null>(null);
45+
const { loading } = useSelector((state: AppState) => state.opensearch);
4246

4347
// Hook to initialize all resources. Reduce to unique IDs, since
4448
// the backend resources may include the same resource multiple times
@@ -72,10 +76,7 @@ export function ResourceListWithFlyout(props: ResourceListFlyoutProps) {
7276
try {
7377
const result = await fetchResourceData(row, dataSourceId!, dispatch);
7478
setResourceDetails(customStringify(result));
75-
} catch (error) {
76-
console.error('Failed to fetch resource data:', error);
77-
setResourceDetails('Error fetching resource data.');
78-
}
79+
} catch (error) {}
7980
};
8081

8182
// Closes the flyout and resets the selected resource data.
@@ -123,21 +124,27 @@ export function ResourceListWithFlyout(props: ResourceListFlyoutProps) {
123124
</EuiFlyoutHeader>
124125
<EuiFlyoutBody>
125126
<EuiFlexGroup direction="column" gutterSize="xs">
126-
<EuiFlexItem grow={true} style={{ paddingLeft: '20px' }}>
127+
<EuiFlexItem grow={true}>
127128
<EuiText size="m">
128129
<h4>Resource details</h4>
129130
</EuiText>
130131
</EuiFlexItem>
131-
132132
<EuiFlexItem grow={true}>
133-
<EuiCodeBlock
134-
language="json"
135-
fontSize="m"
136-
isCopyable={true}
137-
overflowHeight={650}
138-
>
139-
{resourceDetails || 'Loading...'}
140-
</EuiCodeBlock>
133+
{resourceDetails && !loading ? (
134+
<EuiCodeBlock
135+
language="json"
136+
fontSize="m"
137+
isCopyable={true}
138+
overflowHeight={650}
139+
>
140+
{resourceDetails}
141+
</EuiCodeBlock>
142+
) : (
143+
<EuiEmptyPrompt
144+
icon={<EuiLoadingSpinner size="xl" />}
145+
title={<h2>Loading</h2>}
146+
/>
147+
)}
141148
</EuiFlexItem>
142149
</EuiFlexGroup>
143150
</EuiFlyoutBody>

public/pages/workflows/workflow_list/resource_list.tsx

+43-24
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ import {
1414
RIGHT_ALIGNMENT,
1515
EuiText,
1616
Direction,
17+
EuiEmptyPrompt,
18+
EuiLoadingSpinner,
1719
} from '@elastic/eui';
1820
import {
1921
Workflow,
2022
WorkflowResource,
2123
customStringify,
2224
} from '../../../../common';
23-
import { useAppDispatch } from '../../../store';
25+
import { AppState, useAppDispatch } from '../../../store';
2426
import { fetchResourceData, getDataSourceId } from '../../../utils';
27+
import { useSelector } from 'react-redux';
28+
import { isEmpty } from 'lodash';
2529

2630
interface ResourceListProps {
2731
workflow?: Workflow;
@@ -35,9 +39,9 @@ export function ResourceList(props: ResourceListProps) {
3539
const dispatch = useAppDispatch();
3640
const dataSourceId = getDataSourceId();
3741
const [itemIdToExpandedRowMap, setItemIdToExpandedRowMap] = useState<{
38-
[key: string]: React.ReactNode;
42+
[key: string]: any;
3943
}>({});
40-
const [codeBlockData, setCodeBlockData] = useState<any>(null);
44+
const { loading } = useSelector((state: AppState) => state.opensearch);
4145
const [pageIndex, setPageIndex] = useState(0);
4246
const [pageSize, setPageSize] = useState(10);
4347
const [sortField, setSortField] = useState<keyof WorkflowResource>('id');
@@ -56,16 +60,6 @@ export function ResourceList(props: ResourceListProps) {
5660
}
5761
}, [props.workflow?.resourcesCreated]);
5862

59-
useEffect(() => {
60-
if (codeBlockData) {
61-
const { item, data } = codeBlockData;
62-
setItemIdToExpandedRowMap((prevMap) => ({
63-
...prevMap,
64-
[item.id]: renderExpandedRow(data),
65-
}));
66-
}
67-
}, [codeBlockData]);
68-
6963
// Renders the expanded row to show resource details in a code block.
7064
const renderExpandedRow = useCallback(
7165
(data: any) => (
@@ -76,18 +70,37 @@ export function ResourceList(props: ResourceListProps) {
7670
</EuiText>
7771
</EuiFlexItem>
7872
<EuiFlexItem grow={true} style={{ paddingLeft: '20px' }}>
79-
<EuiCodeBlock
80-
language="json"
81-
fontSize="m"
82-
isCopyable={true}
83-
overflowHeight={150}
84-
>
85-
{customStringify(data)}
86-
</EuiCodeBlock>
73+
{!isEmpty(data) && !loading ? (
74+
<EuiCodeBlock
75+
language="json"
76+
fontSize="m"
77+
isCopyable={true}
78+
overflowHeight={150}
79+
>
80+
{customStringify(data)}
81+
</EuiCodeBlock>
82+
) : loading ? (
83+
<EuiEmptyPrompt
84+
icon={<EuiLoadingSpinner size="xl" />}
85+
title={<h2>Loading</h2>}
86+
/>
87+
) : (
88+
<EuiEmptyPrompt
89+
iconType="alert"
90+
iconColor="danger"
91+
title={<h2>Error loading resource details</h2>}
92+
body={
93+
<p>
94+
You do not have permissions to access details of this
95+
resource.
96+
</p>
97+
}
98+
/>
99+
)}
87100
</EuiFlexItem>
88101
</EuiFlexGroup>
89102
),
90-
[codeBlockData]
103+
[loading]
91104
);
92105

93106
// Expands or collapses the details for a resource item.
@@ -101,10 +114,16 @@ export function ResourceList(props: ResourceListProps) {
101114
try {
102115
const result = await fetchResourceData(item, dataSourceId!, dispatch);
103116
if (result) {
104-
setCodeBlockData({ item, data: result });
117+
setItemIdToExpandedRowMap((prevMap) => ({
118+
...prevMap,
119+
[item.id]: renderExpandedRow(result),
120+
}));
105121
}
106122
} catch (error) {
107-
console.error('Failed to fetch resource data:', error);
123+
setItemIdToExpandedRowMap((prevMap) => ({
124+
...prevMap,
125+
[item.id]: renderExpandedRow(''),
126+
}));
108127
}
109128
}
110129
};

public/store/reducers/opensearch_reducer.ts

+39-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ export const getIndex = createAsyncThunk(
8383
dataSourceId
8484
);
8585
if (response instanceof HttpFetchError) {
86-
return rejectWithValue('Error getting index settings and mappings: ' + response.body.message);
86+
return rejectWithValue(
87+
'Error getting index settings and mappings: ' + response.body.message
88+
);
8789
} else {
8890
return response;
8991
}
@@ -272,6 +274,18 @@ const opensearchSlice = createSlice({
272274
state.loading = true;
273275
state.errorMessage = '';
274276
})
277+
.addCase(getIndex.pending, (state, action) => {
278+
state.loading = true;
279+
state.errorMessage = '';
280+
})
281+
.addCase(getIngestPipeline.pending, (state, action) => {
282+
state.loading = true;
283+
state.errorMessage = '';
284+
})
285+
.addCase(getSearchPipeline.pending, (state, action) => {
286+
state.loading = true;
287+
state.errorMessage = '';
288+
})
275289
.addCase(searchIndex.pending, (state, action) => {
276290
state.loading = true;
277291
state.errorMessage = '';
@@ -293,6 +307,18 @@ const opensearchSlice = createSlice({
293307
state.loading = false;
294308
state.errorMessage = '';
295309
})
310+
.addCase(getIndex.fulfilled, (state, action) => {
311+
state.loading = false;
312+
state.errorMessage = '';
313+
})
314+
.addCase(getSearchPipeline.fulfilled, (state, action) => {
315+
state.loading = false;
316+
state.errorMessage = '';
317+
})
318+
.addCase(getIngestPipeline.fulfilled, (state, action) => {
319+
state.loading = false;
320+
state.errorMessage = '';
321+
})
296322
.addCase(searchIndex.fulfilled, (state, action) => {
297323
state.loading = false;
298324
state.errorMessage = '';
@@ -309,6 +335,18 @@ const opensearchSlice = createSlice({
309335
state.errorMessage = action.payload as string;
310336
state.loading = false;
311337
})
338+
.addCase(getIndex.rejected, (state, action) => {
339+
state.errorMessage = action.payload as string;
340+
state.loading = false;
341+
})
342+
.addCase(getIngestPipeline.rejected, (state, action) => {
343+
state.errorMessage = action.payload as string;
344+
state.loading = false;
345+
})
346+
.addCase(getSearchPipeline.rejected, (state, action) => {
347+
state.errorMessage = action.payload as string;
348+
state.loading = false;
349+
})
312350
.addCase(searchIndex.rejected, (state, action) => {
313351
state.errorMessage = action.payload as string;
314352
state.loading = false;

0 commit comments

Comments
 (0)