Skip to content

Commit

Permalink
fix: prevents collapsing of execution errors when scrolled out of view
Browse files Browse the repository at this point in the history
  • Loading branch information
schottra committed Jul 6, 2020
1 parent 2404a5a commit a61fee2
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 43 deletions.
6 changes: 4 additions & 2 deletions src/components/Executions/Tables/ExpandableExecutionError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { useExecutionTableStyles } from './styles';
*/
export const ExpandableExecutionError: React.FC<{
error: ExecutionError;
onExpandCollapse?(): void;
}> = ({ error, onExpandCollapse }) => {
initialExpansionState?: boolean;
onExpandCollapse?(expanded: boolean): void;
}> = ({ error, initialExpansionState = false, onExpandCollapse }) => {
const styles = useExecutionTableStyles();
return (
<div className={styles.errorContainer}>
<ExpandableMonospaceText
onExpandCollapse={onExpandCollapse}
initialExpansionState={initialExpansionState}
text={error.message}
/>
</div>
Expand Down
116 changes: 78 additions & 38 deletions src/components/Executions/Tables/WorkflowExecutionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import {
} from 'common/formatters';
import { timestampToDate } from 'common/utils';
import { DataList, DataListRef } from 'components';
import { getCacheKey } from 'components/Cache';
import { ListProps } from 'components/common';
import { useCommonStyles } from 'components/common/styles';
import { Execution } from 'models';
import { WorkflowExecutionPhase } from 'models/Execution/enums';
import * as React from 'react';
import { ListRowRenderer } from 'react-virtualized';
import { ListRowProps, ListRowRenderer } from 'react-virtualized';
import { ExecutionInputsOutputsModal } from '../ExecutionInputsOutputsModal';
import { ExecutionStatusBadge } from '../ExecutionStatusBadge';
import { getWorkflowExecutionTimingMS } from '../utils';
Expand Down Expand Up @@ -168,18 +169,80 @@ function generateColumns(
];
}

interface WorkflowExecutionRowProps extends ListRowProps {
columns: WorkflowExecutionColumnDefinition[];
errorExpanded: boolean;
execution: Execution;
onExpandCollapseError(expanded: boolean): void;
state: ReturnType<typeof useWorkflowExecutionsTableState>;
}

const WorkflowExecutionRow: React.FC<WorkflowExecutionRowProps> = ({
columns,
errorExpanded,
execution,
onExpandCollapseError,
state,
style
}) => {
const { error } = execution.closure;
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({
execution,
state
})}
</div>
))}
</div>
{error ? (
<ExpandableExecutionError
onExpandCollapse={onExpandCollapseError}
initialExpansionState={errorExpanded}
error={error}
/>
) : null}
</div>
);
};

export interface WorkflowExecutionsTableProps extends ListProps<Execution> {}

/** Renders a table of WorkflowExecution records. Executions with errors will
* have an expanadable container rendered as part of the table row.
*/
export const WorkflowExecutionsTable: React.FC<WorkflowExecutionsTableProps> = props => {
const executions = props.value;
const [expandedErrors, setExpandedErrors] = React.useState<
Dictionary<boolean>
>({});
const state = useWorkflowExecutionsTableState();
const commonStyles = useCommonStyles();
const styles = useStyles();
const tableStyles = useExecutionTableStyles();
const listRef = React.useRef<DataListRef>(null);

// Reset error expansion states whenever list changes
React.useEffect(() => {
setExpandedErrors({});
}, [executions]);

// Memoizing columns so they won't be re-generated unless the styles change
const columns = React.useMemo(() => generateColumns(styles, tableStyles), [
styles,
Expand All @@ -197,44 +260,21 @@ export const WorkflowExecutionsTable: React.FC<WorkflowExecutionsTableProps> = p
// Custom renderer to allow us to append error content to executions which
// are in a failed state
const rowRenderer: ListRowRenderer = rowProps => {
const { index: rowIndex, style } = rowProps;
const execution = executions[rowIndex];
const { error } = execution.closure;

const execution = executions[rowProps.index];
const cacheKey = getCacheKey(execution.id);
const onExpandCollapseError = (expanded: boolean) => {
setExpandedErrors({ ...expandedErrors, [cacheKey]: expanded });
recomputeRow(rowProps.index);
};
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({
execution,
state
})}
</div>
)
)}
</div>
{error ? (
<ExpandableExecutionError
onExpandCollapse={recomputeRow.bind(null, rowIndex)}
error={error}
/>
) : null}
</div>
<WorkflowExecutionRow
{...rowProps}
columns={columns}
execution={execution}
errorExpanded={!!expandedErrors[cacheKey]}
onExpandCollapseError={onExpandCollapseError}
state={state}
/>
);
};

Expand Down
8 changes: 5 additions & 3 deletions src/components/common/ExpandableMonospaceText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,24 @@ export const useExpandableMonospaceTextStyles = makeStyles((theme: Theme) => ({
}));

export interface ExpandableMonospaceTextProps {
initialExpansionState?: boolean;
text: string;
onExpandCollapse?(): void;
onExpandCollapse?(expanded: boolean): void;
}

/** An expandable/collapsible container which renders the provided text in a
* monospace font. It also provides a button to copy the text.
*/
export const ExpandableMonospaceText: React.FC<ExpandableMonospaceTextProps> = ({
onExpandCollapse,
initialExpansionState = false,
text
}) => {
const [expanded, setExpanded] = React.useState(false);
const [expanded, setExpanded] = React.useState(initialExpansionState);
const styles = useExpandableMonospaceTextStyles();
const onClickExpand = () => {
setExpanded(!expanded);
typeof onExpandCollapse === 'function' && onExpandCollapse();
typeof onExpandCollapse === 'function' && onExpandCollapse(!expanded);
};
const onClickCopy = () => copyToClipboard(text);

Expand Down

0 comments on commit a61fee2

Please sign in to comment.