Skip to content

Commit

Permalink
Switch router push to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Apr 30, 2024
1 parent beac11d commit 72d2a1b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ async function onOperation(operation: Operation, rowData: RowData) {
* Handle router push request emitted by grid module
*/
function onRouterPush(route: string, options = {}) {
// @ts-ignore
router.push(route, options);
router.push({ path: route, params: { ...options } });
}
/**
Expand Down
6 changes: 2 additions & 4 deletions client/src/components/History/Content/ContentItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,9 @@ function onDisplay() {
// but we're using a __vkey__ bit as a workaround
// Only conditionally force to keep urls clean most of the time.
if (route.path === itemUrls.value.display) {
// @ts-ignore - monkeypatched router, drop with migration.
router.push(itemUrls.value.display, { title: props.name, force: true });
router.push({ path: itemUrls.value.display, params: { __title__: props.name, __force__: "true" } });
} else if (itemUrls.value.display) {
// @ts-ignore - monkeypatched router, drop with migration.
router.push(itemUrls.value.display, { title: props.name });
router.push({ path: itemUrls.value.display, params: { __title__: props.name } });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getGalaxyInstance } from "app";
import { addSearchParams } from "utils/url";
import { getGalaxyInstance } from "@/app";

Check failure on line 1 in client/src/entry/analysis/router-push.ts

View workflow job for this annotation

GitHub Actions / client-unit-test (18)

Run autofix to sort these imports!
import { addSearchParams } from "@/utils/url";
import { Route } from 'vue-router';

/**
* Is called before the regular router.push() and allows us to provide logs,
Expand All @@ -9,13 +10,15 @@ import { addSearchParams } from "utils/url";
* @param {String} Location as parsed to original router.push()
* @param {Object} Custom options, to provide a title and/or force reload
*/
export function patchRouterPush(VueRouter) {
export function patchRouterPush(VueRouter: any) {
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, options = {}) {
VueRouter.prototype.push = function push(route: Route) {
let location: string = route.path;
const title = route.params?.__title__;
const force = route.params?.__force__;
// add key to location to force component refresh
const { title, force } = options;
if (force) {
location = addSearchParams(location, { __vkey__: Date.now() });
location = addSearchParams(location, { __vkey__: String(Date.now()) });
}
// verify if confirmation is required
if (this.confirmation) {
Expand All @@ -34,7 +37,7 @@ export function patchRouterPush(VueRouter) {
// always emit event, even when a duplicate route is pushed
this.app.$emit("router-push");
// avoid console warning when user clicks to revisit same route
return originalPush.call(this, location).catch((err) => {
return originalPush.call(this, location).catch((err: any) => {
if (err.name !== "NavigationDuplicated") {
throw err;
}
Expand Down

0 comments on commit 72d2a1b

Please sign in to comment.