Troubleshooting Query Param Problems in EmberJS Route Navigation

("ember-cli": "2.2.0-beta.6")

A search page on my website allows users to look for two different types of records: Users or Organizations.

The URL for this search page is /search and I have implemented query parameters to maintain the state and enable back/forward navigation within a web browser (keeping track of previous search terms).

This feature works well when searching for Users, but not for Organizations. When an organization is searched and the user presses the back button, they are redirected to a random route (sometimes even one that was never accessed and doesn't appear in the browsing history).

search/controller.js

export default Ember.Controller.extend({
  itemType: 'users',
  queryParams: [
    {
      searchString: {
        scope: 'controller',
        as: 'term'
      }
    }
  ],
  searchString: '',
  userColumns: [
    {
      'title': 'Name',
      'key': 'name',
      'type': 'function',
      'handler': (key, document) => {
        return document._source.firstname + ' ' + document._source.lastname;
      }
    },
    {
      'title': 'Email',
      'key': '_source.name',
      'type': 'string'
    },
    {
      'title': 'Date Registered',
      'key': '_source.created_at',
      'type': 'date'
    }
  ],
  roleColumns: [
    {
      'title': 'Name',
      'key': '_source.name',
      'type': 'string'
    },
    {
      'title': 'Email',
      'key': '_source.info.email',
      'type': 'string'
    },
    {
      'title': 'Date Registered',
      'key': '_source.created_at',
      'type': 'date'
    }
  ],
  linkToTarget: Ember.computed('itemType', function() {
    const itemType = this.get('itemType');
    return itemType === 'users' ? 'user' : 'organization';
  }),
  columnDefinitions: Ember.computed('itemType', function() {
    const itemType = this.get('itemType');
    return itemType === 'users' ? this.get('userColumns') : this.get('roleColumns');
  })
});

search/route.js

export default Ember.Route.extend(AuthenticatedRouteMixin, {
  queryParams: { searchString: { replace: true } },
  resetController(controller, isExiting) {
    if (isExiting) {
      controller.set('searchString', '');
    }
  }
});

search/template.hbs

{{#es-generic-search
    itemType=itemType
    searchString=searchString
    columnDefinitions=columnDefinitions
    as |section data|
}}

  {{#if (eq section 'searchForm')}}
    {{#bs-button-group value=itemType type="radio" size="xs"}}
      {{#bs-button value='users'}}Users{{/bs-button}}
      {{#bs-button value='roles'}}Organizations{{/bs-button}}
    {{/bs-button-group}}
  {{/if}}
    {{#if (eq section 'afterLastHeader')}}
        <th></th>
    {{/if}}
    {{#if (eq section 'afterLastColumn')}}
        <td>
            {{#link-to linkToTarget data._id}}
            <button class="btn btn-default btn-xs">
              <i class="fa fa-eye"></i>
            </button>
            {{/link-to}}
        </td>
    {{/if}}

{{/es-generic-search}}
{{outlet}}

es-generic-search is a component that executes an Elasticsearch query and then utilizes the columnDefinitions to present relevant information in a table format.

I initially had separate routes for Users and Organizations, but decided to consolidate them into a single view for better user experience. However, the same issue persists even with this change.

I am struggling to resolve this issue and would greatly appreciate any help provided!!

Answer №1

It seems like there may be a potential issue in your code involving the linkToTarget computed property in the search/controller.js file, where it toggles between 'users' and 'organisation'.

return itemType === 'users' ? 'user' : 'organisation';

However, in your search/template.hbs, you are passing the value of roles to the Organisations button.

{{#bs-button value='roles'}}Organisations{{/bs-button}}

Do you think there could be a mix-up somewhere else in your code with 'role' and 'organisation'? Just something to consider.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Explore additional sub-categories by clicking on them with the help of jQuery or alternate techniques

I am currently working on a Magento store that has Categories with an overwhelming amount of sub-categories, taking up almost half of the page. I want to enhance user experience by implementing a feature that displays a "Load more" button when there are mo ...

Express req.files returns null when using jQuery FormData

For client side functionality, I am utilizing Bootstrap and jQuery. On the server side, my technology stack includes node.js and express. The form structure is displayed below: <form id="signupform" action=""> <h2&g ...

Invoke Selenium using JavaScript

Imagine I have this (fictional) JavaScript snippet: asynchronousOperation.addEventListener("completed", function (event) { if (event.property == "required value") tell Selenium we are good; else tell Selenium the test failed; }); ...

Struggling with organizing my code in node.js - it's all over the place and not very reliable. How should I tackle this

Can anyone help me troubleshoot an issue I'm facing with code that writes to the console late or in random order? var request = require('request'); var vFind = 'HelloWorld'; var vFound = false; var vSites = ['http://www.youtu ...

Struggling with a TypeError in React/Next-js: Why is it saying "Cannot read properties of undefined" for 'id' when the object is clearly filled with data?

Encountering an issue with a checkbox list snippet in Next-js and React after moving it to the sandbox. Each time I click on a checkbox, I receive the error message: TypeError: Cannot read properties of undefined (reading 'id') This error is co ...

Node and Web scraping Promise: a powerful combination

I've been using Cheerio and Node for web scraping, and I thought implementing promises could simplify handling asynchronous code. However, my attempt to chain promises hasn't been successful. Below is the code I'm working with, in hopes that ...

hybrid application combining AngularJS with Angular 17 and above versions

I have been attempting to set up a hybrid environment with both AngularJS and Angular 1.7+ running side by side. I diligently followed all the guidelines and even created a custom webpack configuration to bundle my AngularJS and Angular files together. The ...

The Angular component fails to retrieve data from a subscribed service when the data is being fetched from the sessionStorage

Within my Angular application, there exists a service that handles incoming objects by adding them to a list of objects, then saving the updated array to sessionStorage. This service also sends the updated list to another application that is subscribed to ...

What are strategies for handling intricate state logic within my Vue.js checkbox component?

I'm facing a few challenges as I dive into learning Vue.js for just one week. Keep in mind that this example is actually nested within a parent component called <question>, but for the sake of simplicity, I've streamlined the code for this ...

What steps can be taken to ensure that a WebSQL query does not return negative

Here's the code snippet I am currently using: function decrementCart(quantity, id){ db.transaction(function(tx){ tx.executeSql("UPDATE cart SET quantity=(quantity -1) WHERE id=?", [id]) ...

Having issues updating table with Javascript after form submit in IE and Edge browsers

My current setup involves using Contact Form 7 in Wordpress to store data in a MySQL Database with Submit-Form. Now, I am working on reloading a table containing this data after the form submission. Here is the script I am currently using: /* FORM RELOAD ...

Is it possible for jQuery UI Autocomplete to utilize values from various input fields simultaneously?

I've hit a roadblock with this code and it's been giving me trouble for some time now. Here is the current state of my auto-complete script: jQ19(function(){ // minLength:1 - how many characters user enters in order to start search jQ19 ...

Magical Stylist - Eradicate Indicators while Preserving Labeling

Recently, I've been experimenting with the Google styling wizard in an effort to remove markers while retaining labels for businesses. My objective is to eliminate the marker icons but still display the text labels such as "Jimmy Johns," "Boone Saloon ...

What are alternative methods for creating a two-column form layout that do not involve the use of

When generating the html form, I am looping through the form variables as shown below: {% for field in form %} {{ LABEL }}{{ INPUT FIELD }} The labels and fields are going through a loop. A simple one-column layout can be generated using: {% for field ...

Making a POST request to a Next.js API route results in a 500 Internal Server Error being sent back

Check out the code in createComment.ts file, which serves as a Next.js api route: import type { NextApiRequest, NextApiResponse } from 'next' import sanityClient from "@sanity/client" const config = { dataset: process.env.NEXT_PUBLI ...

Is there a performance benefit to using node.js over client-side JavaScript in comparison to Chrome/V8?

Currently, I am working on a client-side javascript application for image manipulation. However, some of the operations are running quite slowly in the browser, taking about 2-3 seconds to complete. To address this issue, I am considering implementing a s ...

Error alert: Object expected on OnClientClick in Microsoft JScript runtime

I was in the middle of a quick test when I encountered an error. At this point, I haven't implemented any C# code yet and my aspx code looks like this: <script language=javascript type="text/javascript"> function myOnClick() { ...

encountering an issue while working with Selenium on Google Colab

I'm attempting to perform web scraping with selenium in Google Colab and running into some errors The webpage is prompting me to enable JavaScript and disable any ad blockers. I tried enabling JavaScript by adding the following line of code: chrome_o ...

The exportAs attribute is not specified as "ngForm" for any directive

Encountered an error while attempting to test the LoginComponent PhantomJS 2.1.1 (Linux 0.0.0): Executed 3 of 55 (1 FAILED) (0 secs / 0.307 secs) PhantomJS 2.1.1 (Linux 0.0.0) LoginComponent should create FAILED Failed: Uncaught (in promise): Error: Templ ...

The process of utilizing variables to form objects in ES6

My ES5 code contains a variable as shown below. var options = { clientId : clientId, keepAlive : keepAlive, clean : clean, reconnectPeriod : reconnectPeriod, will : lastWillMessage }; If I want to convert this to ES6, I can do so by writing ...