Skip to content

Commit

Permalink
🐛 Backport
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Dec 17, 2024
1 parent e3be670 commit c84a280
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/g3w-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import * as vueSearchComp from 'components/SearchPanel.vue';
*/
function _getSavedSearches() {
const ITEMS = ApplicationState.querybuilder.searches;
const id = ProjectsRegistry.getCurrentProject().getId();
ITEMS[id] = ITEMS[id] || [];
const id = ProjectsRegistry.getCurrentProject().getId();
ITEMS[id] = ITEMS[id] || [];
return ITEMS[id];
}

Expand Down Expand Up @@ -133,6 +133,8 @@ export function SearchPanel(opts = {}, show = false) {
/** keep a reference to initial search options (you shouldn't mutate them..) */
options: d.input.options,
})),
return: (opts.options || {}).return || 'data', //@since 3.11.0 considere type of search return. Can be another search or data
child: !!opts.child, //@since 3.11.0 Need to know if search is coming from another search
};

state.mounted = createInputsFormFromFilter(state);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createInputsFormFromFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function createInputsFormFromFilter(state) {
// set key-values for select
input.values = [
...('selectfield' === input.type ? [SEARCH_ALLVALUE] : []), // set `SEARCH_ALLVALUE` as first element
...(input.dependance_strict || has_autocomplete
...(input.dependance_strict || has_autocomplete || ('selectfield' === input.type && state.child)
? input.values
: await getDataForSearchInput({ state, field: input.attribute }) // retrieve input values from server
)
Expand Down
21 changes: 20 additions & 1 deletion src/utils/doSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ProjectsRegistry from 'store/projects';
import DataRouterService from 'services/data';
import GUI from 'services/gui';
import { createFilterFormInputs } from 'utils/createFilterFormInputs';
import { SearchPanel } from "components/g3w-search";

/**
* Perform search
Expand Down Expand Up @@ -41,11 +42,29 @@ export async function doSearch({
queryUrl,
formatter: 1,
feature_count,
raw: false // in order to get raw response
raw: 'search' === state.return, // in order to get a raw response
},
outputs: show && { title: state.title }
});

// Backport @since 3.11.0.
// In case of search return == 'search' options.return = 'search', it means that a new search panel needs to show
if ('search' === state.return) {
// in case of return, a structure of search
if (Object.keys((data.data[0] || {}).data || {}).length > 0) {
//need to eventually close an open result
await GUI.closeContent();
const opts = (data.data[0] || {}).data;
opts.child = true; //set child true
//and open a new Search panel
new SearchPanel(opts, true)
} else {
//otherwise, mean the return of search has no values, so we can show an empty results
DataRouterService.showEmptyOutputs();
data = [];
}
}

// auto zoom to query
if (show && ProjectsRegistry.getCurrentProject().state.autozoom_query && data && data.data && 1 === data.data.length) {
GUI.getService('map').zoomToFeatures(data.data[0].features);
Expand Down

0 comments on commit c84a280

Please sign in to comment.