-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dashboard): Fixed dashboard edit and view links for drafts
- Loading branch information
1 parent
4a9004a
commit 535b0b2
Showing
3 changed files
with
286 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
assets/js/invenio_app_rdm/overridableRegistry/search/RecordsResultsListItemDashboard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<ComputerTabletUploadsItem | ||
result={result} | ||
editRecord={editRecord} | ||
statuses={statuses} | ||
access={access} | ||
uiMetadata={uiMetadata} | ||
/> | ||
); | ||
}; | ||
|
||
RecordResultsListItemDashboard.propTypes = { | ||
result: PropTypes.object.isRequired, | ||
}; | ||
|
||
export { RecordResultsListItemDashboard }; |
173 changes: 173 additions & 0 deletions
173
...io_app_rdm/overridableRegistry/user_dashboard/uploads_items/ComputerTabletUploadsItem.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ? ( | ||
<Icon name="check" className="positive" /> | ||
) : ( | ||
<Icon name="upload" className="negative" /> | ||
); | ||
const uniqueViews = _get(result, "stats.all_versions.unique_views", 0); | ||
const uniqueDownloads = _get(result, "stats.all_versions.unique_downloads", 0); | ||
|
||
return ( | ||
<Item key={result.id} className="search-result flex"> | ||
{/* <div className="status-icon mr-10"> | ||
<Item.Content verticalAlign="top"> | ||
<div className="status-icon mt-5">{icon}</div> | ||
</Item.Content> | ||
</div> */} | ||
<Item.Content> | ||
{/* FIXME: Uncomment to enable themed banner */} | ||
{/* <DisplayVerifiedCommunity communities={result.parent?.communities} /> */} | ||
<Item.Extra className="labels-actions"> | ||
{result.status in statuses && ( | ||
<Label horizontal size="small" icon={icon} className={statuses[result.status].color}> | ||
{statuses[result.status].title} | ||
</Label> | ||
)} | ||
<span className="status-icon ml-5 mt-5"> | ||
{icon} | ||
</span> | ||
<Button | ||
compact | ||
size="small" | ||
floated="right" | ||
onClick={() => editRecord()} | ||
labelPosition="left" | ||
icon="edit" | ||
content={i18next.t("Edit")} | ||
/> | ||
</Item.Extra> | ||
<Item.Header as="h2"> | ||
<a href={viewLink}>{title}</a> | ||
</Item.Header> | ||
<Item className="creatibutors"> | ||
<Icon name={`${creators.length === 1 ? "user" : "users"}`} /> <SearchItemCreators creators={creators} othersLink={viewLink} /> | ||
</Item> | ||
<Item.Description> | ||
{_truncate(descriptionStripped, { length: 350 })} | ||
</Item.Description> | ||
<Item.Extra className="item-footer ui grid"> | ||
<Grid.Column mobile={16} tablet={11} computer={11} className="item-footer-left"> | ||
{subjects.map((subject) => ( | ||
<Label key={subject.title_l10n} size="tiny"> | ||
{subject.title_l10n} | ||
</Label> | ||
))} | ||
<p> | ||
<Label horizontal size="small" className=""> | ||
{publicationDate} ({version}) | ||
</Label> | ||
<Label horizontal size="small" className=""> | ||
{resourceType} | ||
</Label> | ||
<Label | ||
horizontal | ||
size="small" | ||
className={`basic access-status ${accessStatusId}`} | ||
> | ||
{accessStatusIcon && <Icon name={accessStatusIcon} />} | ||
{accessStatus} | ||
</Label> | ||
{/* {createdDate && publishingInformation && " | "} */} | ||
</p> | ||
|
||
{publishingInformation && ( | ||
<p> | ||
{i18next.t("Published in: {{publishInfo}}", { | ||
publishInfo: publishingInformation, | ||
})} | ||
</p> | ||
)} | ||
|
||
{!allVersionsVisible && versions.index > 1 && ( | ||
<p> | ||
<b> | ||
{i18next.t("{{count}} more versions exist for this record", { | ||
count: numOtherVersions, | ||
})} | ||
</b> | ||
</p> | ||
)} | ||
|
||
<DisplayPartOfCommunities communities={result.parent?.communities} /> | ||
</Grid.Column> | ||
|
||
<Grid.Column mobile={16} tablet={5} computer={5} className="item-footer-right"> | ||
<small> | ||
<CompactStats | ||
uniqueViews={uniqueViews} | ||
uniqueDownloads={uniqueDownloads} | ||
/> | ||
</small> | ||
{createdDate && ( | ||
<small className="created-date"> | ||
{i18next.t("Uploaded on {{uploadDate}}", { | ||
uploadDate: createdDate, | ||
})} | ||
</small> | ||
)} | ||
</Grid.Column> | ||
</Item.Extra> | ||
</Item.Content> | ||
</Item> | ||
); | ||
}; | ||
|
||
ComputerTabletUploadsItem.propTypes = { | ||
result: PropTypes.object.isRequired, | ||
editRecord: PropTypes.func.isRequired, | ||
statuses: PropTypes.object.isRequired, | ||
access: PropTypes.object.isRequired, | ||
uiMetadata: PropTypes.object.isRequired, | ||
}; | ||
|
||
export { ComputerTabletUploadsItem }; |