Skip to content

Commit

Permalink
refactor: slightly change implementation method of disableSort
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Jul 10, 2024
1 parent 82286cf commit ab176f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/vuetify/src/components/VDataTable/VDataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { provideDefaults } from '@/composables/defaults'
import { makeFilterProps, useFilter } from '@/composables/filter'

// Utilities
import { computed, toRef } from 'vue'
import { computed, toRef, toRefs } from 'vue'
import { genericComponent, propsFactory, useRender } from '@/util'

// Types
Expand Down Expand Up @@ -130,6 +130,7 @@ export const VDataTable = genericComponent<new <T extends readonly any[], V>(
const { groupBy } = createGroupBy(props)
const { sortBy, multiSort, mustSort } = createSort(props)
const { page, itemsPerPage } = createPagination(props)
const { disableSort } = toRefs(props)

const {
columns,
Expand Down Expand Up @@ -158,7 +159,7 @@ export const VDataTable = genericComponent<new <T extends readonly any[], V>(
extractRows,
isGroupOpen,
toggleGroup,
} = provideGroupBy({ groupBy, sortBy, disableSort: toRef(props, 'disableSort') })
} = provideGroupBy({ groupBy, sortBy, disableSort })

const { sortedItems } = useSortedItems(props, filteredItems, sortByWithGroups, {
transform: item => item.columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createSort, provideSort } from './composables/sort'
import { provideDefaults } from '@/composables/defaults'

// Utilities
import { computed, provide, toRef } from 'vue'
import { computed, provide, toRef, toRefs } from 'vue'
import { genericComponent, propsFactory, useRender } from '@/util'

// Types
Expand Down Expand Up @@ -69,6 +69,7 @@ export const VDataTableServer = genericComponent<new <T extends readonly any[],
const { groupBy } = createGroupBy(props)
const { sortBy, multiSort, mustSort } = createSort(props)
const { page, itemsPerPage } = createPagination(props)
const { disableSort } = toRefs(props)
const itemsLength = computed(() => parseInt(props.itemsLength, 10))

const { columns, headers } = createHeaders(props, {
Expand All @@ -81,7 +82,7 @@ export const VDataTableServer = genericComponent<new <T extends readonly any[],

const { toggleSort } = provideSort({ sortBy, multiSort, mustSort, page })

const { opened, isGroupOpen, toggleGroup, extractRows } = provideGroupBy({ groupBy, sortBy, disableSort: toRef(props, 'disableSort') })
const { opened, isGroupOpen, toggleGroup, extractRows } = provideGroupBy({ groupBy, sortBy, disableSort })

const { pageCount, setItemsPerPage } = providePagination({ page, itemsPerPage, itemsLength })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { makeFilterProps, useFilter } from '@/composables/filter'
import { makeVirtualProps, useVirtual } from '@/composables/virtual'

// Utilities
import { computed, shallowRef, toRef } from 'vue'
import { computed, shallowRef, toRef, toRefs } from 'vue'
import { convertToUnit, genericComponent, propsFactory, useRender } from '@/util'

// Types
Expand Down Expand Up @@ -85,6 +85,7 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
setup (props, { attrs, slots }) {
const { groupBy } = createGroupBy(props)
const { sortBy, multiSort, mustSort } = createSort(props)
const { disableSort } = toRefs(props)

const {
columns,
Expand Down Expand Up @@ -112,7 +113,7 @@ export const VDataTableVirtual = genericComponent<new <T extends readonly any[],
extractRows,
isGroupOpen,
toggleGroup,
} = provideGroupBy({ groupBy, sortBy, disableSort: toRef(props, 'disableSort') })
} = provideGroupBy({ groupBy, sortBy, disableSort })

const { sortedItems } = useSortedItems(props, filteredItems, sortByWithGroups, {
transform: item => item.columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function createGroupBy (props: GroupProps) {
export function provideGroupBy (options: {
groupBy: Ref<readonly SortItem[]>
sortBy: Ref<readonly SortItem[]>
disableSort?: Ref<boolean>
disableSort: Ref<boolean>
}) {
const { disableSort, groupBy, sortBy } = options
const opened = ref(new Set<string>())
Expand All @@ -63,7 +63,7 @@ export function provideGroupBy (options: {
return groupBy.value.map<SortItem>(val => ({
...val,
order: val.order ?? false,
})).concat(disableSort?.value ? [] : sortBy.value)
})).concat(disableSort.value ? [] : sortBy.value)
})

function isGroupOpen (group: Group) {
Expand Down

0 comments on commit ab176f1

Please sign in to comment.