Skip to content

Commit

Permalink
feat: add cache icons for cached tasks in graph view (#400)
Browse files Browse the repository at this point in the history
* feat: add cache icons for cached tasks in graph view

Signed-off-by: Olga Nad <olga@union.ai>
  • Loading branch information
olga-union authored Apr 18, 2022
1 parent e060056 commit 0c0cd4b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
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',
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.

27 changes: 26 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,13 @@ export const ReactFlowCustomTaskNode = ({ data }: any) => {
padding: '.1rem .2rem',
fontSize: '.3rem',
};
const cacheIconStyles: React.CSSProperties = {
width: '8px',
height: '8px',
marginLeft: '4px',
marginTop: '1px',
color: COLOR_GRAPH_BACKGROUND,
};

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

const renderCacheIcon = (cacheStatus) => {
switch (cacheStatus) {
case CatalogCacheStatus.CACHE_HIT:
return <CachedOutlined style={cacheIconStyles} />;
case CatalogCacheStatus.CACHE_POPULATED:
return <PublishedWithChangesOutlined style={cacheIconStyles} />;
default:
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

0 comments on commit 0c0cd4b

Please sign in to comment.