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

fix: prevents collapsing of execution errors when scrolled out of view #80

Merged
merged 3 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 });
schottra marked this conversation as resolved.
Show resolved Hide resolved
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