Skip to content

Commit 0397830

Browse files
authored
Fix: Deleted Content Item is Appearing in the Multi Page Content Table (#2513)
* Fix: Deleted Content Item is Appearing in the Multi Page Content Table * clean up PR * Ref: useDispatch hook instead directly using store
1 parent 2559fe4 commit 0397830

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/apps/content-editor/src/app/views/ItemEdit/components/ItemEditHeader/DeleteItemDialog.tsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@mui/material";
88
import { DeleteRounded } from "@mui/icons-material";
99
import { useHistory, useParams } from "react-router";
10-
import { useSelector } from "react-redux";
10+
import { useDispatch, useSelector } from "react-redux";
1111
import { AppState } from "../../../../../../../../shell/store/types";
1212
import { ContentItem } from "../../../../../../../../shell/services/types";
1313
import {
@@ -22,6 +22,7 @@ type DuplicateItemProps = {
2222
};
2323

2424
export const DeleteItemDialog = ({ onClose }: DuplicateItemProps) => {
25+
const dispatch = useDispatch();
2526
const { modelZUID, itemZUID } = useParams<{
2627
modelZUID: string;
2728
itemZUID: string;
@@ -68,12 +69,21 @@ export const DeleteItemDialog = ({ onClose }: DuplicateItemProps) => {
6869
data-cy="DeleteContentItemConfirmButton"
6970
variant="contained"
7071
color="error"
71-
onClick={() =>
72+
onClick={() => {
7273
deleteContentItem({
7374
modelZUID: modelZUID,
7475
itemZUID: itemZUID,
75-
}).then(() => history.push(`/content/${modelZUID}`))
76-
}
76+
}).then(() => {
77+
/**
78+
* Remove the item from the store before redirecting
79+
*/
80+
dispatch({
81+
type: "REMOVE_ITEM",
82+
itemZUID,
83+
});
84+
history.push(`/content/${modelZUID}`);
85+
});
86+
}}
7787
loading={isLoading}
7888
>
7989
Delete Item

src/apps/content-editor/src/app/views/ItemList/ItemList.js

+2
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export default connect((state, props) => {
209209
})
210210
),
211211
]);
212+
212213
if (_isMounted.current) {
213214
// render 1st page of results
214215
setShouldRunFilters(true);
@@ -220,6 +221,7 @@ export default connect((state, props) => {
220221
// re-render after all pages fetched
221222
setShouldRunFilters(true);
222223
}
224+
223225
setBackgroundLoading(false);
224226
}
225227
} catch (err) {

src/shell/store/content.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ export function fetchItem(modelZUID, itemZUID) {
259259
itemZUID,
260260
});
261261
}
262-
263262
return res;
264263
},
265264
});
@@ -408,7 +407,7 @@ export function saveItem(itemZUID, action = "") {
408407
item.web.metaDescription = item.web.metaDescription.slice(0, 160);
409408
}
410409

411-
/*
410+
/*
412411
Nav item will not be found if item does exist in the nav such is the case
413412
when the item is in a dataset
414413
*/

0 commit comments

Comments
 (0)