-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor experiment table header context menu (#4407)
- Loading branch information
1 parent
108f11b
commit 5b17f99
Showing
7 changed files
with
63 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 0 additions & 50 deletions
50
webview/src/experiments/components/table/header/TableHeader.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Header } from '@tanstack/react-table' | ||
import { SortDefinition } from 'dvc/src/experiments/model/sortBy' | ||
import { Experiment } from 'dvc/src/experiments/webview/contract' | ||
|
||
export enum SortOrder { | ||
ASCENDING = 'Sort Ascending', | ||
DESCENDING = 'Sort Descending', | ||
NONE = 'Remove Sort' | ||
} | ||
|
||
const possibleOrders = { | ||
false: SortOrder.ASCENDING, | ||
true: SortOrder.DESCENDING, | ||
undefined: SortOrder.NONE | ||
} as const | ||
|
||
export const isFromExperimentColumn = (header: Header<Experiment, unknown>) => | ||
header.column.id === 'id' || header.column.id.startsWith('id_placeholder') | ||
|
||
export const getSortDetails = ( | ||
header: Header<Experiment, unknown>, | ||
sorts: SortDefinition[] | ||
): { id: string; isSortable: boolean; sortOrder: SortOrder } => { | ||
const isNotExperiments = !isFromExperimentColumn(header) | ||
const isSortable = isNotExperiments && header.column.columns.length <= 1 | ||
const baseColumn = | ||
header.headerGroup.headers.find( | ||
h => h.column.id === header.placeholderId | ||
) || header.column | ||
const sort = sorts.find(sort => sort.path === baseColumn.id) | ||
|
||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions | ||
const sortOrder: SortOrder = possibleOrders[`${sort?.descending}`] | ||
|
||
return { id: baseColumn.id, isSortable, sortOrder } | ||
} |