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: Resource associations visualization #243

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -64,11 +64,11 @@ const createEdgesFromEnvironmentToDeployments = (
}));

const createEdgesFromDeploymentsToResources = (relationships: Relationships) =>
relationships.map((resource) => {
relationships.nodes.map((resource) => {
const { parent } = resource;
if (parent == null) return null;

const allReleaseJobTriggers = relationships
const allReleaseJobTriggers = relationships.nodes
.flatMap((r) => r.workspace.systems)
.flatMap((s) => s.environments)
.flatMap((e) => e.latestActiveReleases)
Expand All @@ -93,26 +93,48 @@ const createEdgesFromDeploymentsToResources = (relationships: Relationships) =>
});

export const getEdges = (relationships: Relationships) => {
const resourceToEnvEdges = relationships.flatMap((r) =>
const resourceToEnvEdges = relationships.nodes.flatMap((r) =>
createEdgesFromResourceToEnvironments(
r,
r.workspace.systems.flatMap((s) => s.environments),
),
);
const environmentToDeploymentEdges = relationships.flatMap((r) =>
const environmentToDeploymentEdges = relationships.nodes.flatMap((r) =>
r.workspace.systems.flatMap((s) =>
createEdgesFromEnvironmentToDeployments(s.environments, s.deployments),
),
);
const providerEdges = relationships.flatMap((r) =>
const providerEdges = relationships.nodes.flatMap((r) =>
r.provider != null ? [createEdgeFromProviderToResource(r.provider, r)] : [],
);
const deploymentEdges = createEdgesFromDeploymentsToResources(relationships);

const { resource } = relationships;

const fromEdges = relationships.associations.from.map((r) => ({
id: `${r.resource.id}-${resource.id}`,
source: r.resource.id,
target: resource.id,
style: { stroke: colors.neutral[800] },
markerEnd,
label: r.type,
}));

const toEdges = relationships.associations.to.map((r) => ({
id: `${resource.id}-${r.resource.id}`,
source: resource.id,
target: r.resource.id,
style: { stroke: colors.neutral[800] },
markerEnd,
label: r.type,
}));

return [
...resourceToEnvEdges,
...environmentToDeploymentEdges,
...providerEdges,
...deploymentEdges,
...fromEdges,
...toEdges,
].filter(isPresent);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { Handle, Position } from "reactflow";
import { useEnvironmentDrawer } from "~/app/[workspaceSlug]/(app)/_components/environment-drawer/EnvironmentDrawer";

type Environment = NonNullable<
RouterOutputs["resource"]["relationships"][number]
>["workspace"]["systems"][number]["environments"][number];
RouterOutputs["resource"]["relationships"]
>["nodes"][number]["workspace"]["systems"][number]["environments"][number];

type EnvironmentNodeProps = NodeProps<{
label: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const nodeTypes: NodeTypes = {
};

const getResourceNodes = (relationships: Relationships) =>
relationships.map((r) => ({
relationships.nodes.map((r) => ({
id: r.id,
type: NodeType.Resource,
data: { ...r, label: r.identifier },
position: { x: 0, y: 0 },
}));

const getProviderNodes = (relationships: Relationships) =>
relationships
relationships.nodes
.map((r) =>
r.provider != null
? {
Expand All @@ -46,7 +46,7 @@ const getProviderNodes = (relationships: Relationships) =>
.filter(isPresent);

const getEnvironmentNodes = (relationships: Relationships) =>
relationships
relationships.nodes
.flatMap((r) => r.workspace.systems)
.flatMap((s) => s.environments.map((e) => ({ s, e })))
.map(({ s, e }) => ({
Expand All @@ -57,7 +57,7 @@ const getEnvironmentNodes = (relationships: Relationships) =>
}));

const getDeploymentNodes = (relationships: Relationships) =>
relationships.flatMap((r) =>
relationships.nodes.flatMap((r) =>
r.workspace.systems.flatMap((system) =>
system.environments.flatMap((environment) =>
system.deployments.map((deployment) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { notFound } from "next/navigation";

import { api } from "~/trpc/server";
import { ResourceVisualizationDiagramProvider } from "./ResourceVisualizationDiagram";

Expand All @@ -7,5 +9,6 @@ export default async function VisualizePage({
params: { targetId: string };
}) {
const relationships = await api.resource.relationships(targetId);
if (relationships == null) return notFound();
return <ResourceVisualizationDiagramProvider relationships={relationships} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { JobAgent } from "./JobAgent";
import { JobMetadata } from "./JobMetadata";
import { JobPropertiesTable } from "./JobProperties";
import { JobVariables } from "./JobVariables";
import { DependenciesDiagram } from "./RelationshipsDiagramDependencies";
import { useJobDrawer } from "./useJobDrawer";

export const JobDrawer: React.FC = () => {
Expand Down Expand Up @@ -128,13 +127,6 @@ export const JobDrawer: React.FC = () => {
<JobMetadata job={job} />
</div>
</div>

<DependenciesDiagram
targetId={job.resource.id}
relationships={job.relationships}
targets={job.relatedResources}
releaseDependencies={job.releaseDependencies}
/>
</div>
)}
</>
Expand Down

This file was deleted.

Loading
Loading