Skip to content

Commit

Permalink
improved active tab finding and abstracted to utility
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Sep 10, 2024
1 parent a7fdffd commit bcffa19
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 213 deletions.
19 changes: 3 additions & 16 deletions addon/components/contact-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isArray } from '@ember/array';
import ContactPanelDetailComponent from './contact-panel/details';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import findActiveTab from '../utils/find-active-tab';

export default class ContactPanelComponent extends Component {
@service fetch;
Expand Down Expand Up @@ -53,7 +54,7 @@ export default class ContactPanelComponent extends Component {
constructor() {
super(...arguments);
this.contact = this.args.contact;
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -76,7 +77,7 @@ export default class ContactPanelComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

Expand Down Expand Up @@ -108,18 +109,4 @@ export default class ContactPanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.contact);
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
19 changes: 3 additions & 16 deletions addon/components/customer-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isArray } from '@ember/array';
import CustomerPanelDetailComponent from './customer-panel/details';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import findActiveTab from '../utils/find-active-tab';

export default class CustomerPanelComponent extends Component {
@service fetch;
Expand Down Expand Up @@ -53,7 +54,7 @@ export default class CustomerPanelComponent extends Component {
constructor() {
super(...arguments);
this.customer = this.args.customer;
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -76,7 +77,7 @@ export default class CustomerPanelComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

Expand Down Expand Up @@ -108,18 +109,4 @@ export default class CustomerPanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.customer);
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
19 changes: 3 additions & 16 deletions addon/components/driver-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DriverPanelDetailComponent from './driver-panel/details';
import DriverPanelOrdersComponent from './driver-panel/orders';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import findActiveTab from '../utils/find-active-tab';

export default class DriverPanelComponent extends Component {
/**
Expand Down Expand Up @@ -92,7 +93,7 @@ export default class DriverPanelComponent extends Component {
constructor() {
super(...arguments);
this.driver = this.args.driver;
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -115,7 +116,7 @@ export default class DriverPanelComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

Expand Down Expand Up @@ -160,18 +161,4 @@ export default class DriverPanelComponent extends Component {
this.contextPanel.focus(vehicle);
}
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
19 changes: 3 additions & 16 deletions addon/components/fleet-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FleetPanelDriverListingComponent from './fleet-panel/driver-listing';
import FleetPanelVehicleListingComponent from './fleet-panel/vehicle-listing';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import findActiveTab from '../utils/find-active-tab';

export default class FleetPanelComponent extends Component {
@service fetch;
Expand Down Expand Up @@ -70,7 +71,7 @@ export default class FleetPanelComponent extends Component {
constructor() {
super(...arguments);
this.fleet = this.args.fleet;
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -93,7 +94,7 @@ export default class FleetPanelComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

Expand Down Expand Up @@ -125,18 +126,4 @@ export default class FleetPanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.fleet);
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
19 changes: 3 additions & 16 deletions addon/components/fuel-report-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { isArray } from '@ember/array';
import FuelReportPanelDetailsComponent from './fuel-report-panel/details';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import findActiveTab from '../utils/find-active-tab';

export default class FuelReportPanelComponent extends Component {
/**
Expand Down Expand Up @@ -89,7 +90,7 @@ export default class FuelReportPanelComponent extends Component {
constructor() {
super(...arguments);
this.fuelReport = this.args.fuelReport;
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -112,7 +113,7 @@ export default class FuelReportPanelComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

Expand Down Expand Up @@ -144,18 +145,4 @@ export default class FuelReportPanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.fuelReport);
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
20 changes: 4 additions & 16 deletions addon/components/issue-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { isArray } from '@ember/array';
import IssuePanelDetailComponent from './issue-panel/details';
import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments';
import findActiveTab from '../utils/find-active-tab';

export default class IssuePanelComponent extends Component {
/**
* Service for fetching data.
Expand Down Expand Up @@ -88,7 +90,7 @@ export default class IssuePanelComponent extends Component {
constructor() {
super(...arguments);
this.issue = this.args.issue;
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -111,7 +113,7 @@ export default class IssuePanelComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

Expand Down Expand Up @@ -143,18 +145,4 @@ export default class IssuePanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.issue);
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
19 changes: 3 additions & 16 deletions addon/components/live-map-drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-co
import LiveMapDrawerVehicleListingComponent from './live-map-drawer/vehicle-listing';
import LiveMapDrawerDriverListingComponent from './live-map-drawer/driver-listing';
import LiveMapDrawerPlaceListingComponent from './live-map-drawer/place-listing';
import findActiveTab from '../utils/find-active-tab';

export default class LiveMapDrawerComponent extends Component {
/**
Expand Down Expand Up @@ -58,7 +59,7 @@ export default class LiveMapDrawerComponent extends Component {
*/
constructor() {
super(...arguments);
this.tab = this.getTabUsingSlug(this.args.tab);
this.tab = findActiveTab(this.tabs, this.args.tab);
applyContextComponentArguments(this);
}

Expand All @@ -84,21 +85,7 @@ export default class LiveMapDrawerComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
contextComponentCallback(this, 'onTabChanged', tab);
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
19 changes: 3 additions & 16 deletions addon/components/order-config-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import OrderConfigManagerDetailsComponent from './order-config-manager/details';
import OrderConfigManagerCustomFieldsComponent from './order-config-manager/custom-fields';
import OrderConfigManagerActivityFlowComponent from './order-config-manager/activity-flow';
import OrderConfigManagerEntitiesComponent from './order-config-manager/entities';
import findActiveTab from '../utils/find-active-tab';

const configManagerContext = EmberObject.extend(Evented);
export default class OrderConfigManagerComponent extends Component {
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class OrderConfigManagerComponent extends Component {
this.context = context;
this.contextModel = contextModel;
this.configManagerContext = configManagerContext.create();
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
this.loadOrderConfigs.perform();
}

Expand Down Expand Up @@ -255,7 +256,7 @@ export default class OrderConfigManagerComponent extends Component {
* @action
*/
@action onTabChanged(tab) {
this.tab = this.getTabUsingSlug(tab);
this.tab = findActiveTab(this.tabs, tab);
this.configManagerContext.trigger('onTabChanged');
contextComponentCallback(this, 'onTabChanged', tab);
}
Expand Down Expand Up @@ -284,18 +285,4 @@ export default class OrderConfigManagerComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel');
}

/**
* Finds and returns a tab based on its slug.
*
* @param {String} tabSlug - The slug of the tab.
* @returns {Object|null} The found tab or null.
*/
getTabUsingSlug(tabSlug) {
if (tabSlug) {
return this.tabs.find(({ slug }) => slug === tabSlug);
}

return this.tabs[0];
}
}
1 change: 1 addition & 0 deletions addon/components/place-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</div>
</div>
<div class="tab-content tab-{{this.tab.slug}}">
{{log this.tab}}
{{component this.tab.component place=this.place tabOptions=this.tab options=this.tab.componentParams}}
</div>
<Spacer @height="300px" />
Expand Down
Loading

0 comments on commit bcffa19

Please sign in to comment.