Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override ResourceGrid config via overrideLocalConfig has only effect for non-paged views #1916

Open
ridoo opened this issue Dec 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ridoo
Copy link

ridoo commented Dec 4, 2024

Describe the bug

Making config changes, e.g. adding a new entry to the "Add Resource" menu, via overrideLocalConfig does not work for the root route /. It only works for paged views like /catalogue.

For the given example (adding menu entry to ResourceGrid config), the parameters menuItems and filterFormItems are not available for override. These are not yet set in the overrideLocalConfig as these are set later on ResourceGrid creation (as default function parameters). One would have to provide the whole arrays (see this example) in the _geonode_config.html instead of patching existing config.

Expected Behavior

On startup, GeoNode reads and sets overridden configuration declared in _geonode_config.html as documented.

Steps to Reproduce the Problem

  1. Create a fake menu to CARDS_MENU placeholder
  2. Add an override to _geonode_config.html:
 window.__GEONODE_CONFIG__.overrideLocalConfig = function(localConfig, _) {
     
     Object.keys(localConfig.plugins).forEach((pageName) => {
         localConfig.plugins[pageName].forEach((plugin) => {
             if (['ResourcesGrid'].includes(plugin.name) && plugin.cfg && plugin.cfg.datasetsPage) {
                 plugin.cfg.enableGeoNodeCardsMenuItems = false;
             }
         })
     });
 }
  1. Start with /catalogue --> the menu is not there (expected)
  2. Start with / --> the menu is visible (overridden config not applied)

Specifications

  • GeoNode client version: v4.4.x (but older version had the same behaviour)
  • Browser:
  • Installation type (vanilla, geonode-project):
  • Additional details:

Configuration overrides are read and applied only from the last configured contrib module. However, this can be addressed by updating the documentation (and existing config overrides) as described in my comment on a geonode-subsites PR:

{% extends 'geonode-mapstore-client/_geonode_config.html' %}
{% block override_local_config %}

{% comment %} Keep the overrides from other apps {% endcomment %}
{{ block.super }}

<script>
const { overrideLocalConfig } = window.__GEONODE_CONFIG__;
window.__GEONODE_CONFIG__.overrideLocalConfig = function(localConfig, _) {

    if (overrideLocalConfig) {
        overrideLocalConfig(localConfig, _)
    }


    // do actual override

    return localConfig;

}

</script>
{% endblock %}

EDIT: It is necessary to wrap the above as IIFE to encapsulate the overrideLocalConfig variable as multiple overrides may appear in the html, i.e. do

<script>
(function() {
  const { overrideLocalConfig } = window.__GEONODE_CONFIG__;
  // ...
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant