Skip to content

Commit

Permalink
using dropdown for new version keep files field
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducica committed Dec 11, 2024
1 parent 358408a commit 5d14423
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 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 @@ -47,7 +47,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)
update_topic(self.request, topic, new_version_topic._record, uow)
Expand Down
16 changes: 10 additions & 6 deletions oarepo_requests/types/new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ class NewVersionRequestType(NonDuplicableOARepoRequestType):
attribute="draft_record:links:self_html",
data_key="draft_record:links:self_html",
),
"keep_files": ma.fields.String(validate=OneOf(["true", "false"])),
"keep_files": ma.fields.String(validate=OneOf(["yes", "no"])),
}

def extra_entity_links(self, request: Request, entity: dict, entity_type: str, **kwargs) -> dict:
def extra_entity_links(
self, request: Request, entity: dict, entity_type: str, **kwargs
) -> dict:
if request.status == "accepted" and entity_type == "topic":
return {"topic_redirect_link": entity["links"]["edit_html"]}
else:
Expand All @@ -70,15 +72,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 @@ -250,16 +250,15 @@ export const useAction = ({
requestActionName,
});
}
const redirectionURL = data?.data?.links?.redirect_urls?.self_html;
console.log(data.data);
const redirectionURL = 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/";
window.location.href = "/me/records/";
// fetchNewRequests?.();
}
},
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?.topic?.edit_html) {
requestModalFormik?.setFieldError(
if (record?.links?.edit_html) {
formik?.setFieldError(
"api",
i18next.t("Record has validation errors. Redirecting to form...")
);
setTimeout(() => {
window.location.href =
record.links.topic.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
2 changes: 1 addition & 1 deletion tests/test_requests/test_new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_new_version_files(
urls["BASE_URL_REQUESTS"],
json={
**new_version_data_function(record1["id"]),
"payload": {"keep_files": "true"},
"payload": {"keep_files": "yes"},
},
)
resp_request_create2 = creator_client.post(
Expand Down

0 comments on commit 5d14423

Please sign in to comment.