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

remove route-action-helper #925

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions app/controllers/project-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import groupBy from 'lodash.groupby';
import semverCompare from 'semver-compare';
import getCompactVersion from '../utils/get-compact-version';
import { inject as controller } from '@ember/controller'

Check failure on line 11 in app/controllers/project-version.js

View workflow job for this annotation

GitHub Actions / Lint files

Insert `;`

export default class ProjectVersionController extends Controller {
@service
Expand All @@ -19,6 +20,15 @@
@service
project;

@service
router;

@service('project')
projectService;

@controller('project-version.classes.class')
classesController;

@alias('filterData.sideNav.showPrivate')
showPrivateClasses;

Expand Down Expand Up @@ -128,4 +138,114 @@
togglePrivateClasses() {
set(this, 'showPrivateClasses', !this.showPrivateClasses);
}

@action
updateProject(ver /*, component */) {
let project = this.activeProject;
let projectVersionID = ver.compactVersion;
let endingRoute;
switch (this.router.currentRouteName) {
case 'project-version.classes.class': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}`;
break;
}
case 'project-version.classes.class.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}`;
break;
}
case 'project-version.modules.module.index': {
let moduleName = encodeURIComponent(
this.paramsFor('project-version.modules.module').module
);
endingRoute = `modules/${moduleName}`;
break;
}
case 'project-version.namespaces.namespace.index': {
let namespaceName = this.paramsFor(
'project-version.namespaces.namespace'
).namespace;
endingRoute = `namespaces/${namespaceName}`;
break;
}
case 'project-version.classes.class.methods.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}/methods`;
break;
}
case 'project-version.classes.class.events.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}/events`;
break;
}
case 'project-version.classes.class.properties.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}/properties`;
break;
}
case 'project-version.classes.class.methods.method': {
let className = this._getEncodedNameForCurrentClass();
let methodName = this.paramsFor(
'project-version.classes.class.methods.method'
).method;
endingRoute = `classes/${className}/methods/${methodName}?anchor=${methodName}`;
break;
}
case 'project-version.classes.class.events.event': {
let className = this._getEncodedNameForCurrentClass();
let eventName = this.paramsFor(
'project-version.classes.class.events.event'
).event;
endingRoute = `classes/${className}/events/${eventName}?anchor=${eventName}`;
break;
}
case 'project-version.classes.class.properties.property': {
let className = this._getEncodedNameForCurrentClass();
let propertyName = this.paramsFor(
'project-version.classes.class.properties.property'
).property;
endingRoute = `classes/${className}/properties/${propertyName}?anchor=${propertyName}`;
break;
}
default:
endingRoute = '';
break;
}
// if the user is navigating to/from api versions >= 2.16, take them
// to the home page instead of trying to translate the url
let shouldConvertPackages = this.shouldConvertPackages(
ver,
this.projectService.version
);
let isEmberProject = project === 'ember';
if (!isEmberProject || !shouldConvertPackages) {
this.router.transitionTo(
`/${project}/${projectVersionID}/${endingRoute}`
);
} else {
this.router.transitionTo(`/${project}/${projectVersionID}`);
}
}

// Input some version info, returns a boolean based on
// whether the user is switching versions for a 2.16 docs release or later.
// The urls for pre-2.16 classes and later packages are quite different
shouldConvertPackages(targetVer, previousVer) {
let targetVersion = getCompactVersion(targetVer.id);
let previousVersion = getCompactVersion(previousVer);
let previousComparison = semverCompare(previousVersion, '2.16');
let targetComparison = semverCompare(targetVersion, '2.16');
return (
(previousComparison < 0 && targetComparison >= 0) ||
(previousComparison >= 0 && targetComparison < 0)
);
}

_getEncodedNameForCurrentClass() {
// escape any reserved characters for url, like slashes
return encodeURIComponent(

Check failure on line 247 in app/controllers/project-version.js

View workflow job for this annotation

GitHub Actions / Lint files

Replace `⏎······this.classesController.model.get('name')⏎····` with `this.classesController.model.get('name')`
this.classesController.model.get('name')
);
}
}
88 changes: 0 additions & 88 deletions app/routes/project-version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action } from '@ember/object';

Check failure on line 1 in app/routes/project-version.js

View workflow job for this annotation

GitHub Actions / Lint files

'action' is defined but never used
import { inject as service } from '@ember/service';
import Route from '@ember/routing/route';
import semverCompare from 'semver-compare';
Expand Down Expand Up @@ -144,94 +144,6 @@
};
}

@action
updateProject(project, ver /*, component */) {
let projectVersionID = ver.compactVersion;
let endingRoute;
switch (this.router.currentRouteName) {
case 'project-version.classes.class': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}`;
break;
}
case 'project-version.classes.class.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}`;
break;
}
case 'project-version.modules.module.index': {
let moduleName = encodeURIComponent(
this.paramsFor('project-version.modules.module').module
);
endingRoute = `modules/${moduleName}`;
break;
}
case 'project-version.namespaces.namespace.index': {
let namespaceName = this.paramsFor(
'project-version.namespaces.namespace'
).namespace;
endingRoute = `namespaces/${namespaceName}`;
break;
}
case 'project-version.classes.class.methods.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}/methods`;
break;
}
case 'project-version.classes.class.events.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}/events`;
break;
}
case 'project-version.classes.class.properties.index': {
let className = this._getEncodedNameForCurrentClass();
endingRoute = `classes/${className}/properties`;
break;
}
case 'project-version.classes.class.methods.method': {
let className = this._getEncodedNameForCurrentClass();
let methodName = this.paramsFor(
'project-version.classes.class.methods.method'
).method;
endingRoute = `classes/${className}/methods/${methodName}?anchor=${methodName}`;
break;
}
case 'project-version.classes.class.events.event': {
let className = this._getEncodedNameForCurrentClass();
let eventName = this.paramsFor(
'project-version.classes.class.events.event'
).event;
endingRoute = `classes/${className}/events/${eventName}?anchor=${eventName}`;
break;
}
case 'project-version.classes.class.properties.property': {
let className = this._getEncodedNameForCurrentClass();
let propertyName = this.paramsFor(
'project-version.classes.class.properties.property'
).property;
endingRoute = `classes/${className}/properties/${propertyName}?anchor=${propertyName}`;
break;
}
default:
endingRoute = '';
break;
}
// if the user is navigating to/from api versions >= 2.16, take them
// to the home page instead of trying to translate the url
let shouldConvertPackages = this.shouldConvertPackages(
ver,
this.projectService.version
);
let isEmberProject = project === 'ember';
if (!isEmberProject || !shouldConvertPackages) {
this.router.transitionTo(
`/${project}/${projectVersionID}/${endingRoute}`
);
} else {
this.router.transitionTo(`/${project}/${projectVersionID}`);
}
}

// Input some version info, returns a boolean based on
// whether the user is switching versions for a 2.16 docs release or later.
// The urls for pre-2.16 classes and later packages are quite different
Expand Down
2 changes: 1 addition & 1 deletion app/templates/project-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div class="select-container">
<PowerSelect
@onChange={{route-action "updateProject" this.activeProject}}
@onChange={{this.updateProject}}
@options={{this.projectVersions}}
@selected={{this.selectedProjectVersion}}
@ariaLabel="Select a version"
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
"ember-rfc176-data": "^0.3.17",
"ember-route-action-helper": "^2.0.8",
"ember-showdown-shiki": "^1.2.1",
"ember-sinon": "^4.1.1",
"ember-source": "~3.28.8",
Expand Down
32 changes: 0 additions & 32 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading