-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added post delete mutation for posts in the admin-x-activitypub
app
#22330
base: main
Are you sure you want to change the base?
Added post delete mutation for posts in the admin-x-activitypub
app
#22330
Conversation
Warning Rate limit exceeded@mike182uk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 57 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (4)
WalkthroughThis update adds deletion capabilities to the ActivityPub implementation. A new boolean property, Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
a4716b4
to
11cd1a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
apps/admin-x-activitypub/src/hooks/use-activity-pub-queries.ts (1)
819-882
: Comprehensive implementation with room for improvement in cache managementThe implementation is solid, handling optimistic updates and error recovery for feed and inbox. However, despite defining query keys for
outboxQueryKey
,likedQueryKey
, andprofilePostsQueryKey
, the code doesn't update these caches optimistically, which could lead to stale data.Consider updating all defined caches to maintain consistent state across the application. Here's a suggestion for extending the optimistic updates:
onMutate: (id) => { // Find the post in the feed query cache const previousFeed = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(feedQueryKey); queryClient.setQueryData(feedQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { if (!current) { return current; } return { ...current, pages: current.pages.map((page: {posts: Activity[]}) => { return { ...page, posts: page.posts.filter((item: Activity) => item.id !== id) }; }) }; }); // Find the post in the inbox query cache const previousInbox = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(inboxQueryKey); queryClient.setQueryData(inboxQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { if (!current) { return current; } return { ...current, pages: current.pages.map((page: {posts: Activity[]}) => { return { ...page, posts: page.posts.filter((item: Activity) => item.id !== id) }; }) }; }); + // Also update outbox, liked, and profile posts caches + const previousOutbox = queryClient.getQueryData<{pages: {data: Activity[]}[]}[]>(outboxQueryKey); + queryClient.setQueryData(outboxQueryKey, (current?: {pages: {data: Activity[]}[]}) => { + if (!current) { + return current; + } + + return { + ...current, + pages: current.pages.map((page: {data: Activity[]}) => { + return { + ...page, + data: page.data.filter((item: Activity) => item.id !== id) + }; + }) + }; + }); + + // Similar updates for likedQueryKey and profilePostsQueryKey + return { previousFeed, previousInbox, + previousOutbox, + // Add other previous states }; }, onError: (_err, _variables, context) => { queryClient.setQueryData(feedQueryKey, context?.previousFeed); queryClient.setQueryData(inboxQueryKey, context?.previousInbox); + queryClient.setQueryData(outboxQueryKey, context?.previousOutbox); + // Restore other caches }apps/admin-x-activitypub/src/components/feed/FeedItem.tsx (2)
218-224
: Improve user confirmation UX for delete operationThe current confirmation dialog is minimal and only shows the post ID, which isn't user-friendly. Consider showing a more descriptive message that includes some content from the post.
const handleDelete = (postId: string) => { - const confirm = window.confirm(`Delete post\n\n${postId}\n\n?`); + // Get a readable post identifier (title or first few characters of content) + const postIdentifier = object.name || + (object.content ? stripHtml(object.content).substring(0, 50) + '...' : 'this post'); + const confirm = window.confirm(`Are you sure you want to delete "${postIdentifier}"?\n\nThis action cannot be undone.`); if (confirm) { deletePostMutation.mutate(postId); } };
259-265
: Remove TODO commentThe TODO comment about deleting posts can now be removed since you've implemented the functionality.
- // TODO: If this is your own Note/Article, you should be able to delete it - // menuItems.push({ - // id: 'delete', - // label: 'Delete', - // destructive: true, - // onClick: handleDelete - // });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/admin-x-activitypub/src/api/activitypub.ts
(4 hunks)apps/admin-x-activitypub/src/components/feed/FeedItem.tsx
(4 hunks)apps/admin-x-activitypub/src/hooks/use-activity-pub-queries.ts
(1 hunks)apps/admin-x-activitypub/src/utils/posts.ts
(1 hunks)
🔇 Additional comments (7)
apps/admin-x-activitypub/src/utils/posts.ts (1)
107-107
: LGTM! Appropriate handling of author status.The explicit comparison
=== true
ensures that the property is boolean, avoiding potential issues with falsy values. This change properly supports the post deletion feature being implemented.apps/admin-x-activitypub/src/components/feed/FeedItem.tsx (2)
195-195
: LGTM! Good initialization of the delete mutation hook.The hook is properly initialized with 'index' as the handle parameter.
251-257
: LGTM! Appropriate conditional rendering of delete optionThe delete menu item is correctly displayed only when the post is authored by the current user, ensuring proper access control.
apps/admin-x-activitypub/src/api/activitypub.ts (4)
104-104
: LGTM! Clear interface extension.Adding the
authoredByMe
boolean property to thePost
interface is a clean way to track post ownership.
137-137
: Type update correctly expands HTTP method supportThe update to include 'DELETE' as a valid method type is appropriate and follows TypeScript best practices.
151-155
: Proper handling of HTTP 204 No Content responsesThe implementation correctly handles 204 status code responses by returning null, which is appropriate for successful deletion operations that don't return content.
307-310
: Well-implemented delete methodThe delete method follows the established pattern in the class, using the appropriate URL structure and HTTP method. The implementation is clean and consistent with the codebase's style.
const previousFeed = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(feedQueryKey); | ||
queryClient.setQueryData(feedQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix type assertion in getQueryData
The type assertion <{pages: {posts: Activity[]}[]}[]>
doesn't match the structure returned by the query. This could lead to runtime type errors.
- const previousFeed = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(feedQueryKey);
+ const previousFeed = queryClient.getQueryData<{pages: {posts: Activity[]}[]}>(feedQueryKey);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const previousFeed = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(feedQueryKey); | |
queryClient.setQueryData(feedQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { | |
const previousFeed = queryClient.getQueryData<{pages: {posts: Activity[]}[]}>(feedQueryKey); | |
queryClient.setQueryData(feedQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { |
const previousInbox = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(inboxQueryKey); | ||
queryClient.setQueryData(inboxQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix type assertion in getQueryData
Same issue as previous comment - the type assertion doesn't match the structure returned by the query.
- const previousInbox = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(inboxQueryKey);
+ const previousInbox = queryClient.getQueryData<{pages: {posts: Activity[]}[]}>(inboxQueryKey);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const previousInbox = queryClient.getQueryData<{pages: {posts: Activity[]}[]}[]>(inboxQueryKey); | |
queryClient.setQueryData(inboxQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { | |
const previousInbox = queryClient.getQueryData<{pages: {posts: Activity[]}[]}>(inboxQueryKey); | |
queryClient.setQueryData(inboxQueryKey, (current?: {pages: {posts: Activity[]}[]}) => { |
11cd1a5
to
038d842
Compare
refs [AP-806](https://linear.app/ghost/issue/AP-806/wire-up-the-delete-buttons-to-the-deleteid-api) Added post delete mutation for posts in the `admin-x-activitypub` app
038d842
to
7f85b92
Compare
refs AP-806
Added post delete mutation for posts in the
admin-x-activitypub
app