Skip to content

Commit 2df0a8f

Browse files
committed
[Fix]: #1848 delete/recycled and movetofolder
1 parent 9e10673 commit 2df0a8f

File tree

2 files changed

+55
-57
lines changed

2 files changed

+55
-57
lines changed

client/packages/lowcoder/src/pages/ApplicationV2/HomeResOptions.tsx

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { HomeResTypeEnum } from "../../types/homeRes";
33
import { exportApplicationAsJSONFile } from "./components/AppImport";
44
import { CustomModal, EditPopover, EditPopoverItemType, PointIcon } from "lowcoder-design";
55
import { HomeResInfo } from "../../util/homeResUtils";
6-
import { recycleApplication } from "../../redux/reduxActions/applicationActions";
7-
import { deleteFolder } from "../../redux/reduxActions/folderActions";
86
import { useDispatch } from "react-redux";
97
import React, { useState } from "react";
108
import styled from "styled-components";
@@ -13,6 +11,9 @@ import { useParams } from "react-router-dom";
1311
import { AppTypeEnum } from "constants/applicationConstants";
1412
import { CopyModal } from "pages/common/copyModal";
1513
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
14+
import ApplicationApi from "../../api/applicationApi";
15+
import { FolderApi } from "../../api/folderApi";
16+
import { ReduxActionTypes } from "constants/reduxActionConstants";
1617

1718
const PopoverIcon = styled(PointIcon)`
1819
cursor: pointer;
@@ -80,23 +81,20 @@ export const HomeResOptions = (props: {
8081
type: HomeResInfo[res.type].name,
8182
name: <b>{res.name}</b>,
8283
}),
83-
onConfirm: () =>{
84-
new Promise((resolve, reject) => {
85-
dispatch(
86-
recycleApplication(
87-
{ applicationId: res.id, folderId: folderId },
88-
() => {
89-
messageInstance.success(trans("success"));
90-
resolve(true);
91-
},
92-
() => reject()
93-
)
94-
);
84+
onConfirm: async () => {
85+
try {
86+
await ApplicationApi.recycleApplication({
87+
applicationId: res.id,
88+
folderId: folderId || ""
89+
});
90+
messageInstance.success(trans("success"));
9591
setTimeout(() => {
9692
setModify(!modify);
9793
}, 200);
98-
})
99-
94+
} catch (error) {
95+
console.error("Failed to recycle application:", error);
96+
messageInstance.error("Failed to delete application");
97+
}
10098
},
10199
confirmBtnType: "delete",
102100
okText: trans("home.moveToTrash"),
@@ -122,22 +120,27 @@ export const HomeResOptions = (props: {
122120
type: HomeResInfo[res.type].name.toLowerCase(),
123121
name: <b>{res.name}</b>,
124122
}),
125-
onConfirm: () =>{
126-
new Promise((resolve, reject) => {
127-
dispatch(
128-
deleteFolder(
129-
{ folderId: res.id, parentFolderId: folderId },
130-
() => {
131-
messageInstance.success(trans("home.deleteSuccessMsg"));
132-
resolve(true);
133-
},
134-
() => reject()
135-
)
136-
);
137-
})
138-
setTimeout(() => {
139-
setModify(!modify);
140-
}, 200);
123+
onConfirm: async () => {
124+
try {
125+
await FolderApi.deleteFolder({
126+
folderId: res.id,
127+
parentFolderId: folderId || ""
128+
});
129+
130+
// Update Redux state to remove deleted folder from dropdown
131+
dispatch({
132+
type: ReduxActionTypes.DELETE_FOLDER_SUCCESS,
133+
payload: { folderId: res.id, parentFolderId: folderId || "" }
134+
});
135+
136+
messageInstance.success(trans("home.deleteSuccessMsg"));
137+
setTimeout(() => {
138+
setModify(!modify);
139+
}, 200);
140+
} catch (error) {
141+
console.error("Failed to delete folder:", error);
142+
messageInstance.error("Failed to delete folder");
143+
}
141144
},
142145
confirmBtnType: "delete",
143146
okText: trans("delete"),

client/packages/lowcoder/src/pages/ApplicationV2/TrashTableView.tsx

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import styled from "styled-components";
55
import { useDispatch } from "react-redux";
66
import { HomeResInfo } from "../../util/homeResUtils";
77
import { HomeResTypeEnum } from "../../types/homeRes";
8-
import { deleteApplication, restoreApplication } from "../../redux/reduxActions/applicationActions";
98
import { HomeRes } from "./HomeLayout";
109
import { trans, transToNode } from "../../i18n";
1110
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
1211
import { BrandedIcon } from "@lowcoder-ee/components/BrandedIcon";
12+
import ApplicationApi from "../../api/applicationApi";
1313

1414
const OperationWrapper = styled.div`
1515
display: flex;
@@ -123,17 +123,18 @@ export const TrashTableView = (props: { resources: HomeRes[] , setModify: any, m
123123
style={{ padding: "0 8px", width: "fit-content", minWidth: "52px" }}
124124
buttonType={"blue"}
125125
className={"home-datasource-edit-button"}
126-
onClick={() =>{
127-
dispatch(
128-
restoreApplication({ applicationId: item.id }, () => {
129-
messageInstance.success(trans("home.recoverSuccessMsg"));
130-
})
131-
)
126+
onClick={async () => {
127+
try {
128+
await ApplicationApi.restoreApplication({ applicationId: item.id });
129+
messageInstance.success(trans("home.recoverSuccessMsg"));
132130
setTimeout(() => {
133-
setModify(!modify);
131+
setModify(!modify);
134132
}, 200);
135-
}
136-
}
133+
} catch (error) {
134+
console.error("Failed to restore application:", error);
135+
messageInstance.error("Failed to restore application");
136+
}
137+
}}
137138
>
138139
{trans("recover")}
139140
</EditBtn>
@@ -148,27 +149,21 @@ export const TrashTableView = (props: { resources: HomeRes[] , setModify: any, m
148149
type: HomeResInfo[item.type].name.toLowerCase(),
149150
name: <b>{item.name}</b>,
150151
}),
151-
onConfirm: () =>{
152-
new Promise((resolve, reject) => {
153-
dispatch(
154-
deleteApplication(
155-
{ applicationId: item.id },
156-
() => {
157-
messageInstance.success(trans("home.deleteSuccessMsg"));
158-
resolve(true);
159-
},
160-
() => reject()
161-
)
162-
);
163-
})
152+
onConfirm: async () => {
153+
try {
154+
await ApplicationApi.deleteApplication({ applicationId: item.id });
155+
messageInstance.success(trans("home.deleteSuccessMsg"));
164156
setTimeout(() => {
165-
setModify(!modify);
157+
setModify(!modify);
166158
}, 200);
159+
} catch (error) {
160+
console.error("Failed to delete application:", error);
161+
messageInstance.error("Failed to delete application permanently");
162+
}
167163
},
168164
confirmBtnType: "delete",
169165
okText: trans("delete"),
170166
})
171-
172167
}
173168
style={{ marginLeft: "12px", width: "76px" }}
174169
>

0 commit comments

Comments
 (0)