Skip to content
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

moderation: fix admin links generation #2722

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is part of Invenio.
* Copyright (C) 2022-2024 CERN.
* Copyright (C) 2024 KTH Royal Institute of Technology.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -22,8 +23,18 @@ class SearchResultItemComponent extends Component {
updateQueryState(currentQueryState);
};

buildAdminLinks = (userId) => {
const baseQuery = `parent.access.owned_by.user:${userId}`;
return {
admin_records_html: `/administration/records?q=${baseQuery}&f=allversions`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest not to generate the links in the ui whenever not absolutely unavoidable, but to use the ones supplied by REST API, otherwise the code becomes very difficult to maintain

admin_drafts_html: `/administration/drafts?q=${baseQuery}&f=allversions`,
admin_moderation_html: `/administration/moderation?q=topic.user:${userId}`,
};
};

render() {
const { result, idKeyPath, listUIEndpoint } = this.props;
const adminLinks = this.buildAdminLinks(result.id);

return (
<Table.Row>
Expand Down Expand Up @@ -153,15 +164,15 @@ class SearchResultItemComponent extends Component {
<Dropdown.Menu>
<Dropdown.Item
text="Records"
onClick={() => (window.location = result.links.admin_records_html)}
onClick={() => (window.location = adminLinks.admin_records_html)}
/>
<Dropdown.Item
text="Drafts"
onClick={() => (window.location = result.links.admin_drafts_html)}
onClick={() => (window.location = adminLinks.admin_drafts_html)}
/>
<Dropdown.Item
text="Moderation"
onClick={() => (window.location = result.links.admin_moderation_html)}
onClick={() => (window.location = adminLinks.admin_moderation_html)}
/>
</Dropdown.Menu>
</Dropdown>
Expand Down
Loading