Skip to content

Commit

Permalink
feat: add empty state for empty page filters apllied on resource expl…
Browse files Browse the repository at this point in the history
…orer
  • Loading branch information
shavidze committed Oct 16, 2023
1 parent 6215b4c commit 06b5c1a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 34 deletions.
3 changes: 2 additions & 1 deletion dashboard/components/empty-state/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type Poses =
| 'shirt'
| 'whiteboard'
| 'thinking'
| 'working';
| 'working'
| 'tablet';

export type EmptyStateProps = {
title: string;
Expand Down
86 changes: 53 additions & 33 deletions dashboard/components/explorer/DependencyGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useState, memo } from 'react';
import React, { useState, memo, useEffect } from 'react';
import CytoscapeComponent from 'react-cytoscapejs';
import Cytoscape, { EventObject } from 'cytoscape';
import popper from 'cytoscape-popper';
Expand All @@ -12,6 +12,8 @@ import nodeHtmlLabel, {
// @ts-ignore
import COSEBilkent from 'cytoscape-cose-bilkent';

import EmptyState from '@components/empty-state/EmptyState';

import Tooltip from '@components/tooltip/Tooltip';
import WarningIcon from '@components/icons/WarningIcon';
import { ReactFlowData } from './hooks/useDependencyGraph';
Expand All @@ -36,6 +38,8 @@ Cytoscape.use(popper);
const DependencyGraph = ({ data }: DependencyGraphProps) => {
const [initDone, setInitDone] = useState(false);

const dataIsEmpty: boolean = data.nodes.length === 0;

// Type technically is Cytoscape.EdgeCollection but that throws an unexpected error
const loopAnimation = (eles: any) => {
const ani = eles.animation(edgeAnimationConfig[0], edgeAnimationConfig[1]);
Expand Down Expand Up @@ -122,39 +126,55 @@ const DependencyGraph = ({ data }: DependencyGraphProps) => {

return (
<div className="relative h-full flex-1 bg-dependency-graph bg-[length:40px_40px]">
<CytoscapeComponent
className="h-full w-full"
elements={CytoscapeComponent.normalizeElements({
nodes: data.nodes,
edges: data.edges
})}
maxZoom={maxZoom}
minZoom={minZoom}
layout={graphLayoutConfig}
stylesheet={[
{
selector: 'node',
style: nodeStyeConfig
},
{
selector: 'edge',
style: edgeStyleConfig
},
{
selector: '.leaf',
style: leafStyleConfig
}
]}
cy={(cy: Cytoscape.Core) => cyActionHandlers(cy)}
/>
<div className="absolute bottom-0 left-0 flex gap-2 overflow-visible overflow-visible bg-black-100 text-black-400">
{dataIsEmpty ? (
<>
<div className="translate-y-[201px]">
<EmptyState
title="No results for this filter"
message="It seems like you have no cloud resources matching the filters you added"
mascotPose="tablet"
/>
</div>
</>
) : (
<>
<CytoscapeComponent
className="h-full w-full"
elements={CytoscapeComponent.normalizeElements({
nodes: data.nodes,
edges: data.edges
})}
maxZoom={maxZoom}
minZoom={minZoom}
layout={graphLayoutConfig}
stylesheet={[
{
selector: 'node',
style: nodeStyeConfig
},
{
selector: 'edge',
style: edgeStyleConfig
},
{
selector: '.leaf',
style: leafStyleConfig
}
]}
cy={(cy: Cytoscape.Core) => cyActionHandlers(cy)}
/>
</>
)}
<div className="absolute bottom-0 left-0 flex gap-2 overflow-visible bg-black-100 text-black-400">
{data?.nodes?.length} Resources
<div className="relative">
<WarningIcon className="peer" height="16" width="16" />
<Tooltip bottom="xs" align="left" width="lg">
Only AWS resources are currently supported on the explorer.
</Tooltip>
</div>
{!dataIsEmpty && (
<div className="relative">
<WarningIcon className="peer" height="16" width="16" />
<Tooltip bottom="xs" align="left" width="lg">
Only AWS resources are currently supported on the explorer.
</Tooltip>
</div>
)}
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "next build && next export",
"start": "next start -p 3002",
"lint": "next lint",
"format": "prettier --write \"**/*.{ts,tsx,json,css,scss,md}\"",
"prepare": "cd .. && husky install dashboard/.husky",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
Expand Down

0 comments on commit 06b5c1a

Please sign in to comment.