fix: add worker default selection is incorrect

This commit is contained in:
jialin
2026-01-08 11:01:06 +08:00
parent 0cff804cd7
commit 7b5ce83cbd
2 changed files with 23 additions and 19 deletions
@@ -29,26 +29,36 @@ const useAddWorker = (props: {
cluster_id: null
});
const handleAddWorker = async (row: ClusterListItem) => {
const handleAddWorker = async (row: ClusterListItem, fromWorker = false) => {
try {
if (!row?.id) return;
// set the title based on provider type
const title =
let title =
row.provider === ProviderValueMap.Docker
? intl.formatMessage({ id: 'resources.button.create' })
: intl.formatMessage({ id: 'clusters.button.register' });
if (!row?.id) return;
let clusterId: number | null = [
ProviderValueMap.Docker,
ProviderValueMap.Kubernetes
].includes(row.provider as string)
? row.id
: null;
if (fromWorker) {
title = intl.formatMessage({ id: 'resources.button.create' });
}
if (fromWorker && row.provider === ProviderValueMap.Kubernetes) {
clusterId = null;
}
setOpenAddWorker({
open: true,
title: title,
provider: row.provider as ProviderType,
cluster_id: [
ProviderValueMap.Docker,
ProviderValueMap.Kubernetes
].includes(row.provider as string)
? row.id
: null
cluster_id: clusterId
});
} catch (error: any) {
message.error(error?.message || 'Failed to fetch cluster token');
@@ -83,8 +93,7 @@ const useAddWorker = (props: {
* @returns
*/
const checkDefaultCluster = (
clusterList: Global.BaseOption<number, ClusterListItem>[],
includeDigitalOcean?: boolean
clusterList: Global.BaseOption<number, ClusterListItem>[]
) => {
// select default and ready cluster first, digitalocean no READY state
let currentData = clusterList.find(