-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jupyterlab Workflows frontend plugin initial commit (#526)
* Jupyterlab Workflows frontend plugin initial commit * Fix minor UI issues and refactor duplicate styled components --------- Co-authored-by: Sathish Kumar Thangaraj <[email protected]>
- Loading branch information
1 parent
7cf42f9
commit 3ae5e3f
Showing
102 changed files
with
19,902 additions
and
5,300 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ dist | |
coverage | ||
**/*.d.ts | ||
tests | ||
lib | ||
|
||
**/__tests__ | ||
ui-tests |
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
102 changes: 102 additions & 0 deletions
102
src/dag-scheduler/components/advanced-table/advanced-table-header.tsx
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,102 @@ | ||
import React from 'react'; | ||
import { caretDownIcon, caretUpIcon, LabIcon } from '@jupyterlab/ui-components'; | ||
import TableHead from '@mui/material/TableHead'; | ||
import TableCell from '@mui/material/TableCell'; | ||
|
||
import { AdvancedTableColumn, AdvancedTableQuery } from './advanced-table'; | ||
import { Scheduler } from '../../handler'; | ||
|
||
type AdvancedTableHeaderProps<Q extends AdvancedTableQuery> = { | ||
columns: AdvancedTableColumn[]; | ||
query: Q; | ||
setQuery: React.Dispatch<React.SetStateAction<Q>>; | ||
}; | ||
|
||
export function AdvancedTableHeader<Q extends AdvancedTableQuery>( | ||
props: AdvancedTableHeaderProps<Q> | ||
): JSX.Element { | ||
return ( | ||
<TableHead> | ||
{props.columns.map((column, idx) => ( | ||
<AdvancedTableHeaderCell | ||
key={idx} | ||
column={column} | ||
query={props.query} | ||
setQuery={props.setQuery} | ||
/> | ||
))} | ||
</TableHead> | ||
); | ||
} | ||
|
||
const sortAscendingIcon = ( | ||
<LabIcon.resolveReact icon={caretUpIcon} tag="span" /> | ||
); | ||
const sortDescendingIcon = ( | ||
<LabIcon.resolveReact icon={caretDownIcon} tag="span" /> | ||
); | ||
|
||
type AdvancedTableHeaderCellProps<Q extends AdvancedTableQuery> = Pick< | ||
AdvancedTableHeaderProps<Q>, | ||
'query' | 'setQuery' | ||
> & { | ||
column: AdvancedTableColumn; | ||
}; | ||
|
||
function AdvancedTableHeaderCell<Q extends AdvancedTableQuery>( | ||
props: AdvancedTableHeaderCellProps<Q> | ||
): JSX.Element { | ||
const sort = props.query.sort_by; | ||
const defaultSort = sort?.[0]; | ||
|
||
const headerIsDefaultSort = | ||
defaultSort && defaultSort.name === props.column.sortField; | ||
const isSortedAscending = | ||
headerIsDefaultSort && | ||
defaultSort && | ||
defaultSort.direction === Scheduler.SortDirection.ASC; | ||
const isSortedDescending = | ||
headerIsDefaultSort && | ||
defaultSort && | ||
defaultSort.direction === Scheduler.SortDirection.DESC; | ||
|
||
const sortByThisColumn = () => { | ||
// If this field is not sortable, do nothing. | ||
if (!props.column.sortField) { | ||
return; | ||
} | ||
|
||
// Change the sort of this column. | ||
// If not sorted at all or if sorted descending, sort ascending. If sorted ascending, sort descending. | ||
const newSortDirection = isSortedAscending | ||
? Scheduler.SortDirection.DESC | ||
: Scheduler.SortDirection.ASC; | ||
|
||
// Set the new sort direction. | ||
const newSort: Scheduler.ISortField = { | ||
name: props.column.sortField, | ||
direction: newSortDirection | ||
}; | ||
|
||
// If this field is already present in the sort list, remove it. | ||
const oldSortList = sort || []; | ||
const newSortList = [ | ||
newSort, | ||
...oldSortList.filter(item => item.name !== props.column.sortField) | ||
]; | ||
|
||
// Sub the new sort list in to the query. | ||
props.setQuery(query => ({ ...query, sort_by: newSortList })); | ||
}; | ||
|
||
return ( | ||
<TableCell | ||
onClick={sortByThisColumn} | ||
sx={props.column.sortField ? { cursor: 'pointer' } : {}} | ||
> | ||
{props.column.name} | ||
{isSortedAscending && sortAscendingIcon} | ||
{isSortedDescending && sortDescendingIcon} | ||
</TableCell> | ||
); | ||
} |
Oops, something went wrong.