-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workflow versions table (#193)
Signed-off-by: csirius <[email protected]>
- Loading branch information
Showing
11 changed files
with
383 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Typography } from '@material-ui/core'; | ||
import { makeStyles, Theme } from '@material-ui/core/styles'; | ||
import { contentMarginGridUnits } from 'common/layout'; | ||
import { WaitForData } from 'components/common/WaitForData'; | ||
import { useWorkflowExecutionFiltersState } from 'components/Executions/filters/useExecutionFiltersState'; | ||
import { WorkflowVersionsTable } from 'components/Executions/Tables/WorkflowVersionsTable'; | ||
import { isLoadingState } from 'components/hooks/fetchMachine'; | ||
import { useWorkflowVersions } from 'components/hooks/useWorkflowVersions'; | ||
import { interactiveTextColor } from 'components/Theme/constants'; | ||
import { SortDirection } from 'models/AdminEntity/types'; | ||
import { ResourceIdentifier } from 'models/Common/types'; | ||
import { executionSortFields } from 'models/Execution/constants'; | ||
import * as React from 'react'; | ||
import { executionFilterGenerator } from './generators'; | ||
import { WorkflowVersionsTablePageSize } from './constants'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
headerContainer: { | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
marginLeft: theme.spacing(contentMarginGridUnits), | ||
marginRight: theme.spacing(contentMarginGridUnits) | ||
}, | ||
header: { | ||
marginBottom: theme.spacing(1) | ||
}, | ||
viewAll: { | ||
color: interactiveTextColor, | ||
cursor: 'pointer' | ||
} | ||
})); | ||
|
||
export interface EntityVersionsProps { | ||
id: ResourceIdentifier; | ||
} | ||
|
||
/** | ||
* The tab/page content for viewing a workflow's versions. | ||
* @param id | ||
*/ | ||
export const EntityVersions: React.FC<EntityVersionsProps> = ({ id }) => { | ||
const { domain, project, resourceType } = id; | ||
const styles = useStyles(); | ||
const filtersState = useWorkflowExecutionFiltersState(); | ||
const sort = { | ||
key: executionSortFields.createdAt, | ||
direction: SortDirection.DESCENDING | ||
}; | ||
|
||
const baseFilters = React.useMemo( | ||
() => executionFilterGenerator[resourceType](id), | ||
[id] | ||
); | ||
|
||
const versions = useWorkflowVersions( | ||
{ domain, project }, | ||
{ | ||
sort, | ||
filter: [...baseFilters, ...filtersState.appliedFilters], | ||
limit: WorkflowVersionsTablePageSize | ||
} | ||
); | ||
|
||
/** Don't render component until finish fetching user profile */ | ||
if (filtersState.filters[4].status !== 'LOADED') { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={styles.headerContainer}> | ||
<Typography className={styles.header} variant="h6"> | ||
Recent Workflow Versions | ||
</Typography> | ||
<Typography className={styles.viewAll} variant="body1"> | ||
View All | ||
</Typography> | ||
</div> | ||
<WaitForData {...versions}> | ||
<WorkflowVersionsTable | ||
{...versions} | ||
isFetching={isLoadingState(versions.state)} | ||
/> | ||
</WaitForData> | ||
</> | ||
); | ||
}; |
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,66 @@ | ||
import { makeStyles, Theme } from '@material-ui/core'; | ||
import classnames from 'classnames'; | ||
import * as React from 'react'; | ||
import { ListRowProps } from 'react-virtualized'; | ||
import { Workflow } from 'models/Workflow/types'; | ||
import { useExecutionTableStyles } from './styles'; | ||
import { | ||
WorkflowExecutionsTableState, | ||
WorkflowVersionColumnDefinition | ||
} from './types'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
row: { | ||
paddingLeft: theme.spacing(2) | ||
} | ||
})); | ||
|
||
export interface WorkflowVersionRowProps extends Partial<ListRowProps> { | ||
columns: WorkflowVersionColumnDefinition[]; | ||
workflow: Workflow; | ||
state: WorkflowExecutionsTableState; | ||
} | ||
|
||
/** | ||
* Renders a single `Workflow` record as a row. Designed to be used as a child | ||
* of `WorkflowVersionsTable`. | ||
* @param columns | ||
* @param workflow | ||
* @param state | ||
* @param style | ||
* @constructor | ||
*/ | ||
export const WorkflowVersionRow: React.FC<WorkflowVersionRowProps> = ({ | ||
columns, | ||
workflow, | ||
state, | ||
style | ||
}) => { | ||
const tableStyles = useExecutionTableStyles(); | ||
const styles = useStyles(); | ||
|
||
return ( | ||
<div | ||
className={classnames( | ||
tableStyles.row, | ||
styles.row, | ||
tableStyles.borderBottom | ||
)} | ||
style={style} | ||
> | ||
<div className={tableStyles.rowColumns}> | ||
{columns.map(({ className, key: columnKey, cellRenderer }) => ( | ||
<div | ||
key={columnKey} | ||
className={classnames(tableStyles.rowColumn, className)} | ||
> | ||
{cellRenderer({ | ||
workflow, | ||
state | ||
})} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
src/components/Executions/Tables/WorkflowVersionsTable.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,63 @@ | ||
import * as classnames from 'classnames'; | ||
import { noWorkflowVersionsFoundString } from 'common/constants'; | ||
import { useCommonStyles } from 'components/common/styles'; | ||
import { ListProps } from 'components/common/types'; | ||
import { DataList, DataListRef } from 'components/Tables/DataList'; | ||
import { Workflow } from 'models/Workflow/types'; | ||
import * as React from 'react'; | ||
import { ListRowRenderer } from 'react-virtualized'; | ||
import { ExecutionsTableHeader } from './ExecutionsTableHeader'; | ||
import { useExecutionTableStyles } from './styles'; | ||
import { useWorkflowExecutionsTableState } from './useWorkflowExecutionTableState'; | ||
import { useWorkflowVersionsTableColumns } from './useWorkflowVersionsTableColumns'; | ||
import { WorkflowVersionRow } from './WorkflowVersionRow'; | ||
|
||
/** | ||
* Renders a table of WorkflowVersion records. | ||
* @param props | ||
* @constructor | ||
*/ | ||
export const WorkflowVersionsTable: React.FC<ListProps<Workflow>> = props => { | ||
const { value: workflows } = props; | ||
const state = useWorkflowExecutionsTableState(); | ||
const commonStyles = useCommonStyles(); | ||
const tableStyles = useExecutionTableStyles(); | ||
const listRef = React.useRef<DataListRef>(null); | ||
|
||
const columns = useWorkflowVersionsTableColumns(); | ||
|
||
const retry = () => props.fetch(); | ||
|
||
// Custom renderer to allow us to append error content to workflow versions which | ||
// are in a failed state | ||
const rowRenderer: ListRowRenderer = rowProps => { | ||
const workflow = workflows[rowProps.index]; | ||
return ( | ||
<WorkflowVersionRow | ||
{...rowProps} | ||
columns={columns} | ||
workflow={workflow} | ||
state={state} | ||
/> | ||
); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={classnames( | ||
tableStyles.tableContainer, | ||
commonStyles.flexFill | ||
)} | ||
> | ||
<ExecutionsTableHeader columns={columns} /> | ||
<DataList | ||
{...props} | ||
onRetry={retry} | ||
noRowsContent={noWorkflowVersionsFoundString} | ||
moreItemsAvailable={false} | ||
ref={listRef} | ||
rowContentRenderer={rowRenderer} | ||
/> | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.