Skip to content

Commit

Permalink
Merge pull request #98 from oarepo/stojanovic/fe-307-the-link-structu…
Browse files Browse the repository at this point in the history
…re-change-oarepo-requests

Stojanovic/fe 307 the link structure change oarepo requests
  • Loading branch information
mirekys authored Dec 12, 2024
2 parents 82f7c4e + 577ff23 commit 0b63417
Show file tree
Hide file tree
Showing 23 changed files with 213 additions and 186 deletions.
2 changes: 1 addition & 1 deletion oarepo_requests/actions/new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def apply(
if (
"payload" in self.request
and "keep_files" in self.request["payload"]
and self.request["payload"]["keep_files"] == "true"
and self.request["payload"]["keep_files"] == "yes"
):
topic_service.import_files(identity, new_version_topic.id)

Expand Down
Binary file modified oarepo_requests/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions oarepo_requests/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,7 @@ msgstr ""
#: /home/ron/prace/oarepo-requests/oarepo_requests/types/publish_draft.py:124
msgid "Missing uploaded files."
msgstr "Chybí nahrané soubory."

#: /home/dusanst/Projects/oarepo-requests/oarepo_requests/types/new_version.py:78
msgid "Yes or no"
msgstr "Ano nebo ne"
Binary file modified oarepo_requests/translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions oarepo_requests/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -710,5 +710,9 @@ msgstr ""
msgid "Missing uploaded files."
msgstr ""

#: /home/dusanst/Projects/oarepo-requests/oarepo_requests/types/new_version.py:78
msgid "Yes or no"
msgstr ""

#~ msgid "No status"
#~ msgstr ""
Binary file modified oarepo_requests/translations/messages.mo
Binary file not shown.
252 changes: 126 additions & 126 deletions oarepo_requests/translations/messages.pot

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions oarepo_requests/types/new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NewVersionRequestType(NonDuplicableOARepoRequestType):
attribute="draft_record:id",
data_key="draft_record:id",
),
"keep_files": ma.fields.String(validate=OneOf(["true", "false"])),
"keep_files": ma.fields.String(validate=OneOf(["yes", "no"])),
}

def get_ui_redirect_url(self, request: Request, ctx: dict) -> str:
Expand Down Expand Up @@ -86,15 +86,17 @@ def available_actions(cls) -> dict[str, type[RequestAction]]:

form = {
"field": "keep_files",
"ui_widget": "BooleanCheckbox",
"ui_widget": "Dropdown",
"props": {
"label": _("Keep files:"),
"placeholder": _("Keep files in the new version?"),
"placeholder": _("Yes or no"),
"description": _(
"If you choose yes, the current record's files will be linked to the new version of the record. Then you will be able to add/remove files in the form."
),
"falseLabel": _("No"),
"trueLabel": _("Yes"),
"options": [
{"id": "yes", "title_l10n": _("Yes")},
{"id": "no", "title_l10n": _("No")},
],
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DirectCreateAndSubmit = ({
isLoading,
mutate: createAndSubmit,
isError,
error,
reset,
} = useAction({
action: saveAndSubmit,
Expand Down Expand Up @@ -69,9 +70,13 @@ const DirectCreateAndSubmit = ({
{isError && (
<Message negative>
<Message.Header>
{i18next.t(
"Request not created successfully. Please try again in a moment."
)}
{error?.response?.data?.errors?.length > 0
? i18next.t(
"Record has validation errors. Redirecting to form..."
)
: i18next.t(
"Request not created successfully. Please try again in a moment."
)}
</Message.Header>
</Message>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const RequestActionButton = ({
requestOrRequestType: requestOrRequestType,
formik,
modalControl,
requestActionName,
});

const handleClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const RequestCommentInput = ({
editorConfig={{
auto_focus: true,
min_height: 100,
width: "100%",
toolbar:
"blocks | bold italic | bullist numlist | outdent indent | undo redo",
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export const RequestModalContent = ({
{description && (
<Grid.Column as="p" id="request-modal-desc">
<span dangerouslySetInnerHTML={{ __html: sanitizedDescription }} />{" "}
<a
href={request?.links?.self_html}
target="_blank"
rel="noopener noreferrer"
>
({i18next.t("Request details")})
</a>
{request?.links?.self_html && (
<a
href={request.links.self_html}
target="_blank"
rel="noopener noreferrer"
>
({i18next.t("Request details")})
</a>
)}
</Grid.Column>
)}
</Grid.Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export const SideRequestInfo = ({ request }) => {
const statusIcon = getRequestStatusIcon(request?.status_code);
return (
<List horizontal relaxed divided size="small">
{request?.created_by &&
{request?.created_by && (
<List.Item>
<List.Header as="h3">{i18next.t("Creator")}</List.Header>
<List.Content>
<Icon name="user circle outline" />
<span>
{_has(request, "links.created_by_html") ? (
{_has(request, "links.created_by.self_html") ? (
<a
href={request.links.created_by_html}
href={request.links.created_by.self_html}
target="_blank"
rel="noreferrer"
>
Expand All @@ -30,16 +30,16 @@ export const SideRequestInfo = ({ request }) => {
</span>
</List.Content>
</List.Item>
}
{request?.receiver &&
)}
{request?.receiver && (
<List.Item>
<List.Header as="h3">{i18next.t("Receiver")}</List.Header>
<List.Content>
<Icon name="mail outline" />
<span>
{_has(request, "links.receiver_html") ? (
{_has(request, "links.receiver.self_html") ? (
<a
href={request.links.receiver_html}
href={request.links.receiver.self_html}
target="_blank"
rel="noreferrer"
>
Expand All @@ -51,7 +51,7 @@ export const SideRequestInfo = ({ request }) => {
</span>
</List.Content>
</List.Item>
}
)}
<List.Item>
<List.Header as="h3">{i18next.t("Status")}</List.Header>
<List.Content>
Expand All @@ -65,15 +65,19 @@ export const SideRequestInfo = ({ request }) => {
<List.Header as="h3">{i18next.t("Created")}</List.Header>
<List.Content>{request.created}</List.Content>
</List.Item>
{request?.links?.topic_html && (
{request?.links?.topic?.self_html && (
<List.Item>
<List.Header as="h3">{i18next.t("Topic")}</List.Header>
<List.Content>
<a href={request.links.topic_html} target="_blank" rel="noreferrer">
<a
href={request.links.topic.self_html}
target="_blank"
rel="noreferrer"
>
{request?.topic?.label
? _truncate(request?.topic?.label, {
length: 350,
})
length: 350,
})
: i18next.t("Request topic")}
</a>
</List.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { toRelativeTime, Image } from "react-invenio-forms";

export const TimelineActionEvent = ({ event }) => {
const createdBy = event?.expanded?.created_by;
const creatorLabel = createdBy?.username || createdBy?.email;
const creatorLabel =
createdBy?.profile?.full_name || createdBy?.username || createdBy?.email;
const eventIcon = getRequestStatusIcon(event.payload.event);
const feedMessage = getFeedMessage(event.payload.event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { httpApplicationJson } from "@js/oarepo_ui";

const TimelineCommentEvent = ({ event, requestId, page }) => {
const createdBy = event?.expanded?.created_by;
const creatorLabel = createdBy?.username || createdBy?.email;
const creatorLabel =
createdBy?.profile?.full_name || createdBy?.username || createdBy?.email;
const [editMode, setEditMode] = useState(false);
const [deleteMode, setDeleteMode] = useState(false);
const [comment, setComment] = useState(event.payload.content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const TopicPreview = ({ request }) => {
)}
<iframe
ref={iframeRef}
src={request.topic.links.self_html + "?embed=true"}
src={request.links.topic.self_html + "?embed=true"}
onLoad={() => {
updateIframeHeight();
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,18 @@ export const useAction = ({
requestOrRequestType,
formik,
modalControl,
requestActionName,
} = {}) => {
const { onBeforeAction, onAfterAction, onActionError } = useCallbackContext();
return useMutation(
async (values) => {
if (onBeforeAction) {
const shouldProceed = await onBeforeAction(
const shouldProceed = await onBeforeAction({
formik,
modalControl,
requestOrRequestType
);
requestOrRequestType,
requestActionName,
});
if (!shouldProceed) {
modalControl?.closeModal();
throw new Error("Could not proceed with the action.");
Expand All @@ -207,13 +209,14 @@ export const useAction = ({
{
onError: (e, variables) => {
if (onActionError) {
onActionError(
onActionError({
e,
variables,
formik,
modalControl,
requestOrRequestType
);
requestOrRequestType,
requestActionName,
});
} else if (e?.response?.data?.errors) {
formik?.setFieldError(
"api",
Expand All @@ -238,24 +241,25 @@ export const useAction = ({
},
onSuccess: (data, variables) => {
if (onAfterAction) {
onAfterAction(
onAfterAction({
data,
variables,
formik,
modalControl,
requestOrRequestType
);
requestOrRequestType,
requestActionName,
});
}
const redirectionURL = data?.data?.links?.topic_html;
const redirectionURL =
data?.data?.links?.ui_redirect_url ||
data?.data?.links?.topic?.self_html;

modalControl?.closeModal();

if (redirectionURL) {
window.location.href = redirectionURL;
} else {
// TODO: some requests after they complete no longer have a topic_html,
// so redirecting to dashboard instead
window.location.href = "/me/records/";
// fetchNewRequests?.();
window.location.reload();
}
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ const recordRequestsAppDiv = document.getElementById("record-requests");
if (recordRequestsAppDiv) {
const record = JSON.parse(recordRequestsAppDiv.dataset.record);

const onActionError = (e, variables, requestModalFormik, modalControl) => {
const onActionError = ({ e, formik, modalControl }) => {
if (e?.response?.data?.errors) {
const errorData = e.response.data;
const jsonErrors = JSON.stringify(errorData);
const base64EncodedErrors = encodeUnicodeBase64(jsonErrors);
if (record?.links?.edit_html) {
requestModalFormik?.setFieldError(
formik?.setFieldError(
"api",
i18next.t("Record has validation errors. Redirecting to form...")
);
setTimeout(() => {
window.location.href =
record?.links?.edit_html + `#${base64EncodedErrors}`;
record.links.edit_html + `#${base64EncodedErrors}`;
modalControl?.closeModal();
}, 2500);
}
} else {
requestModalFormik?.setFieldError(
formik?.setFieldError(
"api",
i18next.t(
"The action could not be executed. Please try again in a moment."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const RequestDetail = ({
active={activeTab === "timeline"}
onClick={() => setActiveTab("timeline")}
/>
{request?.topic?.links?.self_html && (
{request?.links?.topic?.self_html && (
<Menu.Item
name="topic"
content={i18next.t("Record preview")}
Expand Down
Loading

0 comments on commit 0b63417

Please sign in to comment.