MCPcopy Index your code
hub / github.com/primer/react / getInitialSortState

Function getInitialSortState

packages/react/src/DataTable/useTable.ts:213–282  ·  view source on GitHub ↗
(
  columns: Array<Column<Data>>,
  initialSortColumn?: string | number,
  initialSortDirection?: Exclude<SortDirection, 'NONE'>,
)

Source from the content-addressed store, hash-verified

211}
212
213function getInitialSortState<Data extends UniqueRow>(
214 columns: Array<Column<Data>>,
215 initialSortColumn?: string | number,
216 initialSortDirection?: Exclude<SortDirection, 'NONE'>,
217) {
218 if (initialSortColumn !== undefined) {
219 const column = columns.find(column => {
220 return column.id === initialSortColumn || column.field === initialSortColumn
221 })
222
223 if (column === undefined) {
224 if (__DEV__) {
225 // eslint-disable-next-line no-console
226 console.warn(
227 `Warning: Unable to find a column with id or field set to: ${initialSortColumn}. Please provide a value to \`initialSortColumn\` which corresponds to a \`id\` or \`field\` value in a column.`,
228 )
229 }
230 return null
231 }
232
233 if (column.sortBy === false || column.sortBy === undefined) {
234 if (__DEV__) {
235 // eslint-disable-next-line no-console
236 console.warn(
237 `Warning: The column specified by initialSortColumn={${initialSortColumn}} is not sortable. Please set \`sortBy\` to true or provide a sort strategy.`,
238 )
239 }
240 return null
241 }
242
243 return {
244 id: `${initialSortColumn}`,
245 direction: initialSortDirection ?? DEFAULT_SORT_DIRECTION,
246 }
247 }
248
249 if (initialSortDirection !== undefined) {
250 const column = columns.find(column => {
251 return column.sortBy !== false && column.sortBy !== undefined
252 })
253
254 if (!column) {
255 if (__DEV__) {
256 // eslint-disable-next-line no-console
257 console.warn(
258 `Warning: An initialSortDirection value was provided but no columns are sortable. Please set \`sortBy\` to true or provide a sort strategy to a column.`,
259 )
260 }
261 return null
262 }
263
264 const id = column.id ?? column.field
265 if (id === undefined) {
266 if (__DEV__) {
267 // eslint-disable-next-line no-console
268 console.warn(
269 `Warning: Unable to find an \`id\` or \`field\` for the column: ${column}. Please set one of these properties on the column.`,
270 )

Callers 1

useTableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected