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

Assign entry.field from query response in infoj #1034

Merged
merged 3 commits into from
Dec 13, 2023

Conversation

dbauszus-glx
Copy link
Member

No description provided.

@dbauszus-glx dbauszus-glx added the Bug A genuine bug. There must be some form of error exception to work with. label Dec 11, 2023
Copy link
Contributor

@simon-leech simon-leech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbauszus-glx Thanks for this - a simpler implementation than #1031 .
However, this implementation isn't quite right.
The issue with the implementation below is that this assumes all infoj entries with query also contain queryCheck:true, but this is not the case for the infoj entry containing just a query and a field, as there's no benefit to having queryCheck:true as this is used to disabled checkboxes if no data is provided.

  if (entry.query) {

      // Assign queryparams from layer, and locale.
      entry.queryparams = Object.assign(
        entry.queryparams || {},
        entry.location.layer.queryparams || {},
        entry.location.layer.mapview.locale.queryparams || {})

      // Check whether query returns data.
      if (entry.queryCheck || entry.run === true) {

        // Stringify paramString from object.
        const paramString = mapp.utils.paramString(mapp.utils.queryParams(entry))

        // Run the entry query.
        mapp.utils
          .xhr(`${entry.host || entry.location.layer.mapview.host}/api/query?${paramString}`)
          .then(response => {

            // Assign query response as entry value.
            entry.value = entry.field? response[entry.field] :response;

            // Check whether entry should be skipped.
            if (skipEntry(entry)) {

              // Remove the entry.node from location view.
              entry.node.remove();
              return;
            }

            // Create element to be appended into empty entry.node
            const el = mapp.ui.locations.entries[entry.type]?.(entry)

            el && entry.node.append(el)
          })

        continue;
      }

    }

@dbauszus-glx
Copy link
Member Author

@simon-leech That is correct. Only queries with the run or queryChecks flag will be executed in the infoj iteration.

Copy link

sonarcloud bot commented Dec 12, 2023

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@simon-leech simon-leech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbauszus-glx
I just did a commit to update the console warning to explain how to resolve this warning too.
All working for me happy to merge!

@RobAndrewHurst RobAndrewHurst merged commit c8164be into main Dec 13, 2023
5 checks passed
@RobAndrewHurst RobAndrewHurst deleted the entry-field-query-response branch January 25, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A genuine bug. There must be some form of error exception to work with.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants