Skip to content

Commit

Permalink
Fix: Deleted Content Item is Appearing in the Multi Page Content Table (
Browse files Browse the repository at this point in the history
#2513)

* Fix: Deleted Content Item is Appearing in the Multi Page Content Table

* clean up PR

* Ref: useDispatch hook instead directly using store
  • Loading branch information
jomarmontuya authored Feb 2, 2024
1 parent 2559fe4 commit 0397830
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "@mui/material";
import { DeleteRounded } from "@mui/icons-material";
import { useHistory, useParams } from "react-router";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { AppState } from "../../../../../../../../shell/store/types";
import { ContentItem } from "../../../../../../../../shell/services/types";
import {
Expand All @@ -22,6 +22,7 @@ type DuplicateItemProps = {
};

export const DeleteItemDialog = ({ onClose }: DuplicateItemProps) => {
const dispatch = useDispatch();
const { modelZUID, itemZUID } = useParams<{
modelZUID: string;
itemZUID: string;
Expand Down Expand Up @@ -68,12 +69,21 @@ export const DeleteItemDialog = ({ onClose }: DuplicateItemProps) => {
data-cy="DeleteContentItemConfirmButton"
variant="contained"
color="error"
onClick={() =>
onClick={() => {
deleteContentItem({
modelZUID: modelZUID,
itemZUID: itemZUID,
}).then(() => history.push(`/content/${modelZUID}`))
}
}).then(() => {
/**
* Remove the item from the store before redirecting
*/
dispatch({
type: "REMOVE_ITEM",
itemZUID,
});
history.push(`/content/${modelZUID}`);
});
}}
loading={isLoading}
>
Delete Item
Expand Down
2 changes: 2 additions & 0 deletions src/apps/content-editor/src/app/views/ItemList/ItemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export default connect((state, props) => {
})
),
]);

if (_isMounted.current) {
// render 1st page of results
setShouldRunFilters(true);
Expand All @@ -220,6 +221,7 @@ export default connect((state, props) => {
// re-render after all pages fetched
setShouldRunFilters(true);
}

setBackgroundLoading(false);
}
} catch (err) {
Expand Down
3 changes: 1 addition & 2 deletions src/shell/store/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export function fetchItem(modelZUID, itemZUID) {
itemZUID,
});
}

return res;
},
});
Expand Down Expand Up @@ -408,7 +407,7 @@ export function saveItem(itemZUID, action = "") {
item.web.metaDescription = item.web.metaDescription.slice(0, 160);
}

/*
/*
Nav item will not be found if item does exist in the nav such is the case
when the item is in a dataset
*/
Expand Down

0 comments on commit 0397830

Please sign in to comment.