Skip to content

Commit 69c8ff5

Browse files
committed
Entity selector: Fixed initial load overwriting initial search
This changes how initial searches can be handled via config rather than specific action so they can be considered in how the initial data load is done, to prevent the default empty state loading and overwriting the search data if it lands later (which was commonly likely). For #4778
1 parent 788327f commit 69c8ff5

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

resources/js/components/entity-selector-popup.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@ export class EntitySelectorPopup extends Component {
1818
/**
1919
* Show the selector popup.
2020
* @param {Function} callback
21-
* @param {String} searchText
2221
* @param {EntitySelectorSearchOptions} searchOptions
2322
*/
24-
show(callback, searchText = '', searchOptions = {}) {
23+
show(callback, searchOptions = {}) {
2524
this.callback = callback;
2625
this.getSelector().configureSearchOptions(searchOptions);
2726
this.getPopup().show();
2827

29-
if (searchText) {
30-
this.getSelector().searchText(searchText);
31-
}
32-
3328
this.getSelector().focusSearch();
3429
}
3530

resources/js/components/entity-selector.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Component} from './component';
66
* @property entityTypes string
77
* @property entityPermission string
88
* @property searchEndpoint string
9+
* @property initialValue string
910
*/
1011

1112
/**
@@ -25,6 +26,7 @@ export class EntitySelector extends Component {
2526
entityTypes: this.$opts.entityTypes || 'page,book,chapter',
2627
entityPermission: this.$opts.entityPermission || 'view',
2728
searchEndpoint: this.$opts.searchEndpoint || '',
29+
initialValue: this.searchInput.value || '',
2830
};
2931

3032
this.search = '';
@@ -44,6 +46,7 @@ export class EntitySelector extends Component {
4446
configureSearchOptions(options) {
4547
Object.assign(this.searchOptions, options);
4648
this.reset();
49+
this.searchInput.value = this.searchOptions.initialValue;
4750
}
4851

4952
setupListeners() {
@@ -108,11 +111,6 @@ export class EntitySelector extends Component {
108111
this.searchInput.focus();
109112
}
110113

111-
searchText(queryText) {
112-
this.searchInput.value = queryText;
113-
this.searchEntities(queryText);
114-
}
115-
116114
showLoading() {
117115
this.loading.style.display = 'block';
118116
this.resultsContainer.style.display = 'none';
@@ -128,6 +126,11 @@ export class EntitySelector extends Component {
128126
throw new Error('Search endpoint not set for entity-selector load');
129127
}
130128

129+
if (this.searchOptions.initialValue) {
130+
this.searchEntities(this.searchOptions.initialValue);
131+
return;
132+
}
133+
131134
window.$http.get(this.searchUrl()).then(resp => {
132135
this.resultsContainer.innerHTML = resp.data;
133136
this.hideLoading();

resources/js/components/page-picker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export class PagePicker extends Component {
3535
const selectorPopup = window.$components.first('entity-selector-popup');
3636
selectorPopup.show(entity => {
3737
this.setValue(entity.id, entity.name);
38-
}, '', {
38+
}, {
39+
initialValue: '',
3940
searchEndpoint: this.selectorEndpoint,
4041
entityTypes: 'page',
4142
entityPermission: 'view',

resources/js/markdown/actions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export class Actions {
7373
const selectedText = selectionText || entity.name;
7474
const newText = `[${selectedText}](${entity.link})`;
7575
this.#replaceSelection(newText, newText.length, selectionRange);
76-
}, selectionText, {
76+
}, {
77+
initialValue: selectionText,
7778
searchEndpoint: '/search/entity-selector',
7879
entityTypes: 'page,book,chapter,bookshelf',
7980
entityPermission: 'view',

resources/js/wysiwyg/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ function filePickerCallback(callback, value, meta) {
8585
text: entity.name,
8686
title: entity.name,
8787
});
88-
}, selectionText, {
88+
}, {
89+
initialValue: selectionText,
8990
searchEndpoint: '/search/entity-selector',
9091
entityTypes: 'page,book,chapter,bookshelf',
9192
entityPermission: 'view',

resources/js/wysiwyg/shortcuts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export function register(editor) {
5858

5959
editor.selection.collapse(false);
6060
editor.focus();
61-
}, selectionText, {
61+
}, {
62+
initialValue: selectionText,
6263
searchEndpoint: '/search/entity-selector',
6364
entityTypes: 'page,book,chapter,bookshelf',
6465
entityPermission: 'view',

0 commit comments

Comments
 (0)