Uploaded image for project: 'CMS'
  1. CMS
  2. CMS-10123

[ScriptTool] [Refactor] Make it more clear the purpose of JS params "selection" and "model"

    • Icon: Task Task
    • Resolution: Fixed
    • Icon: Major Major
    • 4.3.0
    • 4.3.0
    • None
    • None
    • 4.3 M5

      While I was reading some code of Ametys.plugins.cms.search.ScriptTool, in line 316 there was:

      Ametys.data.ServerComm.callMethod({
          role: 'org.ametys.cms.scripts.CmsScriptHandler',
          methodName: 'executeScript',
          parameters: [{
              script: this._editor.getValue() || null,
              selection: this._convertedSelection || '',
              model: "search-ui.default"
          }],
      

      And I was wondering why we were passing "selection" and "model" parameters as in server code, org.ametys.plugins.core.ui.script.ScriptHandler.executeScript(Map<String, Object>) it does:

      return executeScript((String) arguments.get("script"));
      

      But in fact, it was used by CmsScriptHandler and CmsScriptBinding:

      String defaultModelId = Optional.ofNullable(_serverCommHelper.getJsParameters())
                                              .map(params -> params.get("parameters"))
                                              .map(List.class::cast)
                                              .map(list -> list.get(0))
                                              .map(Map.class::cast)
                                              .map(params -> (String) params.get("model"))
                                              .orElse(null);
      
      Map<String, Object> jsParameters = _serverCommHelper.getJsParameters();
      Collection<String> selection = Optional.ofNullable(jsParameters.getOrDefault("parameters", null))
                      .map(List.class::cast)
                      .map(l -> l.get(0))
                      .map(Map.class::cast)
                      .map(map -> (Collection<String>) map.getOrDefault(REQUEST_PARAM_SELECTION, null))
                      .orElse(null);
      

      I found it not very clear and explicit, using ServerCommHelper here is too invisible in my opinion.
      And I could have removed them if I did not try to know more.
      So the purpose of this issue is just to do a little refactor to make those kind of parameters them more clear, and visible by the compiler.

            Unassigned Unassigned
            sprieul Simon Prieul (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: