Skip to content

Commit 0ff1465

Browse files
committed
refactor
1 parent f75d6bf commit 0ff1465

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

public/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@
388388
"editMCP": {
389389
"dialogTitle": "Edit Managed Control Plane",
390390
"titleText": "Managed Control Plane Updated Successfully!",
391-
"subtitleText": "Your Managed Control Plane is being updated. It will be ready to use in just a few minutes. You can safely close this window."
391+
"subtitleText": "Your Managed Control Plane is being updated. It will be ready to use in just a few minutes. You can safely close this window.",
392+
"editComponents": "Edit components"
392393
},
393394
"componentsSelection": {
394395
"selectComponents": "Select Components",

src/components/ComponentsSelection/ComponentsSelectionContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export const ComponentsSelectionContainer: React.FC<ComponentsSelectionProps> =
2929
componentsList,
3030
}) => {
3131
const { t } = useTranslation();
32-
const { isLoading, error, templateDefaultsError } = useComponentsSelection();
32+
const { isLoading, error, templateDefaultsError, hasInitialized } = useComponentsSelection();
3333

34-
if (isLoading) {
34+
if (isLoading || !hasInitialized) {
3535
return <Loading />;
3636
}
3737

src/components/ComponentsSelection/ComponentsSelectionProvider.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type ComponentsSelectionContextValue = {
2020
isLoading: boolean;
2121
error: unknown;
2222
templateDefaultsError: string | null;
23+
hasInitialized: boolean;
2324
};
2425

2526
const ComponentsSelectionContext = createContext<ComponentsSelectionContextValue | undefined>(undefined);
@@ -69,12 +70,19 @@ export const ComponentsSelectionProvider: React.FC<ComponentsSelectionProviderPr
6970
!availableManagedComponentsListData?.items ||
7071
availableManagedComponentsListData.items.length === 0
7172
) {
73+
if (!availableManagedComponentsListData?.items) {
74+
return;
75+
}
76+
if (availableManagedComponentsListData.items.length === 0) {
77+
setInitialComponentsList([]);
78+
setComponentsList([]);
79+
initializedComponents.current = true;
7280
return;
7381
}
74-
7582
const newComponentsList = availableManagedComponentsListData.items
7683
.map((item) => {
77-
const versions = sortVersions(item.status?.versions ?? []);
84+
const rawVersions = Array.isArray(item.status?.versions) ? (item.status?.versions as string[]) : [];
85+
const versions = sortVersions(rawVersions);
7886
const template = defaultComponents.find((dc) => dc.name === (item.metadata?.name ?? ''));
7987
const templateVersion = template?.version;
8088
let selectedVersion = template
@@ -112,7 +120,6 @@ export const ComponentsSelectionProvider: React.FC<ComponentsSelectionProviderPr
112120
setTemplateDefaultsError(null);
113121
return;
114122
}
115-
116123
const errors: string[] = [];
117124
defaultComponents.forEach((dc: TemplateDefaultComponent) => {
118125
if (!dc?.name) return;
@@ -136,16 +143,15 @@ export const ComponentsSelectionProvider: React.FC<ComponentsSelectionProviderPr
136143
if (!defaultComponents?.length) return;
137144
if (!componentsList?.length) return;
138145
if (initialSelection && Object.keys(initialSelection).length > 0) return;
139-
140146
const anySelected = componentsList.some((c) => c.isSelected);
141147
if (anySelected) return;
142148

143149
const updated = componentsList.map((c) => {
144150
const template = defaultComponents.find((dc) => dc.name === c.name);
145151
if (!template) return c;
146152
const templateVersion = template.version;
147-
const selectedVersion =
148-
templateVersion && Array.isArray(c.versions) && c.versions.includes(templateVersion) ? templateVersion : '';
153+
const safeVersions = Array.isArray(c.versions) ? c.versions : [];
154+
const selectedVersion = templateVersion && safeVersions.includes(templateVersion) ? templateVersion : '';
149155
return { ...c, isSelected: true, selectedVersion } as ComponentsListItem;
150156
});
151157

@@ -157,6 +163,7 @@ export const ComponentsSelectionProvider: React.FC<ComponentsSelectionProviderPr
157163
isLoading: Boolean(isLoading),
158164
error,
159165
templateDefaultsError,
166+
hasInitialized: Boolean(initializedComponents.current),
160167
};
161168

162169
return <ComponentsSelectionContext.Provider value={value}>{children}</ComponentsSelectionContext.Provider>;

src/spaces/mcp/pages/McpPage.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default function McpPage() {
5555
error,
5656
isLoading,
5757
} = useApiResource(ControlPlaneResource(projectName, workspaceName, controlPlaneName));
58+
// @ts-ignore
5859
const displayName = mcp?.metadata?.annotations?.[DISPLAY_NAME_ANNOTATION];
5960
const onEditComponents = () => {
6061
setEditManagedControlPlaneWizardSection('componentSelection');
@@ -159,9 +160,7 @@ export default function McpPage() {
159160
header={
160161
<FlexBox justifyContent={'SpaceBetween'} alignItems={'Center'} style={{ width: '100%' }}>
161162
<Title level="H3">{t('McpPage.componentsTitle')}</Title>{' '}
162-
<Button icon={'edit'} onClick={onEditComponents}>
163-
Edit components
164-
</Button>
163+
<Button tooltip={t('editMCP.editComponents')} icon={'edit'} onClick={onEditComponents} />
165164
</FlexBox>
166165
}
167166
noAnimation

0 commit comments

Comments
 (0)