Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ui/apps/dashboard/src/pages/cluster-manage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ClusterManagePage = () => {
return ret.data;
},
});
const [deletingNames, setDeletingNames] = useState<Set<string>>(new Set());
const [clusterModalData, setModalData] = useState<{
mode: 'create' | 'edit';
open: boolean;
Expand Down Expand Up @@ -227,6 +228,11 @@ const ClusterManagePage = () => {
name: r.objectMeta.name,
}),
);
setDeletingNames((prev) => {
const next = new Set(prev);
next.add(r.objectMeta.name);
return next;
});
Comment thread
RafsanNeloy marked this conversation as resolved.
await refetch();
} else {
await messageApi.error(
Expand Down Expand Up @@ -283,7 +289,9 @@ const ClusterManagePage = () => {
rowKey={(r: Cluster) => r.objectMeta.name || ''}
columns={columns}
loading={isLoading}
dataSource={data?.clusters || []}
dataSource={(data?.clusters || []).filter(
(r: Cluster) => !deletingNames.has(r.objectMeta.name),
)}
/>

<NewClusterModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ import OverridePolicyEditorDrawer, {
import { GetNamespaces } from '@/services/namespace.ts';

export type PolicyScope = 'namespace-scope' | 'cluster-scope';
Comment thread
RafsanNeloy marked this conversation as resolved.
Outdated
const getPolicyKey = (
policy: OverridePolicy | ClusterOverridePolicy,
scope: PolicyScope,
) => {
return scope === 'cluster-scope'
? policy.objectMeta.name
: `${policy.objectMeta.namespace}-${policy.objectMeta.name}`;
};
Comment thread
RafsanNeloy marked this conversation as resolved.
Outdated

const OverridePolicyManage = () => {
const [filter, setFilter] = useState<{
policyScope: PolicyScope;
Expand All @@ -60,6 +69,7 @@ const OverridePolicyManage = () => {
selectedWorkSpace: '',
searchText: '',
});
const [deletingNames, setDeletingNames] = useState<Set<string>>(new Set());
const { data, isLoading, refetch } = useQuery({
queryKey: ['GetOverridePolicies', JSON.stringify(filter)],
queryFn: async () => {
Expand Down Expand Up @@ -228,6 +238,13 @@ const OverridePolicyManage = () => {
'删除成功',
),
);
setDeletingNames((prev) => {
const next = new Set(prev);
const key = getPolicyKey(r, filter.policyScope);

next.add(key);
return next;
});
Comment thread
RafsanNeloy marked this conversation as resolved.
await refetch();
} else {
await messageApi.error(
Expand Down Expand Up @@ -361,10 +378,19 @@ const OverridePolicyManage = () => {
</div>
</div>
<Table
rowKey={(r: OverridePolicy) => r.objectMeta.name || ''}
rowKey={(r: OverridePolicy | ClusterOverridePolicy) =>
getPolicyKey(r, filter.policyScope)
}

columns={columns}
loading={isLoading}
dataSource={data || []}
dataSource={(data || []).filter(
(r: OverridePolicy | ClusterOverridePolicy) => {
const key = getPolicyKey(r, filter.policyScope);

return !deletingNames.has(key);
},
)}
/>
<OverridePolicyEditorDrawer
open={editorDrawerData.open}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ import { useDebounce } from '@uidotdev/usehooks';
import { PolicyScope } from '@/services/base.ts';
import useNamespace from '@/hooks/use-namespace.ts';

const getPolicyKey = (
policy: PropagationPolicy | ClusterPropagationPolicy,
scope: PolicyScope,
) => {
return scope === PolicyScope.Cluster
? policy.objectMeta.name
: `${policy.objectMeta.namespace}-${policy.objectMeta.name}`;
};


const PropagationPolicyManage = () => {
const [filter, setFilter] = useState<{
policyScope: PolicyScope;
Expand All @@ -57,6 +67,7 @@ const PropagationPolicyManage = () => {
selectedNamespace: '',
searchText: '',
});
const [deletingNames, setDeletingNames] = useState<Set<string>>(new Set());
const debouncedSearchText = useDebounce(filter.searchText, 300);
const { data, isLoading, refetch } = useQuery({
queryKey: [
Expand Down Expand Up @@ -214,6 +225,13 @@ const PropagationPolicyManage = () => {
'删除成功',
),
);
setDeletingNames((prev) => {
const next = new Set(prev);
const key = getPolicyKey(r, filter.policyScope);

next.add(key);
return next;
});
Comment thread
RafsanNeloy marked this conversation as resolved.
await refetch();
} else {
await messageApi.error(
Expand Down Expand Up @@ -354,10 +372,18 @@ const PropagationPolicyManage = () => {
</div>

<Table
rowKey={(r: PropagationPolicy) => r.objectMeta.name || ''}
rowKey={(r: PropagationPolicy | ClusterPropagationPolicy) =>
getPolicyKey(r, filter.policyScope)
}

columns={columns}
loading={isLoading}
dataSource={data || []}
dataSource={(data || []).filter(
(r: PropagationPolicy | ClusterPropagationPolicy) => {
const key = getPolicyKey(r, filter.policyScope);

return !deletingNames.has(key);
})}
/>

<PropagationPolicyEditorDrawer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface ConfigMapTableProps {
onViewConfigMapContent: (r: any) => void;
onEditConfigMapContent: (r: any) => void;
onDeleteConfigMapContent: (r: Config) => void;
deletingNames: Set<string>;
}
const ConfigMapTable: FC<ConfigMapTableProps> = (props) => {
const {
Expand All @@ -38,6 +39,7 @@ const ConfigMapTable: FC<ConfigMapTableProps> = (props) => {
onViewConfigMapContent,
onEditConfigMapContent,
onDeleteConfigMapContent,
deletingNames,
} = props;
const columns: TableColumnProps<Config>[] = [
{
Expand Down Expand Up @@ -169,7 +171,10 @@ const ConfigMapTable: FC<ConfigMapTableProps> = (props) => {
}
columns={columns}
loading={isLoading}
dataSource={data?.items || []}
dataSource={(data?.items || []).filter(
(c: Config) =>
!deletingNames.has(`${c.objectMeta.namespace}-${c.objectMeta.name}`),
)}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface SecretTableProps {
onViewSecret: (r: any) => void;
onEditSecret: (r: Secret) => void;
onDeleteSecretContent: (r: Secret) => void;
deletingNames: Set<string>;
}
const SecretTable: FC<SecretTableProps> = (props) => {
const {
Expand All @@ -38,6 +39,7 @@ const SecretTable: FC<SecretTableProps> = (props) => {
onViewSecret,
onEditSecret,
onDeleteSecretContent,
deletingNames,
} = props;
const { data, isLoading } = useQuery({
queryKey: ['GetSecrets', selectedWorkSpace, searchText],
Expand Down Expand Up @@ -169,7 +171,10 @@ const SecretTable: FC<SecretTableProps> = (props) => {
}
columns={columns}
loading={isLoading}
dataSource={data?.secrets || []}
dataSource={(data?.secrets || []).filter(
(s: Secret) =>
!deletingNames.has(`${s.objectMeta.namespace}-${s.objectMeta.name}`),
)}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import { useStore } from './store.ts';
import { message } from 'antd';
import { DeleteResource } from '@/services/unstructured.ts';
import { useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
import SecretTable from '@/pages/multicloud-resource-manage/config/components/secret-table.tsx';
const ConfigPage = () => {
const [deletingNames, setDeletingNames] = useState<Set<string>>(new Set());
const { nsOptions, isNsDataLoading } = useNamespace({});
const { tagNum } = useTagNum();
const filter = useStore((state) => state.filter);
Expand Down Expand Up @@ -87,6 +89,13 @@ const ConfigPage = () => {
),
);
}
if (ret.code === 200) {
setDeletingNames((prev) => {
const next = new Set(prev);
next.add(`${r.objectMeta.namespace}-${r.objectMeta.name}`);
return next;
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this logic is correct, the surrounding code has separate if blocks for success (code === 200) and failure (code !== 200). For better readability and to follow a more standard pattern, consider refactoring this into a single if/else block.

await queryClient.invalidateQueries({
queryKey: ['GetConfigMaps'],
exact: false,
Expand All @@ -95,6 +104,7 @@ const ConfigPage = () => {
console.log('error', e);
}
}}
deletingNames={deletingNames}
/>
)}
{filter.kind === ConfigKind.Secret && (
Expand Down Expand Up @@ -123,6 +133,13 @@ const ConfigPage = () => {
),
);
}
if (ret.code === 200) {
setDeletingNames((prev) => {
const next = new Set(prev);
next.add(`${r.objectMeta.namespace}-${r.objectMeta.name}`);
return next;
});
}
Comment thread
RafsanNeloy marked this conversation as resolved.
Outdated
await queryClient.invalidateQueries({
queryKey: ['GetSecrets'],
exact: false,
Expand All @@ -131,6 +148,7 @@ const ConfigPage = () => {
console.log('error', e);
}
}}
deletingNames={deletingNames}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import TagList, { convertLabelToTags } from '@/components/tag-list';

const NamespacePage = () => {
const [searchFilter, setSearchFilter] = useState('');
const [deletingNames, setDeletingNames] = useState<Set<string>>(new Set());
const { data, isLoading, refetch } = useQuery({
queryKey: ['GetNamespaces', searchFilter],
queryFn: async () => {
Expand Down Expand Up @@ -130,6 +131,11 @@ const NamespacePage = () => {
'删除命名空间成功',
),
);
setDeletingNames((prev) => {
const next = new Set(prev);
next.add(r.objectMeta.name);
return next;
});
Comment thread
RafsanNeloy marked this conversation as resolved.
Outdated
await refetch();
} else {
await messageApi.error(
Expand Down Expand Up @@ -190,7 +196,11 @@ const NamespacePage = () => {
rowKey={(r: Namespace) => r.objectMeta.name || ''}
columns={columns}
loading={isLoading}
dataSource={data?.namespaces || []}
dataSource={
(data?.namespaces || []).filter(
(n: Namespace) => !deletingNames.has(n.objectMeta.name),
)
}
/>

<NewNamespaceModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface ServiceTableProps {
searchText: string;
onViewIngressContent: (r: any) => void;
onDeleteIngressContent: (r: Ingress) => void;
deletingNames: Set<string>;
}
const IngressTable: FC<ServiceTableProps> = (props) => {
const {
Expand All @@ -39,6 +40,7 @@ const IngressTable: FC<ServiceTableProps> = (props) => {
searchText,
onViewIngressContent,
onDeleteIngressContent,
deletingNames,
} = props;
const columns: TableColumnProps<Ingress>[] = [
{
Expand Down Expand Up @@ -165,7 +167,10 @@ const IngressTable: FC<ServiceTableProps> = (props) => {
}
columns={columns}
loading={isLoading}
dataSource={data?.items || []}
dataSource={(data?.items || []).filter(
(i: Ingress) =>
!deletingNames.has(`${i.objectMeta.namespace}-${i.objectMeta.name}`),
)}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ServiceTableProps {
onViewServiceContent: (r: any) => void;
onEditServiceContent: (r: any) => void;
onDeleteServiceContent: (r: Service) => void;
deletingNames: Set<string>;
}
const ServiceTable: FC<ServiceTableProps> = (props) => {
const {
Expand All @@ -41,6 +42,7 @@ const ServiceTable: FC<ServiceTableProps> = (props) => {
onViewServiceContent,
onEditServiceContent,
onDeleteServiceContent,
deletingNames,
} = props;
const columns: TableColumnProps<Service>[] = [
{
Expand Down Expand Up @@ -169,7 +171,10 @@ const ServiceTable: FC<ServiceTableProps> = (props) => {
}
columns={columns}
loading={isLoading}
dataSource={data?.services || []}
dataSource={(data?.services || []).filter(
(s: Service) =>
!deletingNames.has(`${s.objectMeta.namespace}-${s.objectMeta.name}`),
)}
/>
);
};
Expand Down
Loading
Loading