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

feat: add cache icons for cached tasks in graph view #400

Merged
merged 2 commits into from
Apr 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const useStyles = makeStyles((theme: Theme) => {
position: 'relative',
},
detailsContainer: {
alignItems: 'center',
alignItems: 'start',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Maybe it's only me, but I feel like icon should go 1-2 px lower, to align better with text (as it mainly uses lower case naming), plus it looks like in cases when cache icon present right margin after the icon should become smaller for 2px too.
Screen Shot 2022-04-18 at 12 32 29 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added 1px margin top in customNodeComponents.tsx, where the icon styles are defined

display: 'flex',
flex: '0 1 auto',
paddingTop: theme.spacing(3),
Expand Down
15 changes: 0 additions & 15 deletions src/components/flytegraph/Graph.tsx

This file was deleted.

25 changes: 24 additions & 1 deletion src/components/flytegraph/ReactFlow/customNodeComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as React from 'react';
import { useState, useEffect } from 'react';
import { Handle, Position } from 'react-flow-renderer';
import { dTypes } from 'models/Graph/types';
import CachedOutlined from '@material-ui/icons/CachedOutlined';
import { CatalogCacheStatus } from 'models/Execution/enums';
import { PublishedWithChangesOutlined } from 'components/common/PublishedWithChanges';
import {
COLOR_TASK_TYPE,
COLOR_GRAPH_BACKGROUND,
Expand Down Expand Up @@ -226,6 +229,12 @@ export const ReactFlowCustomTaskNode = ({ data }: any) => {
padding: '.1rem .2rem',
fontSize: '.3rem',
};
const cacheIconStyles: React.CSSProperties = {
width: '8px',
height: '8px',
marginLeft: '4px',
color: COLOR_GRAPH_BACKGROUND,
};

const handleClick = (_e) => {
setSelectedNode(true);
Expand All @@ -238,10 +247,24 @@ export const ReactFlowCustomTaskNode = ({ data }: any) => {
</div>
);
};

const renderCacheIcon = (cacheStatus) => {
if (cacheStatus === CatalogCacheStatus.CACHE_HIT) {
return <CachedOutlined style={cacheIconStyles} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: switch could be a better choice from readability perspective

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrote it in switch this morning, but then decided to use ifs 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

}
if (cacheStatus === CatalogCacheStatus.CACHE_POPULATED) {
return <PublishedWithChangesOutlined style={cacheIconStyles} />;
}
return null;
};

return (
<div onClick={handleClick}>
{data.taskType ? renderTaskType() : null}
<div style={styles}>{data.text}</div>
<div style={styles}>
{data.text}
{renderCacheIcon(data.cacheStatus)}
</div>
{renderDefaultHandles(
data.scopedId,
getGraphHandleStyle('source'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dEdge, dNode, dTypes } from 'models/Graph/types';
import { Edge, Node, Position } from 'react-flow-renderer';
import { NodeExecutionPhase } from 'models/Execution/enums';
import { CatalogCacheStatus, NodeExecutionPhase } from 'models/Execution/enums';
import { createDebugLogger } from 'common/log';
import { ReactFlowGraphConfig } from './utils';
import { ConvertDagProps } from './types';
Expand Down Expand Up @@ -77,13 +77,18 @@ export const buildReactFlowDataProps = (props: BuildDataProps) => {
};
const nodeExecutionStatus = mapNodeExecutionStatus();

const cacheStatus: CatalogCacheStatus =
nodeExecutionsById[node.scopedId]?.closure.taskNodeMetadata?.cacheStatus ??
CatalogCacheStatus.CACHE_DISABLED;

const dataProps = {
nodeExecutionStatus: nodeExecutionStatus,
nodeExecutionStatus,
text: displayName,
handles: [],
nodeType: node.type,
scopedId: node.scopedId,
taskType: taskType,
taskType,
cacheStatus,
onNodeSelectionChanged: () => {
if (onNodeSelectionChanged) {
onNodeSelectionChanged([node.scopedId]);
Expand Down
2 changes: 2 additions & 0 deletions src/components/flytegraph/ReactFlow/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CatalogCacheStatus } from 'models/Execution/enums';
import { NodeExecutionsById } from 'models/Execution/types';
import { dNode, dTypes } from 'models/Graph/types';
import { HandleProps } from 'react-flow-renderer';
Expand Down Expand Up @@ -72,6 +73,7 @@ export interface RFCustomData {
scopedId: string;
dag: any;
taskType?: dTypes;
cacheStatus?: CatalogCacheStatus;
onNodeSelectionChanged?: any;
onAddNestedView: any;
onRemoveNestedView: any;
Expand Down
2 changes: 2 additions & 0 deletions src/components/flytegraph/ReactFlow/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export const getGraphNodeStyle = (
width: 'auto',
zIndex: 100000,
position: 'relative',
display: 'flex',
alignItems: 'center',
};

const nestedPoint = {
Expand Down