Skip to content

Commit

Permalink
🐛 Fix show features/feature query results when layer is editable and …
Browse files Browse the repository at this point in the history
…check async editing config
  • Loading branch information
volterra79 committed Nov 21, 2024
1 parent dd95ce7 commit 7a8d5ca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/index.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ g3wsdk.gui.GUI.once('ready', () => {
});
});

window.GUI = g3wsdk.gui.GUI,
window.GUI = g3wsdk.gui.GUI;
window.localforage = localforage;
1 change: 1 addition & 0 deletions src/map/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,7 @@ class Layer extends G3WObject {
*/
setEditingLayer(editingLayer) {
this._editingLayer = editingLayer;
this.emit('set-editing-config', editingLayer.config.editing);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/map/layers/tablelayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class TableLayer extends Layer {

await waitFor(() => window.g3wsdk.core.hasOwnProperty('editing'), TIMEOUT); // wait until "editing" plugin is loaded
// add editing configurations
this.config.editing = {

this.config.editing = {
fields: vector.fields || [],
format: vector.format,
constraints,
Expand All @@ -127,7 +128,9 @@ export class TableLayer extends Layer {
style: vector.style, // get vector layer style
geometrytype: vector.geometrytype, // whether is a vector layer,
visible: (vector.editing || { visible: true }).visible, //@since 3.11.0 let know if layer should be editable directly (true) or through relation layer (false)
}
};

this.emit('set-editing-config', this.config.editing);

if (vector.style) { // set vector layer color
this.setColor(vector.style.color);
Expand Down
4 changes: 2 additions & 2 deletions src/services/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,15 @@ export default new (class GUI extends G3WObject {
});
}

const show = !stop && 'function' === typeof output.condition ? output.condition(data) : false !== output.condition;
const show = !stop && 'function' === typeof output.condition ? await output.condition(data) : false !== output.condition;

// check if data can be shown on query result content
if (!stop && show) {
(this.getService('queryresults') || this.showQueryResults(output.title || '')).setQueryResponse(data, { add: output.add });
}

if (!stop && !show) {
this.pending_output = this.closeContent.bind(this);
this.pending_output = await this.closeContent();
}

// call after is set with data
Expand Down
19 changes: 15 additions & 4 deletions src/services/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,16 +1067,21 @@ class MapService extends G3WObject {
return;
}

const layer = this.project.getLayerById(layerId);

const { data = [] } = await DataRouterService.getData('search:fids', {
inputs: {
layer: this.project.getLayerById(layerId),
layer,
fids: [fid]
},
outputs: {
show: {
loading: false,
condition({ data = [] } = {}) {
return data[0] && data[0].features.length > 0;
async condition({ data = [] } = {}) {
if (layer.isEditable() && undefined === layer.config.editing) {
await new Promise(resolve => layer.once('set-editing-config', resolve));
}
return !!(data[0] && data[0].features.length > 0);
}
}
}
Expand Down Expand Up @@ -1118,7 +1123,13 @@ class MapService extends G3WObject {
},
outputs: {
show: {
loading: false
loading: false,
async condition({ data = [] } = {}) {
if (layer.isEditable() && undefined === layer.config.editing) {
await new Promise(resolve => layer.once('set-editing-config', resolve));
}
return !!(data[0] && data[0].features.length > 0);
}
}
}
});
Expand Down

0 comments on commit 7a8d5ca

Please sign in to comment.