Consistently use edit_url in the state representation of choosers

Previously we were using edit_link in dicts handled by JS, and edit_url in dicts handled by Python, meaning that ChooserBlock.get_form_state had to rewrite it
pull/8934/head
Matt Westcott 2022-07-06 23:15:36 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 0077183682
commit 90e91e0e4a
8 zmienionych plików z 13 dodań i 13 usunięć

Wyświetl plik

@ -4,7 +4,7 @@ export class Chooser {
modalOnloadHandlers = chooserModalOnloadHandlers; modalOnloadHandlers = chooserModalOnloadHandlers;
titleStateKey = 'title'; // key used in the 'state' dictionary to hold the human-readable title titleStateKey = 'title'; // key used in the 'state' dictionary to hold the human-readable title
editLinkStateKey = 'edit_link'; // key used in the 'state' dictionary to hold the URL of the edit page editUrlStateKey = 'edit_url'; // key used in the 'state' dictionary to hold the URL of the edit page
chosenResponseName = 'chosen'; // identifier for the ModalWorkflow response that indicates an item was chosen chosenResponseName = 'chosen'; // identifier for the ModalWorkflow response that indicates an item was chosen
constructor(id) { constructor(id) {
@ -34,7 +34,7 @@ export class Chooser {
getStateFromHTML() { getStateFromHTML() {
/* /*
Construct initial state of the chooser from the rendered (static) HTML. Construct initial state of the chooser from the rendered (static) HTML.
State is either null (= no item chosen) or a dict of id, title and edit_link. State is either null (= no item chosen) or a dict of id, title and edit_url.
The result returned from the chooser modal (see get_chosen_response_data in The result returned from the chooser modal (see get_chosen_response_data in
wagtail.admin.views.generic.chooser.ChosenView) is a superset of this, and can therefore be wagtail.admin.views.generic.chooser.ChosenView) is a superset of this, and can therefore be
@ -47,8 +47,8 @@ export class Chooser {
if (this.titleElement && this.titleStateKey) { if (this.titleElement && this.titleStateKey) {
state[this.titleStateKey] = this.titleElement.textContent; state[this.titleStateKey] = this.titleElement.textContent;
} }
if (this.editLink && this.editLinkStateKey) { if (this.editLink && this.editUrlStateKey) {
state[this.editLinkStateKey] = this.editLink.getAttribute('href'); state[this.editUrlStateKey] = this.editLink.getAttribute('href');
} }
return state; return state;
} else { } else {
@ -89,7 +89,7 @@ export class Chooser {
} }
this.chooserElement.classList.remove('blank'); this.chooserElement.classList.remove('blank');
if (this.editLink) { if (this.editLink) {
const editUrl = newState[this.editLinkStateKey]; const editUrl = newState[this.editUrlStateKey];
if (editUrl) { if (editUrl) {
this.editLink.setAttribute('href', editUrl); this.editLink.setAttribute('href', editUrl);
this.editLink.classList.remove('u-hidden'); this.editLink.classList.remove('u-hidden');

Wyświetl plik

@ -156,7 +156,7 @@ describe('ModalWorkflowSource', () => {
title: 'Test', title: 'Test',
alt: 'Test', alt: 'Test',
class: 'richtext-image right', class: 'richtext-image right',
edit_link: '/admin/images/53/', edit_url: '/admin/images/53/',
format: 'right', format: 'right',
preview: { preview: {
url: '/media/images/test.width-500.jpg', url: '/media/images/test.width-500.jpg',
@ -183,7 +183,7 @@ describe('ModalWorkflowSource', () => {
it('DOCUMENT', () => { it('DOCUMENT', () => {
expect( expect(
documentSource.filterEntityData({ documentSource.filterEntityData({
edit_link: '/admin/documents/edit/1/', edit_url: '/admin/documents/edit/1/',
filename: 'test.pdf', filename: 'test.pdf',
id: 1, id: 1,
title: 'Test', title: 'Test',

Wyświetl plik

@ -4,7 +4,7 @@ class PageChooser extends Chooser {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
modalOnloadHandlers = PAGE_CHOOSER_MODAL_ONLOAD_HANDLERS; modalOnloadHandlers = PAGE_CHOOSER_MODAL_ONLOAD_HANDLERS;
titleStateKey = 'adminTitle'; titleStateKey = 'adminTitle';
editLinkStateKey = 'editUrl'; editUrlStateKey = 'editUrl';
chosenResponseName = 'pageChosen'; chosenResponseName = 'pageChosen';
constructor(id, parentId, options) { constructor(id, parentId, options) {

Wyświetl plik

@ -12,7 +12,7 @@ class ImageChooser extends Chooser {
getStateFromHTML() { getStateFromHTML() {
/* /*
Construct initial state of the chooser from the rendered (static) HTML. Construct initial state of the chooser from the rendered (static) HTML.
State is either null (= no image chosen) or a dict of id, edit_link, title State is either null (= no image chosen) or a dict of id, edit_url, title
and preview (= a dict of url, width, height). and preview (= a dict of url, width, height).
*/ */
const state = super.getStateFromHTML(); const state = super.getStateFromHTML();

Wyświetl plik

@ -347,7 +347,7 @@ class ChosenResponseMixin:
return { return {
"id": str(self.get_object_id(item)), "id": str(self.get_object_id(item)),
self.response_data_title_key: self.get_display_title(item), self.response_data_title_key: self.get_display_title(item),
"edit_link": self.get_edit_item_url(item), "edit_url": self.get_edit_item_url(item),
} }
def get_chosen_response(self, item): def get_chosen_response(self, item):

Wyświetl plik

@ -24,7 +24,7 @@ class DocumentChooserBlock(ChooserBlock):
else: else:
return { return {
"id": value_data["id"], "id": value_data["id"],
"edit_link": value_data["edit_url"], "edit_url": value_data["edit_url"],
"title": value_data["title"], "title": value_data["title"],
} }

Wyświetl plik

@ -27,7 +27,7 @@ class ImageChooserBlock(ChooserBlock):
else: else:
return { return {
"id": value_data["id"], "id": value_data["id"],
"edit_link": value_data["edit_url"], "edit_url": value_data["edit_url"],
"title": value_data["title"], "title": value_data["title"],
"preview": value_data["preview"], "preview": value_data["preview"],
} }

Wyświetl plik

@ -26,7 +26,7 @@ class SnippetChooserBlock(ChooserBlock):
else: else:
return { return {
"id": value_data["id"], "id": value_data["id"],
"edit_link": value_data["edit_url"], "edit_url": value_data["edit_url"],
"string": value_data["string"], "string": value_data["string"],
} }