-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from RTIInternational/routing-enhancements
Routing enhancements
- Loading branch information
Showing
8 changed files
with
76 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "@rtidatascience/harness-vue", | ||
"author": "RTI CDS <[email protected]>", | ||
"private": false, | ||
"version": "1.6.0", | ||
"version": "1.7.0-0", | ||
"type": "module", | ||
"repository": { | ||
"type": "git", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
// https://stackoverflow.com/questions/72209080/vue-3-is-getcurrentinstance-deprecated | ||
import { getCurrentInstance } from "vue"; | ||
import { useHarnessStore } from "../harness.js"; | ||
|
||
export default function useHarnessComposable() { | ||
/** | ||
* Returns the current harness page store | ||
* If a waypoint is provided, that store is returned | ||
* If the route is provided and the route name matches a harness store key, that store is returned | ||
* If there is no router and only a single harness page exists, that store is returned | ||
* @param {any} waypoint=false a string matching a harness page store key | ||
* @returns {Object} a pinia store representing a harness page | ||
*/ | ||
export default function useHarnessComposable(waypoint = false) { | ||
const harnessMetadata = useHarnessStore(); | ||
const vueInstance = getCurrentInstance(); | ||
if (waypoint === false) { | ||
let currentRoute = | ||
harnessMetadata.optionsProvided?.router?.currentRoute?.name; | ||
|
||
let waypoint = false; | ||
// check for a vue-router route | ||
if (currentRoute && harnessMetadata.getPages.includes(currentRoute)) { | ||
waypoint = currentRoute; | ||
} | ||
|
||
// check for a vue-router route | ||
if ( | ||
vueInstance.appContext.config.globalProperties.$route?.name && | ||
harnessMetadata.getPages.includes( | ||
vueInstance.appContext.config.globalProperties.$route.name, | ||
) | ||
) { | ||
waypoint = vueInstance.appContext.config.globalProperties.$route.name; | ||
// if router is not installed and only a single harness page exists, use it as waypoint | ||
if (harnessMetadata.getPages.length === 1 && !currentRoute) { | ||
waypoint = harnessMetadata.pages[0]; | ||
} | ||
} | ||
|
||
// if router is not installed and only a single harness page exists, use it as waypoint | ||
if ( | ||
(harnessMetadata.getPages.length === 1) & | ||
!vueInstance.appContext.config.globalProperties.$route | ||
waypoint && | ||
Object.keys(harnessMetadata.getPageStores).includes(waypoint) | ||
) { | ||
waypoint = harnessMetadata.pages[0]; | ||
} | ||
|
||
// // if a waypoint override was specified, use that | ||
if (vueInstance.attrs["harness-waypoint"]) { | ||
waypoint = vueInstance.attrs["harness-waypoint"]; | ||
} | ||
|
||
if (waypoint) { | ||
return harnessMetadata.getPageStores[waypoint](); | ||
} | ||
return waypoint; | ||
console.error( | ||
`The detected waypoint ${waypoint} is not a valid harness page.`, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
export default function createHarnessRoute(store, pageDefinition) { | ||
return { | ||
path: "/" + pageDefinition.key, | ||
name: pageDefinition.key, | ||
path: `/${pageDefinition?.routePath || pageDefinition.key}`, | ||
name: pageDefinition?.routeName || pageDefinition.key, | ||
component: pageDefinition.pageComponent, | ||
props: pageDefinition.pageProps ? pageDefinition.pageProps : false, | ||
beforeEnter: pageDefinition.loadData | ||
? (to, from, next) => { | ||
if (from.name) { | ||
store.clearData(); | ||
} | ||
if (to.name) { | ||
store.loadData(); | ||
} | ||
next(); | ||
props: pageDefinition?.pageProps, | ||
beforeEnter: (to, from, next) => { | ||
if (pageDefinition?.routeBeforeEnter) { | ||
pageDefinition.routeBeforeEnter(to, from, next, store); | ||
} else { | ||
if (from.name) { | ||
store.clearData(); | ||
} | ||
: null, | ||
if (to.name) { | ||
store.loadData(); | ||
} | ||
next(); | ||
} | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters