Skip to content

Commit

Permalink
revert(console): map view (#6520)
Browse files Browse the repository at this point in the history
Revert Console's map view and the new SDK connections.
  • Loading branch information
skyrpex authored May 18, 2024
1 parent f6d1493 commit ac61766
Show file tree
Hide file tree
Showing 50 changed files with 1,154 additions and 2,803 deletions.
2 changes: 1 addition & 1 deletion apps/wing-console/console/design-system/src/row-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const RowInput = memo(
type === "checkbox" && [
theme.focusInput,
theme.bg4,
"w-4 h-4 dark:ring-offset-slate-800",
"w-4 h-4 dark:ring-offset-gray-800",
],
type === "date" &&
!value &&
Expand Down
134 changes: 111 additions & 23 deletions apps/wing-console/console/server/src/router/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,18 @@ export const createAppRouter = () => {
.input(
z.object({
edgeId: z.string(),
showTests: z.boolean().optional(),
}),
)
.query(async ({ ctx, input }) => {
const { edgeId } = input;
const { edgeId, showTests } = input;
const simulator = await ctx.simulator();

const { tree } = simulator.tree().rawData();
const nodeMap = buildConstructTreeNodeMap(shakeTree(tree));

let [, sourcePath, _sourceInflight, , targetPath, targetInflight] =
edgeId.match(/^(.+?)#(.*?)#(.*?)#(.+?)#(.*?)#(.*?)$/i) ?? [];

targetPath = targetPath?.startsWith("#")
? targetPath.slice(1)
: targetPath;
const sourcePath = edgeId.split("->")[0]?.trim();
const targetPath = edgeId.split("->")[1]?.trim();

const sourceNode = nodeMap.get(sourcePath);
if (!sourceNode) {
Expand All @@ -315,6 +312,39 @@ export const createAppRouter = () => {
});
}

const connections = simulator.connections();

const inflights = sourceNode.display?.hidden
? []
: connections
?.filter(({ source, target, name }) => {
if (!isFoundInPath(sourceNode, nodeMap, source, true)) {
return false;
}

if (!isFoundInPath(targetNode, nodeMap, target, true)) {
return false;
}

if (name === "$inflight_init()") {
return false;
}

if (
!showTests &&
(matchTest(sourceNode.path) || matchTest(targetNode.path))
) {
return false;
}

return true;
})
.map((connection) => {
return {
name: connection.name,
};
}) ?? [];

return {
source: {
id: sourceNode.id,
Expand All @@ -326,13 +356,7 @@ export const createAppRouter = () => {
path: targetNode?.path ?? "",
type: (targetNode && getResourceType(targetNode, simulator)) ?? "",
},
inflights: targetInflight
? [
{
name: targetInflight,
},
]
: [],
inflights,
};
}),
"app.invalidateQuery": createProcedure.subscription(({ ctx }) => {
Expand All @@ -351,17 +375,42 @@ export const createAppRouter = () => {
};
});
}),
"app.map": createProcedure.query(async ({ ctx }) => {
const simulator = await ctx.simulator();
"app.map": createProcedure
.input(
z
.object({
showTests: z.boolean().optional(),
})
.optional(),
)
.query(async ({ ctx, input }) => {
const simulator = await ctx.simulator();

const { tree } = simulator.tree().rawData();
const connections = simulator.connections();
const { tree } = simulator.tree().rawData();
const connections = simulator.connections();
const shakedTree = shakeTree(tree);
const nodeMap = buildConstructTreeNodeMap(shakedTree);
const nodes = [
createMapNodeFromConstructTreeNode(
shakedTree,
simulator,
input?.showTests,
),
];
const edges = uniqby(
createMapEdgesFromConnectionData(
nodeMap,
connections,
input?.showTests,
),
(edge) => edge.id,
);

return {
tree,
connections,
};
}),
return {
nodes,
edges,
};
}),
"app.state": createProcedure.query(async ({ ctx }) => {
return ctx.appState();
}),
Expand Down Expand Up @@ -542,6 +591,45 @@ export interface MapEdge {
target: string;
}

function createMapEdgesFromConnectionData(
nodeMap: ConstructTreeNodeMap,
connections: NodeConnection[],
showTests = false,
): MapEdge[] {
return [
...connections
.filter((connection) => {
return connectionsBasicFilter(connection, nodeMap, showTests);
})
?.map((connection: NodeConnection) => {
const source = getVisualNodePath(connection.source, nodeMap);
const target = getVisualNodePath(connection.target, nodeMap);
return {
id: `${source} -> ${target}`,
source,
target,
};
})
?.filter(({ source, target }) => {
// Remove redundant connections to a parent resource if there's already a connection to a child resource.
if (
connections.some((connection) => {
if (
connection.source === source &&
connection.target.startsWith(`${target}/`)
) {
return true;
}
})
) {
return false;
}

return true;
}),
].flat();
}

function getResourceType(
node: Node | ConstructTreeNode,
simulator: Simulator,
Expand Down
Loading

0 comments on commit ac61766

Please sign in to comment.