Skip to content

Commit

Permalink
Merge pull request #2775 from okauppinen/metadata-stateful
Browse files Browse the repository at this point in the history
Metadata stateful
  • Loading branch information
ZakarFin authored Jan 20, 2025
2 parents 38fee7c + 7220ad8 commit fd4aa01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bundles/catalogue/metadata/handler/MetadataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class MetadataHandler extends StateHandler {
this.setState({
activeTab: 'basic',
loading: false,
current: null, // { uuid, layerId }
layers: [],
showFullGraphics: false,
metadata: {},
Expand Down Expand Up @@ -46,6 +47,10 @@ class MetadataHandler extends StateHandler {
this.updateState({ layers: layers.map(layer => layer.layerId === layerId ? { ...layer, isVisible, isSelected } : layer) });
}

onFlyoutClose () {
this.updateState({ current: null });
}

fetchMetadata ({ layerId, uuid }) {
// clear previous
this.updateState({ loading: true, metadata: {}, identifications: [], layers: [] });
Expand All @@ -66,7 +71,8 @@ class MetadataHandler extends StateHandler {
}).then(json => {
const { metadata, identifications } = mapResponseForRender(json);
const layers = this._getLayers(uuid, layerId, metadata.fileIdentifier);
this.updateState({ loading: false, metadata, layers, identifications });
const current = { layerId, uuid: uuid || metadata.fileIdentifier };
this.updateState({ loading: false, current, metadata, layers, identifications });
}).catch(error => {
this.updateState({ loading: false });
Oskari.log('MetadataHandler').error(error);
Expand Down
16 changes: 16 additions & 0 deletions bundles/catalogue/metadata/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Oskari.clazz.define('Oskari.catalogue.bundle.metadata.MetadataBundleInstance',
const metadata = Array.isArray(current) ? current[0] : current;
this.showMetadata(metadata);
}
this.sandbox.registerAsStateful(this.mediator.bundleId, this);
},
/**
* Fetches reference to the map layer service
Expand Down Expand Up @@ -160,12 +161,27 @@ Oskari.clazz.define('Oskari.catalogue.bundle.metadata.MetadataBundleInstance',
if (this.flyoutControls) {
this.flyoutControls.close();
}
this.handler.onFlyoutClose();
this.flyoutControls = null;
},
onStateUpdate: function (state) {
if (this.flyoutControls) {
this.flyoutControls.update(state);
}
},
getState: function () {
const { current } = this.handler.getState();
if (!current) {
return {};
}
return { current: [current] };
},
getStateParameters: function () {
const { uuid } = this.handler.getState().current || {};
if (!uuid) {
return '';
}
return `metadata=${uuid}`;
}
}, {
protocol: [
Expand Down

0 comments on commit fd4aa01

Please sign in to comment.