Skip to content

Commit

Permalink
fix: remove workspace support remove projects (#4333)
Browse files Browse the repository at this point in the history
Signed-off-by: miaqiang <[email protected]>
Co-authored-by: miaqiang <[email protected]>
  • Loading branch information
miaqiang and miaqiang authored Nov 5, 2024
1 parent a3f73cd commit a215237
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ module.exports = {
'Enter the workspace name <strong>{resource}</strong> to confirm that you understand the risks of this operation.',
REMOVE_WORKSPACE_CONFIRM_PL:
'Enter the workspace names <strong>{resource}</strong> to confirm that you understand the risks of this operation.',
REMOVE_WORKSPACE_CONFIRM_TIP: 'Delete projects in the workspace',
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ module.exports = {
'Enter the workspace name <strong>{resource}</strong> to confirm that you understand the risks of this operation.',
REMOVE_WORKSPACE_CONFIRM_PL:
'Enter the workspace names <strong>{resource}</strong> to confirm that you understand the risks of this operation.',
REMOVE_WORKSPACE_CONFIRM_TIP: 'Delete projects in the workspace',
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ module.exports = {
'請輸入企業空間名稱 <strong>{resource}</strong> 確保您已了解操作所带来的風險。',
REMOVE_WORKSPACE_CONFIRM_PL:
'請輸入企業空間名稱 <strong>{resource}</strong> 確保您已了解操作所带来的風險。',
REMOVE_WORKSPACE_CONFIRM_TIP: '刪除企業空間的項目',
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ module.exports = {
'请输入企业空间名称 <strong>{resource}</strong> 确保您已了解操作所带来的风险。',
REMOVE_WORKSPACE_CONFIRM_PL:
'请输入企业空间名称 <strong>{resource}</strong> 确保您已了解操作所带来的风险。',
REMOVE_WORKSPACE_CONFIRM_TIP: '删除企业空间的项目',
};
85 changes: 77 additions & 8 deletions packages/console/src/pages/access/containers/Workspaces/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import React, { useRef, useState } from 'react';
import { Link } from 'react-router-dom';
import { Banner, Field, notify, Empty, Card } from '@kubed/components';
import { Banner, Field, notify, Empty, Card, Checkbox } from '@kubed/components';
import { Enterprise, Trash, Pen } from '@kubed/icons';
import {
DataTable,
Expand All @@ -32,14 +32,15 @@ import { CreateWorkspacesModal } from '../../../workspaces/components/Modals';

import type { FormattedWorkspace, WorkspaceFormValues } from '@ks-console/shared';

import { FieldLabel, Wrapper } from './styles';
import { FieldLabel, Wrapper, CheckboxWrapper } from './styles';

const { fetchList } = clusterStore;
const { getListUrl, mapper: workspaceMapper, usePostMutation } = workspaceStore;

export default function Workspaces(): JSX.Element {
const url = getListUrl({});
const tableRef = useRef<any>();
const checkkboxRef = useRef(false);
const [createVisible, setCreateVisible] = useState<boolean>(false);

const refetch = () => {
Expand Down Expand Up @@ -78,10 +79,45 @@ export default function Workspaces(): JSX.Element {
action: 'delete',
onClick: () => {
const selectedRows = tableRef.current?.getSelectedFlatRows() || [];
del({ resource: selectedRows, type: 'WORKSPACE' });
removeDashboardHistory(
globals.user.username,
selectedRows.map((r: { uid: string }) => r.uid),
const onSuccess = () => {
removeDashboardHistory(
globals.user.username,
selectedRows.map((r: { uid: string }) => r.uid),
);
};
del(
{
resource: selectedRows,
type: 'WORKSPACE',
child: (
<CheckboxWrapper>
<Checkbox
label={t('REMOVE_WORKSPACE_CONFIRM_TIP')}
onChange={e => {
checkkboxRef.current = e.target.checked;
}}
/>
</CheckboxWrapper>
),
onOk: async params => {
const deleteParams = selectedRows.map(
(item: { namespace?: string; name: string }) => ({
namespace: item.namespace,
name: item.name,
deleteProject: checkkboxRef.current,
...params,
}),
);
await workspaceStore.batchDelete(deleteParams);
notify.success(t('DELETED_SUCCESSFULLY'));
onSuccess();
refetch();
},
onCancel: () => {
checkkboxRef.current = false;
},
},
'',
);
},
props: {
Expand Down Expand Up @@ -110,8 +146,41 @@ export default function Workspaces(): JSX.Element {
action: 'delete',
show: row => !isSystemWorkspaces(row),
onClick: (_, record) => {
del({ type: 'WORKSPACE', resource: [record] });
removeDashboardHistory(globals.user.username, record.uid);
const onSuccess = () => {
removeDashboardHistory(globals.user.username, record.uid);
};
del(
{
type: 'WORKSPACE',
resource: [record],
child: (
<CheckboxWrapper>
<Checkbox
label={t('REMOVE_WORKSPACE_CONFIRM_TIP')}
onChange={e => {
checkkboxRef.current = e.target.checked;
}}
/>
</CheckboxWrapper>
),
onOk: async params => {
const deleteParams = [record].map(item => ({
namespace: item.namespace,
name: item.name,
deleteProject: checkkboxRef.current,
...params,
}));
await workspaceStore.batchDelete(deleteParams);
notify.success(t('DELETED_SUCCESSFULLY'));
onSuccess();
refetch();
},
onCancel: () => {
checkkboxRef.current = false;
},
},
'',
);
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export const Wrapper = styled.div`
overflow-y: auto;
overflow-x: hidden;
`;

export const CheckboxWrapper = styled.div`
margin-top: 12px;
color: #79879c;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface DeleteConfirmContentProps {
title?: ReactNode;
tip?: string;
desc?: ReactNode;
child?: ReactNode;
onOk?: (data: any[] | undefined) => void;
onCancel?: () => void;
}
Expand Down Expand Up @@ -67,6 +68,7 @@ export function DeleteConfirmContent({
desc,
onCancel = () => {},
onOk = () => {},
child,
}: // ...rest
DeleteConfirmContentProps) {
// @ts-ignore
Expand Down Expand Up @@ -163,6 +165,7 @@ DeleteConfirmContentProps) {
/>
)}
{desc}
{child ?? child}
</Content>
</Body>
<Footer>
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/stores/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,19 @@ const patch = async (params: PathParams, data: Record<string, any>) => {

interface DeleteWorkspaceOptions extends PathParams {
shouldDeleteResource?: boolean;
deleteProject?: boolean;
}

const deleteWorkspace = ({ shouldDeleteResource, ...params }: DeleteWorkspaceOptions) => {
const deleteWorkspace = ({
shouldDeleteResource,
deleteProject,
...params
}: DeleteWorkspaceOptions) => {
const data = !shouldDeleteResource
? {
kind: 'DeleteOptions',
apiVersion: 'v1',
propagationPolicy: 'Orphan',
propagationPolicy: deleteProject ? 'Background' : 'Orphan',
}
: {};
return request.delete<never, OriginalWorkspace, Record<string, any>>(getDetailUrl(params), {
Expand Down

0 comments on commit a215237

Please sign in to comment.