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

Fix issue when using Nova under a /path #71

Merged
merged 2 commits into from
Oct 2, 2023
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ExampleNovaResource extends Resource {
return [
ResourceNavigationField::make('Information'), // show all the available cards by default
ResourceNavigationField::make('Activities')->withCards([ DailySalesCard::class, ClientProfileCard::class ]), // only show these cards when this tab is active
ResourceNavigationField::make('Settings')->withoutCards([ ... ]), // hide all cards when this tab is active
ResourceNavigationField::make('Settings')->withoutCards(), // hide all cards when this tab is active
];
}

Expand Down
2 changes: 1 addition & 1 deletion dist/js/card.js

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

6 changes: 0 additions & 6 deletions dist/js/card.js.LICENSE

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@vue/compiler-sfc": "^3.3.4",
"laravel-mix": "^6.0.49",
"mix-tailwindcss": "^1.3.0",
"postcss": "^8.4.29",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"vue-loader": "^17.2.2"
}
Expand Down
47 changes: 47 additions & 0 deletions resources/js/components/RequestHighjacker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const novaRequest = Nova.request

const interceptors = []
const interceptorsInstance = []

Nova.request = (...params) => {

for (const param of params) {

for (const interceptor of interceptors) {
interceptor(param)
}

}

const axiosInstance = novaRequest(...params)

if (axiosInstance instanceof Promise) {
return axiosInstance
}

for (const interceptor of interceptors) {

interceptorsInstance.push({
instance: axiosInstance,
interceptor: axiosInstance.interceptors.request.use(config => interceptor(config)),
})

}

return axiosInstance

}

function cleanUpInterceptors() {

for (const { instance, interceptor } of interceptorsInstance) {
instance.interceptors.request.eject(interceptor)
}

while (interceptors.length) {
interceptors.pop()
}

}

export { interceptors, cleanUpInterceptors }
55 changes: 16 additions & 39 deletions resources/js/components/ResourceNavigationCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,26 @@

<script>

const novaRequest = Nova.request
import { interceptors } from './RequestHighjacker'

const interceptors = []
const interceptorsInstance = []

Nova.request = (...params) => {
interceptors.push(config => {

for (const param of params) {
try {

for (const interceptor of interceptors) {
interceptor(param)
if (config.params === undefined || config.params === null) {
config.params = {}
}

}
const searchParams = new URLSearchParams(window.location.search)

const axiosInstance = novaRequest(...params)

if (axiosInstance instanceof Promise) {
return axiosInstance
}

for (const interceptor of interceptors) {

interceptorsInstance.push({
instance: axiosInstance,
interceptor: axiosInstance.interceptors.request.use(config => interceptor(config)),
})

}

return axiosInstance

}

interceptors.push(config => {
if (searchParams.has('x-tab')) {
config.params[ 'x-resource-navigation-tab' ] = searchParams.get('x-tab')
}

if (config.params === undefined) {
config.params = {}
}
} catch (error) {

const searchParams = new URLSearchParams(window.location.search)
console.log('ResourceNavigationCard.vue error:', error)

if (searchParams.has('x-tab')) {
config.params[ 'x-resource-navigation-tab' ] = searchParams.get('x-tab')
}

return config
Expand All @@ -78,17 +54,18 @@
onNavigate: slug => {

const searchParams = new URLSearchParams(window.location.search)
const url = window.location.pathname.replace(new RegExp(`^${ Nova.config('base') }`), '')

Nova.visit(window.location.pathname, {
Nova.visit(url, {
data: {
...Object.fromEntries(searchParams.entries()),
'x-tab': slug,
}
},
})

}
},
}
}
},
}

</script>
Expand Down
Loading