Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyterlab Workflows frontend plugin initial commit #526

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist
coverage
**/*.d.ts
tests
lib

**/__tests__
ui-tests
27 changes: 22 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"@emotion/styled": "^11.10.4",
"@jupyterlab/application": "^4",
"@jupyterlab/apputils": "^4",
"@jupyterlab/codeeditor": "^4",
"@jupyterlab/codemirror": "^4",
"@jupyterlab/coreutils": "^6",
"@jupyterlab/filebrowser": "^4",
"@jupyterlab/launcher": "^4",
Expand All @@ -72,21 +74,35 @@
"@mui/icons-material": "^5.10.9",
"@mui/material": "^5.10.6",
"@mui/system": "^5.10.6",
"@mui/x-date-pickers": "^6.19.3",
"@types/react-dom": "^18.0.5",
"cronstrue": "^2.12.0",
"elkjs": "^0.9.1",
"email-validator": "^2.0.4",
"lodash": "^4.17.21",
"moment": "^2.30.1",
"nanoid": "^3.3.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tzdata": "^1.0.33"
"react-hook-form": "^7.50.1",
"react-resizable-panels": "^2.0.9",
"react-router-dom": "^6.22.0",
"react-show-more-text": "^1.7.1",
"reactflow": "^11.10.3",
"tzdata": "^1.0.33",
"zustand": "^4.5.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@jupyterlab/builder": "^4",
"@jupyterlab/testutils": "^4",
"@types/jest": "^29",
"@typescript-eslint/eslint-plugin": "^4.8.1",
"@typescript-eslint/parser": "^4.8.1",
"eslint": "^7.14.0",
"@types/lodash": "4.14.192",
"@types/react-show-more-text": "^1.4.5",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^29",
Expand All @@ -100,7 +116,8 @@
"stylelint-config-standard": "~24.0.0",
"stylelint-prettier": "^2.0.0",
"ts-jest": "^29",
"typescript": "~4.3.0"
"typescript": "~5.1.6",
"zustand-types": "^0.1.0"
},
"resolutions": {
"@types/react": "^17.0.1",
Expand Down
10 changes: 10 additions & 0 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"command": "scheduling:create-from-filebrowser",
"selector": ".jp-DirListing-item[data-file-type=\"notebook\"]",
"rank": 3.9
},
{
"command": "workflows:create-from-filebrowser",
"selector": ".jp-DirListing-item[data-file-type=\"notebook\"]",
"rank": 4
}
]
},
Expand All @@ -17,6 +22,11 @@
"name": "create-job",
"command": "scheduling:create-from-notebook",
"rank": 46
},
{
"name": "create-workflow",
"command": "workflows:create-from-notebook",
"rank": 47
}
]
},
Expand Down
102 changes: 102 additions & 0 deletions src/dag-scheduler/components/advanced-table/advanced-table-header.tsx
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>
);
}
Loading
Loading