PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | js/components/ManageMenu/SnippetsTable/SnippetsListTable.tsx +19 -1 3.10.0 → 4.0.0-beta.2 View file →
@@ -11,9 +11,9 @@
11 11 import { getTableColumns } from './TableColumns'
12 12 import { useFilteredSnippets } from './WithFilteredSnippetsContext'
13 13 import { INDEX_STATUS, useSnippetsFilters } from './WithSnippetsTableFilters'
14 14 import { BULK_ACTIONS, TRASHED_BULK_ACTIONS, useApplyBulkAction } from './useApplyBulkAction'
15 -import type { ListTableAction } from '../../common/ListTable'
15 +import type { ListTableAction, ListTableSortDirection } from '../../common/ListTable'
16 16 import type { SnippetsTableAction } from './useApplyBulkAction'
17 17 import type { Snippet } from '../../../types/Snippet'
18 18 import type { SnippetView } from '../../../types/SnippetView'
19 19 import type { ReactNode } from 'react'
@@ -140,8 +140,9 @@
140 140 />
141 141 : <ListTable
142 142 items={snippets}
143 143 getKey={snippet => snippet.id}
144 + initialSort={getInitialSort()}
144 145 className={classnames({ 'truncate-row-values': truncateRowValues })}
145 146 columns={columns}
146 147 actions={actions}
147 148 doAction={doAction}
@@ -153,8 +154,25 @@
153 154 noItems={<NoItemsMessage />}
154 155 beforeTable={<SearchResultsIndicator />}
155 156 />
156 157 }
158 +
159 +/**
160 + * The "Snippets List Order" setting names a default ordering for the table,
161 + * which sorting is now expressed through columns. Map one to the other so the
162 + * setting still decides how the list opens; clicking a heading overrides it for
163 + * the rest of the visit, as it does for any other starting order.
164 + */
165 +const LIST_ORDER_SORTS: Record<string, { columnId: string, direction: ListTableSortDirection }> = {
166 + 'priority-asc': { columnId: 'priority', direction: 'asc' },
167 + 'name-asc': { columnId: 'name', direction: 'asc' },
168 + 'name-desc': { columnId: 'name', direction: 'desc' },
169 + 'modified-desc': { columnId: 'date', direction: 'desc' },
170 + 'modified-asc': { columnId: 'date', direction: 'asc' }
171 +}
172 +
173 +const getInitialSort = () =>
174 + LIST_ORDER_SORTS[window.CODE_SNIPPETS_MANAGE?.listOrder ?? ''] ?? undefined
157 175
158 176 export interface SnippetsListTableProps {
159 177 snippetView: SnippetView
160 178 setSnippetView: (view: SnippetView) => void