[go: up one dir, main page]

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

Add an onTabActive action #9

Open
cah-brian-gantzler opened this issue Nov 12, 2018 · 9 comments
Open

Add an onTabActive action #9

cah-brian-gantzler opened this issue Nov 12, 2018 · 9 comments

Comments

@cah-brian-gantzler
Copy link
Collaborator

If would be nice to have an action exposed that would inform when and which tab became active.

@cah-brian-gantzler
Copy link
Collaborator Author

I had a specific use case, when a tab was clicked, I wanted to transition to another page. Basically I wanted a few routes to look like a tab control, but each tab was actually a route. Exposing this action would have allowed me to perform a transition on action. But I wasn't sure what other use this action would actually serve.

I came to the conclusion that I could use the ember-href-to as the text of my tab and accomplish the same thing.

Given that, without a more general use case, I have chosen not to implement this as well, but leave this comment for anyone else wishing to accomplish the same thing.

@nsharrok
Copy link
nsharrok commented Jan 31, 2020

I would love this to.
An action to indicate which tab was open.
In my instance I have a dozen report tabs each chewing large data sets.
I would like to process only the active tab.
Knowing which tab was active would allow me to control the processing load and hence the response time of the app

@cah-brian-gantzler
Copy link
Collaborator Author

Is every tab basically the same display, just different data? or is each tab a completely different layout?

If each tab is exactly the same, you should use the page control version. You dont really need a tab control.

The page control version uses one pane, not a pane for each tab, so your DOM is only in there once. I have a tab where there are three accounts. Each account is a tab, the layout of each tab pane is exactly the same, just different data.

You can see below there is only one pane, and there is an @data defined on the tab. So when the tab becomes active, pane.data contains the data from the currently selected tab. You could encode meta data in the data object for more control.

You will also notice I included a {{log pane}}. If you inspect pane I think you will see the the active name of the tab. You could do an if on it. Not as great as an action, but close.

If you are on 2.18 or better you can use {{did-update }} on the pane to load data and its probably better than an action

<XTabs @tab-style="tabs-style-topline" as | xt | >
  <xt.tabs class="row marginLeft0" as | tabs | >
    {{#each model.accounts as | account |}}
      <tabs.tab @name={{account.accountType.accountTypeCode}} @data={{account}}>
        {{account.accountType.displayName}}
      </tabs.tab>
    {{/each}}
  </xt.tabs>

  <xt.dataPane class="row" as | pane | >
    {{log pane}}
    <div class="account-detail-screen text-left x-tabs-override">
      <AccountDetail @model={{pane.data}} @isRfid={{model.hasRfidEnclosure}} />
      <ParsInfo @model={{pane.data}} />
      <BillingInfo @model={{pane.data}} />
    </div>
  </xt.dataPane>

</XTabs>

@nsharrok
Copy link
nsharrok commented Feb 3, 2020

My issue is that the data is loaded after the pane in initially rendered. I need a method to trigger a re-render.
I was just about to do a pull request when I saw your post.

I edited x-tab.js which solved my problem.

  actions: {
    select(id) {
      this.set('isActiveId', id);
      if (typeof this.get('onTabActive') === 'function') {
        this.get('onTabActive')(id);
      }
    }
  }

On the reports template I called x-tabs like this:

{{#x-tab  "tabActivated") tab-style="tabs-style-bar" as |tab| }}

@cah-brian-gantzler
Copy link
Collaborator Author

It looks like you are using the version before they were composable. Looking in the code I cant find that action anywhere on the master branch so when you upgrade you may have to do it another way.

What version of ember are you using and what version of this addon?

@nsharrok
Copy link
nsharrok commented Feb 3, 2020

oops, my bad.
looks like I was using "ember-x-tabs": "0.0.14", and ember-cli: 3.7.1
Does the latest version have my desired functionality?

@cah-brian-gantzler
Copy link
Collaborator Author

If you are on a higher version of xtabs, you probably are on a higher version of ember and I think there is a different way to accomplish that.

It doesnt appear that the onActiveTab action is still there. Im not sure why.

Dont see a reason it couldnt be added back.

@nsharrok
Copy link
nsharrok commented Feb 3, 2020

I've upgraded ember-x-tabs to 1.0.5
Looking in node_modules/ember-x-tabs/addon/components/x-tab.js

import { filter, oneWay } from '@ember/object/computed';
import Component from '@ember/component';
import { A } from '@ember/array';
import { getWithDefault, computed } from '@ember/object';
import layout from '../templates/components/x-tab';
import ComponentParent from '../mixins/component-parent';
import TabPane from './x-tab/pane';

export default Component.extend(ComponentParent, {
  layout,
  classNames: ['tabs'],
  classNameBindings: ['tab-style', 'customClass'],

  childPanes: filter('children', function(view) {
    return view instanceof TabPane;
  }),

  activeId: oneWay('childPanes.firstObject.elementId'),

  isActiveId: computed('activeId', {
    get() {
      return getWithDefault(this, 'activeId', null);
    },
    set(key, value) {
      return value;
    }
  }),

  navItems: computed('childPanes.@each.{elementId,title,icon}', function() {
    let items = A();
    this.get('childPanes').forEach((pane) => {
      let item = pane.getProperties('elementId', 'title', 'icon');
      items.push(item);
    });
    return items;
  }),

  actions: {
    select(id) {
      this.set('isActiveId', id);
      // I added the next three lines
      if (typeof this.get('onTabActive') === 'function') {
        this.get('onTabActive')(id);
      }
    }
  }
});

I've put in a pull request with the above alteration

@cah-brian-gantzler
Copy link
Collaborator Author

Since the PR wasnt linked here, I tried looking it up in closed ones, didnt see anything. Was this merged and is this in the current release? Or do we need to make another PR? If so, I would wait til after it is converted to a V2 addon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants