Skip to content

Commit

Permalink
Extend the original filter component instead of replacing it (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
milewski authored Oct 5, 2023
1 parent 9c4b4c2 commit 8ddbd57
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 49 deletions.
3 changes: 1 addition & 2 deletions dist/js/tool.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions dist/js/tool.js.LICENSE.txt

This file was deleted.

File renamed without changes.
21 changes: 14 additions & 7 deletions resources/js/components/ColumnToggler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Dropdown
:handle-internal-clicks="false"
class="flex h-9 hover:bg-gray-100 dark:hover:bg-gray-700 rounded mr-2"
class="flex h-9 hover:bg-gray-100 dark:hover:bg-gray-700 rounded"
:class="{
'bg-primary-500 hover:bg-primary-600 border-primary-500': isDirty,
'dark:bg-primary-500 dark:hover:bg-primary-600 dark:border-primary-500': isDirty,
Expand Down Expand Up @@ -78,26 +78,22 @@

<script>
import { getStateFromLocalStorage } from './ColumToggler'
import { getStateFromLocalStorage } from './ColumnToggler'
import cloneDeep from 'lodash/cloneDeep'
export default {
name: 'ColumnToggler',
props: [ 'resourceName' ],
data() {
return {
appendToRequestCallback: null,
extraParams: {},
state: {},
originalState: {},
}
},
mounted() {
Nova.$on('custom-relationship-field:extra-params', this.appendToRequestCallback = value => {
this.extraParams = { ...this.extraParams, ...value }
})
Nova.$on('custom-relationship-field:extra-params', this.appendToRequestCallback)
Nova.$emit('custom-relationship-field:request-extra-params')
const queryString = new URLSearchParams(this.extraParams)
Expand Down Expand Up @@ -168,7 +164,18 @@
updateCheckedState(attribute, checked) {
this.state[ attribute ].visible = checked
},
appendToRequestCallback(params) {
this.extraParams = { ...this.extraParams, ...params }
},
},
}
</script>
<style>
#column-toggler ~ div {
margin-left: .5rem;
}
</style>
27 changes: 0 additions & 27 deletions resources/js/components/FilterMenu.vue

This file was deleted.

47 changes: 41 additions & 6 deletions resources/js/tool.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,47 @@
import FilterMenu from './components/FilterMenu.vue'
import { registerMixin } from './components/ColumToggler'
import Index from '@/views/Index'
import ColumnToggler from './components/ColumnToggler.vue'
import { registerMixin } from './components/ColumnToggler'
import { createVNode, render } from 'vue'

Nova.booting(app => {

registerMixin(Index)
const componentFn = app.component

app.component('ResourceIndex', Index)
app.component('FilterMenu', FilterMenu)
app.component = function (name, component) {

if (name === 'ResourceIndex') {
registerMixin(component)
}

return componentFn.call(this, name, component)

}

app.mixin({
mounted() {

if (this._.type?.__file?.endsWith('ResourceTableToolbar.vue')) {

const toolbarTarget = '[dusk$="-index-component"] div.h-9.ml-auto.flex.items-center.pr-2.md\\:pr-3 > div.hidden.md\\:flex.px-2'

const container = document.createElement('div')
container.id = 'column-toggler'

const element = this._.vnode.el.querySelector(toolbarTarget)

if (element) {

element.insertAdjacentElement('afterend', container)

const vnode = createVNode(ColumnToggler, { resourceName: this._.props.resourceName })
vnode.appContext = app._context

render(vnode, container)

}

}

},
})

})

0 comments on commit 8ddbd57

Please sign in to comment.