From 535b0b2506626806c0389a60c5b45dadb82dbecb Mon Sep 17 00:00:00 2001 From: Ian Scott Date: Fri, 8 Nov 2024 13:30:09 -0500 Subject: [PATCH] fix(dashboard): Fixed dashboard edit and view links for drafts --- .../overridableRegistry/mapping.js | 3 +- .../RecordsResultsListItemDashboard.jsx | 111 +++++++++++ .../ComputerTabletUploadsItem.jsx | 173 ++++++++++++++++++ 3 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 assets/js/invenio_app_rdm/overridableRegistry/search/RecordsResultsListItemDashboard.jsx create mode 100644 assets/js/invenio_app_rdm/overridableRegistry/user_dashboard/uploads_items/ComputerTabletUploadsItem.jsx diff --git a/assets/js/invenio_app_rdm/overridableRegistry/mapping.js b/assets/js/invenio_app_rdm/overridableRegistry/mapping.js index 1d40031e..d4b143f0 100644 --- a/assets/js/invenio_app_rdm/overridableRegistry/mapping.js +++ b/assets/js/invenio_app_rdm/overridableRegistry/mapping.js @@ -32,6 +32,7 @@ import { PublicMembersResultsItemWithCommunity } from "./collections/members/pub import { PublisherField } from "./fields/PublisherField"; import { RDMRecordMultipleSearchBarElement } from "./search/RDMRecordMultipleSearchBarElement"; import RecordsResultsListItem from "./search/RecordsResultsListItem"; +import { RecordResultsListItemDashboard } from "./search/RecordsResultsListItemDashboard"; import { RequestMetadata } from "./requests/RequestMetadata"; import { RequestsResultsItemTemplateDashboard } from "./user_dashboard/RequestsResultsItemTemplateDashboard"; import { RequestsResultsItemTemplateWithCommunity } from "./collections/members/requests/RequestsResultsItemTemplate"; @@ -87,7 +88,7 @@ export const overriddenComponents = { "InvenioAppRdm.DashboardRequests.SearchApp.layout": DashboardRequestsSearchLayoutWithApp, "InvenioAppRdm.DashboardRequests.ResultsList.item": RequestsResultsItemTemplateDashboard, "InvenioAppRdm.DashboardUploads.SearchApp.layout": DashboardUploadsSearchLayout, - "InvenioAppRdm.DashboardUploads.ResultsList.item": RecordsResultsListItem, + "InvenioAppRdm.DashboardUploads.ResultsList.item": RecordResultsListItemDashboard, "InvenioAppRdm.Deposit.AccessRightField.container": AccessRightField, "InvenioAppRdm.Deposit.CreatorsField.container": CreatibutorsField, "InvenioAppRdm.Deposit.ContributorsField.container": CreatibutorsField, diff --git a/assets/js/invenio_app_rdm/overridableRegistry/search/RecordsResultsListItemDashboard.jsx b/assets/js/invenio_app_rdm/overridableRegistry/search/RecordsResultsListItemDashboard.jsx new file mode 100644 index 00000000..0de8d31e --- /dev/null +++ b/assets/js/invenio_app_rdm/overridableRegistry/search/RecordsResultsListItemDashboard.jsx @@ -0,0 +1,111 @@ +/* +* This file is part of Knowledge Commons Works. +* Copyright (C) 2024 Mesh Research. +* +* Knowledge Commons Works is based on InvenioRDM, and +* this file is based on code from InvenioRDM. InvenioRDM is +* Copyright (C) 2020-2024 CERN. +* Copyright (C) 2020-2024 Northwestern University. +* Copyright (C) 2020-2024 T U Wien. +* +* InvenioRDM and Knowledge Commons Works are both free software; +* you can redistribute and/or modify them under the terms of the +* MIT License; see LICENSE file for more details. +* +* FIXME: This should be merged with RecordsResultsListItem.js +*/ + +import React from "react"; +import { ComputerTabletUploadsItem } from "../user_dashboard/uploads_items/ComputerTabletUploadsItem"; +import _get from "lodash/get"; +import { i18next } from "@translations/invenio_app_rdm/i18next"; +import { http } from "react-invenio-forms"; +import PropTypes from "prop-types"; + +const statuses = { + in_review: { color: "warning", title: i18next.t("In review") }, + declined: { color: "negative", title: i18next.t("Declined") }, + expired: { color: "expired", title: i18next.t("Expired") }, + draft_with_review: { color: "neutral", title: i18next.t("Draft") }, + draft: { color: "neutral", title: i18next.t("Draft") }, + new_version_draft: { color: "neutral", title: i18next.t("New version draft") }, + published: { color: "positive", title: i18next.t("Published") }, +}; + +const RecordResultsListItemDashboard = ({ currentQueryState, result, key, appName }) => { + console.log(currentQueryState); + console.log("appName", appName); + const editRecord = () => { + http + .post( + `/api/records/${result.id}/draft`, + {}, + { + headers: { + "Content-Type": "application/json", + "Accept": "application/vnd.inveniordm.v1+json", + }, + } + ) + .then(() => { + window.location = `/uploads/${result.id}`; + }) + .catch((error) => { + console.error(error.response.data); + }); + }; + + const filters = currentQueryState && Object.fromEntries(currentQueryState.filters); + const isPublished = result.is_published; + const access = { + accessStatusId: _get(result, "ui.access_status.id", i18next.t("open")), + accessStatus: _get(result, "ui.access_status.title_l10n", i18next.t("Open")), + accessStatusIcon: _get(result, "ui.access_status.icon", i18next.t("unlock")), + }; + const versions = _get(result, "versions"); + const uiMetadata = { + descriptionStripped: _get( + result, + "ui.description_stripped", + i18next.t("No description") + ), + title: _get(result, "metadata.title", i18next.t("No title")), + creators: _get(result, "ui.creators.creators", []).slice(0, 3), + subjects: _get(result, "ui.subjects", []), + publicationDate: _get( + result, + "ui.publication_date_l10n_long", + i18next.t("No publication date found.") + ), + resourceType: _get( + result, + "ui.resource_type.title_l10n", + i18next.t("No resource type") + ), + createdDate: result.ui?.created_date_l10n_long, + version: result.ui?.version ?? "", + versions: versions, + isPublished: isPublished, + viewLink: isPublished ? `/records/${result.id}` : `/records/${result.id}?preview=1`, + publishingInformation: _get(result, "ui.publishing_information.journal", ""), + allVersionsVisible: filters?.allversions, + numOtherVersions: versions.index - 1, + }; + + + return ( + + ); +}; + +RecordResultsListItemDashboard.propTypes = { + result: PropTypes.object.isRequired, +}; + +export { RecordResultsListItemDashboard }; \ No newline at end of file diff --git a/assets/js/invenio_app_rdm/overridableRegistry/user_dashboard/uploads_items/ComputerTabletUploadsItem.jsx b/assets/js/invenio_app_rdm/overridableRegistry/user_dashboard/uploads_items/ComputerTabletUploadsItem.jsx new file mode 100644 index 00000000..cda43e54 --- /dev/null +++ b/assets/js/invenio_app_rdm/overridableRegistry/user_dashboard/uploads_items/ComputerTabletUploadsItem.jsx @@ -0,0 +1,173 @@ +/* +* This file is part of Knowledge Commons Works. +* Copyright (C) 2024 Mesh Research. +* +* Knowledge Commons Works is based on InvenioRDM, and +* this file is based on code from InvenioRDM. InvenioRDM is +* Copyright (C) 2020-2024 CERN. +* Copyright (C) 2020-2024 Northwestern University. +* Copyright (C) 2020-2024 T U Wien. +* +* InvenioRDM and Knowledge Commons Works are both free software; +* you can redistribute and/or modify them under the terms of the +* MIT License; see LICENSE file for more details. +*/ + +import { i18next } from "@translations/invenio_app_rdm/i18next"; +import React from "react"; +import PropTypes from "prop-types"; +import _truncate from "lodash/truncate"; +import _get from "lodash/get"; +import { Button, Grid, Icon, Item, Label } from "semantic-ui-react"; +import { SearchItemCreators } from "@js/invenio_app_rdm/utils"; +import { CompactStats } from "../../search/records_list_item_components/CompactStats"; +import { DisplayPartOfCommunities } from "../../search/records_list_item_components/DisplayPartOfCommunities"; + +const ComputerTabletUploadsItem = ({ + result, + editRecord, + statuses, + access, + uiMetadata, +}) => { + const { accessStatusId, accessStatus, accessStatusIcon } = access; + const { + descriptionStripped, + title, + creators, + subjects, + publicationDate, + resourceType, + createdDate, + version, + versions, + isPublished, + viewLink, + publishingInformation, + filters, + allVersionsVisible, + numOtherVersions, + } = uiMetadata; + + const icon = isPublished ? ( + + ) : ( + + ); + const uniqueViews = _get(result, "stats.all_versions.unique_views", 0); + const uniqueDownloads = _get(result, "stats.all_versions.unique_downloads", 0); + + return ( + + {/*
+ +
{icon}
+
+
*/} + + {/* FIXME: Uncomment to enable themed banner */} + {/* */} + + {result.status in statuses && ( + + )} + + {icon} + +