Skip to content

Commit

Permalink
access request: update guest request payload
Browse files Browse the repository at this point in the history
* add an overridable for the timeline header
* inject permissions prop
* closes inveniosoftware/invenio-rdm-records#1395
  • Loading branch information
anikachurilova committed Aug 10, 2023
1 parent db668ab commit b0971bb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export class InvenioRequestsApp extends Component {
}

render() {
const { overriddenCmps, userAvatar } = this.props;
const { overriddenCmps, userAvatar, permissions } = this.props;

return (
<OverridableContext.Provider value={overriddenCmps}>
<Provider store={this.store}>
<Request userAvatar={userAvatar} />
<Request userAvatar={userAvatar} permissions={permissions}/>
</Provider>
</OverridableContext.Provider>
);
Expand All @@ -57,6 +57,7 @@ InvenioRequestsApp.propTypes = {
request: PropTypes.object.isRequired,
userAvatar: PropTypes.string.isRequired,
defaultQueryParams: PropTypes.object,
permissions: PropTypes.object.isRequired,
};

InvenioRequestsApp.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Request extends Component {
}

render() {
const { request, updateRequestAfterAction, userAvatar } = this.props;
const { request, updateRequestAfterAction, userAvatar, permissions } = this.props;

return (
<Overridable id="InvenioRequest.Request.layout">
Expand All @@ -28,7 +28,7 @@ export class Request extends Component {
request={request}
actionSuccessCallback={updateRequestAfterAction}
/>
<RequestDetails request={request} userAvatar={userAvatar} />
<RequestDetails request={request} userAvatar={userAvatar} permissions={permissions}/>
</Loader>
</Overridable>
);
Expand All @@ -40,6 +40,7 @@ Request.propTypes = {
initRequest: PropTypes.func.isRequired,
updateRequestAfterAction: PropTypes.func.isRequired,
userAvatar: PropTypes.string,
permissions: PropTypes.object.isRequired,
};

Request.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { Timeline } from "../timeline";

class RequestDetails extends Component {
render() {
const { request, userAvatar } = this.props;
const { request, userAvatar, permissions } = this.props;
return (
<Overridable id="InvenioRequests.RequestDetails.layout" {...this.props}>
<>
<Grid stackable reversed="mobile">
<Grid.Column mobile={16} tablet={12} computer={13}>
<Timeline userAvatar={userAvatar} />
<Timeline userAvatar={userAvatar} request={request} permissions={permissions}/>
</Grid.Column>
<Grid.Column mobile={16} tablet={4} computer={3}>
<RequestMetadata request={request} />
Expand All @@ -34,6 +34,7 @@ class RequestDetails extends Component {
RequestDetails.propTypes = {
request: PropTypes.object.isRequired,
userAvatar: PropTypes.string,
permissions: PropTypes.object.isRequired,
};

RequestDetails.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ import {
LabelTypeCommunityInvitation,
LabelTypeCommunitySubmission,
} from "./contrib";
import { overrideStore } from "react-overridable";

const requestDetailsDiv = document.getElementById("request-detail");
const request = JSON.parse(requestDetailsDiv.dataset.record);
const defaultQueryParams = JSON.parse(requestDetailsDiv.dataset.defaultQueryConfig);
const userAvatar = JSON.parse(requestDetailsDiv.dataset.userAvatar);
const permissions = JSON.parse(requestDetailsDiv.dataset.permissions);

const overriddenComponents = {
"TimelineEvent.layout.unknown": TimelineUnknownEvent,
Expand Down Expand Up @@ -72,12 +74,17 @@ const overriddenComponents = {
"RequestActionModal.title.decline": () => i18next.t("Decline request"),
};

for (const [key, value] of Object.entries(overriddenComponents)) {
overrideStore.add(key, value);
}

ReactDOM.render(
<InvenioRequestsApp
request={request}
defaultQueryParams={defaultQueryParams}
overriddenCmps={overriddenComponents}
overriddenCmps={overrideStore.getAll()}
userAvatar={userAvatar}
permissions={permissions}
/>,
requestDetailsDiv
);
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ class TimelineFeed extends Component {
};

render() {
const { timeline, loading, error, setPage, size, page, userAvatar } = this.props;
const { timeline, loading, error, setPage, size, page, userAvatar, request, permissions } = this.props;
const { modalOpen, modalAction } = this.state;

return (
<Loader isLoading={loading}>
<Error error={error}>
<Overridable id="TimelineFeed.layout" {...this.props}>
<Container id="requests-timeline" className="ml-0-mobile mr-0-mobile">
<Overridable id="TimelineFeed.header" request={request} permissions={permissions}/>
<RequestsFeed>
{timeline.hits?.hits.map((event) => (
<TimelineCommentEventControlled
Expand Down Expand Up @@ -92,6 +93,8 @@ TimelineFeed.propTypes = {
page: PropTypes.number,
size: PropTypes.number,
userAvatar: PropTypes.string,
request: PropTypes.object.isRequired,
permissions: PropTypes.object.isRequired,
};

TimelineFeed.defaultProps = {
Expand Down
2 changes: 2 additions & 0 deletions invenio_requests/services/requests/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def update(self, identity, data=None, record=None, **kwargs):
if record.status == "created":
keys = ("title", "description", "payload", "receiver", "topic")
else:
# TODO: add possibility to update payload (https://github.com/inveniosoftware/invenio-rdm-records/issues/1402)
# keys = ("title", "description", "payload")
keys = ("title", "description")

for k in keys:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ <h2 class="ui header">
data-record='{{ invenio_request | tojson }}'
data-default-query-config='{{ dict(size=config["REQUESTS_TIMELINE_PAGE_SIZE"]) | tojson }}'
data-user-avatar='{{ user_avatar | tojson }}'
data-permissions='{{ permissions | tojson }}'
>{# react app root #}
<div class="ui grid">
<div class="stretched row">
Expand Down

0 comments on commit b0971bb

Please sign in to comment.