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

Executing Controller Actions within a JavaScript Timer

Presenting my latest timer: var eventDate = new Date(Date.parse(new Date) + 3600); function countdown() { var elapsed = Date.parse(eventDate) - Date.parse(new Date()); var seconds = Math.floor((elaps ...

Troubleshooting: Vue JS failing to recognize new objects and properties in HTML

Within my Vue instance, I have a method named `loadPlannedAlerts` that performs an AJAX call to retrieve JSON data. This method is called during the `mounted` lifecycle hook of my Vue JS instance. The retrieved JSON object consists of key-value pairs struc ...

Omit a certain td element from the querySelectorAll results

Greetings! I am currently working with an HTML table and I need to figure out how to exclude a specific td element from it, but I'm not sure how to go about it. Here's the HTML code: <table id="datatable-responsive" c ...

Is there a method to modify the arrangement in which 3 specific HTML elements are displayed (i.e., their hierarchy in relation to one another)?

I have 3 "p" elements and I'm trying to find a way to change the order in which they load on the page using JS or CSS. Below is an example of what I've attempted so far. When you click on the first box labeled "about 1," it opens up and displays ...

Setting up a Node.js http2 server along with an http server specifically designed for a single

In my upcoming project, I am interested in implementing the http2 protocol. My goal is to have both http and http2 servers running on a single domain and port, if feasible. When a client that does not support http2 connects, communication will default to ...

Arrow indicating the correct direction to expand or collapse all items with a single click

I have successfully implemented the "expand/collapse all" function, but I am facing an issue with the arrow direction. The arrows are not pointing in the correct direction as desired. Since I am unsure how to fix this problem, I have left it empty in my co ...

Create visual representations using the data displayed in charts generated by Chart JS

Good evening. I am currently utilizing Chart JS in my project to visualize the total count per column in a bar graph. My backend framework is Laravel, and I pass the data from the controller using the variable $datacount. This snippet shows the query in ...

How can I prevent my Vue.js application from losing focus when navigating to different components?

I am encountering an issue with my Vue.js app where the focus is lost when changing routes. Initially, when the site loads, the first element of the header component is correctly in focus as desired. However, when navigating to a different link on the site ...

Facing an issue with the format.js not functioning properly in Rails version 6.1.3

styles.css @import url("https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap"); body { font-family: 'Roboto', sans-serif; color: #333; } .wrapper { max-width: 960px; margin: 0 auto; } button { background ...

Can you explain the definition of "mount" in the context of Express?

Currently diving into the world of Express.js, I stumbled upon this definition: "An Express router offers a limited set of Express methods. To initialize one, we call the .Router() method on the main Express import. To utilize a router, we mount it a ...

What is the best way to populate an array with JSON data using jQuery?

As a newcomer to jQuery, I decided to experiment with the getJSON function. My goal was to extract the "id" section from a JSON file and store it in an array called planes using jQuery. This array would then be utilized in an autocomplete function to popul ...

Uncover the solution to eliminating webpack warnings associated with incorporating the winston logger by utilizing the ContextReplacementPlugin

When running webpack on a project that includes the winston package, several warnings are generated. This is because webpack automatically includes non-javascript files due to a lazy-loading mechanism in a dependency called logform. The issue arises when ...

Attach a click event listener to content loaded through AJAX using only JavaScript, without relying on jQuery

I'm curious about how to attach a click event to an element that will be added later through an ajax call. I know jQuery can handle this like so: $(document).on('click', '.ajax-loaded-element' function(){}); However, I'm not ...

How to remove checkbox border using HTML, JavaScript, and CSS

Is it possible to remove the square border from a checkbox in HTML? ...

Incorporate duration into date using angular

In my Firebase database, I store the following information: Timestamp for the day a record was created in Firebase. Terms entered by the user at the time of creation. For instance, it may look like this: 1439612582756 // converts to: Aug 14, 2015 15 / ...

The specified type '{}' cannot be assigned to type 'ReactNode'

Can someone help me figure out why I am getting this error in Vercel but not locally? Error: 'FontAwesomeIcon' cannot be used as a JSX component. ./components/Services/ServiceContainer.tsx:25:6 12:01:54.967 Type error: 'FontAwesomeIcon&a ...

Using Firebase to interact with data: $add(), .push(), and .set()

Utilizing Firebase and AngularFire has opened up many different approaches for CRUD operations with the Firebase API. However, I am still uncertain about the specific differences between using: $add with $firebaseArray The .push() method The .set() metho ...

What is the best way to compile TypeScript files without them being dependent on each other?

I have created a TypeScript class file with the following code: class SampleClass { public load(): void { console.log('loaded'); } } Now, I also have another TypeScript file which contains functions that need to utilize this class: // ...

String includes another String not refreshing automatically

How come myCtrl.greeting doesn't automatically update when I change myCtrl.name? angular.module('MyApp', []) .controller('MainController', [function(){ var mCtrl = this; mCtrl.name = ''; mCt ...

Utilize jQuery and JSP (or PHP) to showcase detailed information about a specific item when a user clicks on it within an HTML page

For my upcoming college project, I am tasked with developing a movie library. The main page of the library will feature various movie posters. Upon clicking on a poster, users will be directed to a dedicated page displaying detailed information about the ...