Skip to content

Commit a445d0c

Browse files
committed
refactor: minor code style aligment
1 parent e6d59d8 commit a445d0c

3 files changed

Lines changed: 20 additions & 18 deletions

File tree

packages/api-generator/src/locale/en/DataTable-group.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"props": {
33
"groupBy": "Defines the grouping of the table items.",
44
"groupKey": "Custom function to generate group IDs. Receives `{ key, value, parentKey }` where `parentKey` is `null` for top-level groups. Useful when group values contain special characters or are non-string types.",
5-
"openAll": "Opens all groups by default. Synchronizes `v-model:opened`, so closed groups are not re-opened accidentally.",
6-
"opened": "An array of group IDs that should be open. Supports two-way binding with `v-model:opened`.",
5+
"openAll": "Opens all groups by default. Synchronizes with **v-model:opened**, so closed groups are not re-opened accidentally.",
6+
"opened": "Array of group IDs that should be open. Can be bound to external variable using **v-model:opened**.",
77
"pageBy": "Controls how pagination counts items.\n- **item** paginates by individual items,\n- **auto** paginates by top-level groups and falls back to regular items if **group-by** is empty,\n- **any** paginates by both items and groups combined"
88
}
99
}

packages/vuetify/src/components/VDataIterator/VDataIterator.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// Components
22
import { VFadeTransition } from '@/components/transitions'
33
import { makeDataTableExpandProps, provideExpanded } from '@/components/VDataTable/composables/expand'
4-
import { makeDataTableGroupProps, provideGroupBy, syncOpenedWithGroups, useGroupedItems } from '@/components/VDataTable/composables/group'
4+
import {
5+
createGroupBy,
6+
makeDataTableGroupProps,
7+
provideGroupBy,
8+
syncOpenedWithGroups,
9+
useGroupedItems,
10+
} from '@/components/VDataTable/composables/group'
511
import { useOptions } from '@/components/VDataTable/composables/options'
612
import {
713
createPagination,
@@ -17,7 +23,6 @@ import { makeDataIteratorItemsProps, useDataIteratorItems } from './composables/
1723
import { makeComponentProps } from '@/composables/component'
1824
import { makeFilterProps, useFilter } from '@/composables/filter'
1925
import { LoaderSlot } from '@/composables/loader'
20-
import { useProxiedModel } from '@/composables/proxiedModel'
2126
import { makeTagProps } from '@/composables/tag'
2227
import { useToggleScope } from '@/composables/toggleScope'
2328
import { makeTransitionProps, MaybeTransition } from '@/composables/transition'
@@ -110,10 +115,7 @@ export const VDataIterator = genericComponent<new <T> (
110115
},
111116

112117
setup (props, { slots }) {
113-
const groupBy = useProxiedModel(props, 'groupBy')
114-
const openedModel = useProxiedModel(props, 'opened')
115-
const openAll = toRef(() => props.openAll)
116-
const groupKeyFn = toRef(() => props.groupKey)
118+
const { groupBy, opened, openAll, groupKey } = createGroupBy(props)
117119
const search = toRef(() => props.search)
118120

119121
const { items } = useDataIteratorItems(props)
@@ -125,15 +127,15 @@ export const VDataIterator = genericComponent<new <T> (
125127
const { toggleSort } = provideSort({ initialSortOrder, sortBy, multiSort, mustSort, page })
126128
const {
127129
sortByWithGroups,
128-
opened,
130+
opened: openedGroups,
129131
extractRows,
130132
isGroupOpen,
131133
toggleGroup,
132-
} = provideGroupBy({ groupBy, sortBy, opened: openedModel })
134+
} = provideGroupBy({ groupBy, sortBy, opened })
133135

134136
const { sortedItems } = useSortedItems(props, filteredItems, sortByWithGroups, { transform: item => item.raw })
135-
syncOpenedWithGroups(opened, openAll, sortedItems, groupBy, groupKeyFn)
136-
const { flatItems } = useGroupedItems(sortedItems, groupBy, opened, false, isGroupOpen, groupKeyFn)
137+
syncOpenedWithGroups(openedGroups, openAll, sortedItems, groupBy, groupKey)
138+
const { flatItems } = useGroupedItems(sortedItems, groupBy, openedGroups, false, isGroupOpen, groupKey)
137139

138140
const manualPagination = toRef(() => !isEmpty(props.itemsLength))
139141
const itemsLength = toRef(() => manualPagination.value ? Number(props.itemsLength) : flatItems.value.length)

packages/vuetify/src/components/VDataTable/composables/group.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface GroupSummary<T = any> {
3333
items: readonly (T | Group<T> | GroupSummary<T>)[]
3434
}
3535

36-
export type GroupKeyFn = (options: { key: string, value: any, parentKey: string | null }) => string
36+
export type GroupKeyFunction = (options: { key: string, value: any, parentKey: string | null }) => string
3737

3838
export const makeDataTableGroupProps = propsFactory({
3939
groupBy: {
@@ -45,7 +45,7 @@ export const makeDataTableGroupProps = propsFactory({
4545
default: () => ([]),
4646
},
4747
openAll: Boolean,
48-
groupKey: Function as PropType<GroupKeyFn>,
48+
groupKey: Function as PropType<GroupKeyFunction>,
4949
}, 'DataTable-group')
5050

5151
const VDataTableGroupSymbol: InjectionKey<{
@@ -63,7 +63,7 @@ type GroupProps = {
6363
opened: readonly string[]
6464
'onUpdate:opened': ((value: string[]) => void) | undefined
6565
openAll: boolean
66-
groupKey: GroupKeyFn | undefined
66+
groupKey: GroupKeyFunction | undefined
6767
}
6868

6969
export function createGroupBy (props: GroupProps) {
@@ -170,7 +170,7 @@ const defaultGroupId = (key: string, value: any, parentKey: string) => `${parent
170170
function groupItems <T extends GroupableItem> (
171171
items: readonly T[],
172172
groupBy: readonly string[],
173-
groupKeyFn?: GroupKeyFn,
173+
groupKeyFn?: GroupKeyFunction,
174174
depth = 0,
175175
parentKey = 'root',
176176
) {
@@ -210,7 +210,7 @@ export function syncOpenedWithGroups (
210210
openAll: MaybeRefOrGetter<boolean>,
211211
items: MaybeRefOrGetter<readonly GroupableItem[]>,
212212
groupBy: Ref<readonly SortItem[]>,
213-
groupKeyFn?: MaybeRefOrGetter<GroupKeyFn | undefined>,
213+
groupKeyFn?: MaybeRefOrGetter<GroupKeyFunction | undefined>,
214214
) {
215215
const allIds = computed(() => {
216216
if (!toValue(openAll) || !groupBy.value.length) return new Set<string>()
@@ -271,7 +271,7 @@ export function useGroupedItems <T extends GroupableItem> (
271271
opened: Ref<Set<string>>,
272272
hasSummary: MaybeRefOrGetter<boolean>,
273273
isGroupOpen?: (group: Group) => boolean,
274-
groupKeyFn?: MaybeRefOrGetter<GroupKeyFn | undefined>,
274+
groupKeyFn?: MaybeRefOrGetter<GroupKeyFunction | undefined>,
275275
) {
276276
const groups = computed(() => {
277277
if (!groupBy.value.length) return []

0 commit comments

Comments
 (0)