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 new freeze function to component #2624

Merged
merged 18 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6cadf69
feat: Add new API endpoint for retrieving vertex order
anovazzi1 Jul 9, 2024
b10bd0c
feat: Refactor usePostRetrieveVertexOrder to improve code readability…
anovazzi1 Jul 10, 2024
9d2c8d5
feat: Add FreezeAllSvg component for displaying a freeze all icon
anovazzi1 Jul 10, 2024
f73f137
feat: Add freezeMultipleNodes method to FlowStoreType
anovazzi1 Jul 10, 2024
cb8ac2d
feat: Update freezeMultipleNodes to use updateFreezeStatus and update…
anovazzi1 Jul 10, 2024
7efb65e
feat: Update FreezeAllSvg component to use currentColor for fill
anovazzi1 Jul 10, 2024
beaa8a6
feat: Add freezeAll shortcut and component
anovazzi1 Jul 10, 2024
17c6c7b
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 10, 2024
302a75e
feat: Refactor get_vertex method to include silent parameter
ogabrielluiz Jul 10, 2024
d618e3e
feat: check if parent vertex is frozen and cache children
ogabrielluiz Jul 10, 2024
0974e5c
feat: change ungroup_node function to add frozen status to nodes
ogabrielluiz Jul 10, 2024
0f2b705
Refactor code to check if parent vertex is frozen before caching chil…
ogabrielluiz Jul 12, 2024
af5f44d
feat: Rename "Freeze All" to "Freeze Path" in shortcuts and components
anovazzi1 Jul 12, 2024
ec2d7c9
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 12, 2024
dfacd55
fix: refactor get_vertex method to handle silent parameter
ogabrielluiz Jul 12, 2024
30e9ef4
fix(base.py): remove unnecessary silent parameter in get_vertex metho…
ogabrielluiz Jul 12, 2024
72c6247
Added new freezeAll icon
lucaseduoli Jul 16, 2024
b17246a
refactor: add default value for 'frozen' in ungroup_node function
ogabrielluiz Jul 16, 2024
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
5 changes: 3 additions & 2 deletions src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def _validate_vertex(self, vertex: Vertex) -> bool:
# All vertices that do not have edges are invalid
return len(self.get_vertex_edges(vertex.id)) > 0

def get_vertex(self, vertex_id: str) -> Vertex:
def get_vertex(self, vertex_id: str, silent: bool = False) -> Vertex:
"""Returns a vertex by id."""
try:
return self.vertex_map[vertex_id]
Expand Down Expand Up @@ -869,7 +869,8 @@ async def build_vertex(
self.run_manager.add_to_vertices_being_run(vertex_id)
try:
params = ""
if vertex.frozen:
parent_vertex = self.get_vertex(vertex.parent_node_id) if vertex.parent_node_id else None
if vertex.frozen or (parent_vertex and parent_vertex.frozen):
# Check the cache for the vertex
cached_result = await chat_service.get_cache(key=vertex.id)
if isinstance(cached_result, CacheMiss):
Expand Down
16 changes: 13 additions & 3 deletions src/backend/base/langflow/graph/graph/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import List, Dict
import copy
from collections import deque

from typing import Dict, List

PRIORITY_LIST_OF_INPUTS = ["webhook", "chat"]

Expand Down Expand Up @@ -38,14 +37,25 @@ def add_parent_node_id(nodes, parent_node_id):
node["parent_node_id"] = parent_node_id


def add_frozen(nodes, frozen):
"""
This function receives a list of nodes and adds a frozen to each node.
"""
for node in nodes:
node["frozen"] = frozen


def ungroup_node(group_node_data, base_flow):
template, flow = (
template, flow, frozen = (
group_node_data["node"]["template"],
group_node_data["node"]["flow"],
group_node_data["node"].get("frozen", False),
)
parent_node_id = group_node_data["id"]

g_nodes = flow["data"]["nodes"]
add_parent_node_id(g_nodes, parent_node_id)
add_frozen(g_nodes, frozen)
g_edges = flow["data"]["edges"]

# Redirect edges to the correct proxy node
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@ export const defaultShortcuts = [
name: "Freeze",
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + F`,
},
{
name: "Freeze Path",
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + Shift + F`,
},
{
name: "Flow Share",
shortcut: `${IS_MAC ? "Cmd" : "Ctrl"} + B`,
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/controllers/API/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const URLs = {
VERSION: `version`,
MESSAGES: `monitor/messages`,
STORE: `store`,
BUILD: `build`,
} as const;

export function getURL(key: keyof typeof URLs, params: any = {}) {
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/controllers/API/queries/vertex/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./use-post-retrieve-vertex-order";
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { useMutationFunctionType } from "@/types/api";
import { AxiosRequestConfig } from "axios";
import { ReactFlowJsonObject } from "reactflow";
import { api } from "../../api";
import { getURL } from "../../helpers/constants";
import { UseRequestProcessor } from "../../services/request-processor";

interface retrieveGetVerticesOrder {
flowId: string;
data?: ReactFlowJsonObject;
stopNodeId?: string;
startNodeId?: string;
}

interface retrieveGetVerticesOrderResponse {
ids: string[];
rund_id: string;
vertices_to_run: string[];
}

// add types for error handling and success
export const usePostRetrieveVertexOrder: useMutationFunctionType<
retrieveGetVerticesOrder,
retrieveGetVerticesOrderResponse
> = (options) => {
const { mutate } = UseRequestProcessor();

const postRetrieveVertexOrder = async ({
flowId,
data: flow,
startNodeId,
stopNodeId,
}: retrieveGetVerticesOrder): Promise<retrieveGetVerticesOrderResponse> => {
// nodeId is optional and is a query parameter
// if nodeId is not provided, the API will return all vertices
const config: AxiosRequestConfig<any> = {};
if (stopNodeId) {
config["params"] = { stop_component_id: decodeURIComponent(stopNodeId) };
} else if (startNodeId) {
config["params"] = {
start_component_id: decodeURIComponent(startNodeId),
};
}
const data = {
data: {},
};
if (flow && flow.nodes && flow.edges) {
const { nodes, edges } = flow;
data["data"]["nodes"] = nodes;
data["data"]["edges"] = edges;
}
const response = await api.post(
`${getURL("BUILD")}/${flowId}/vertices`,
data,
config,
);

return response.data;
};

const mutation = mutate(
["usePostRetrieveVertexOrder"],
postRetrieveVertexOrder,
options,
);

return mutation;
};
46 changes: 46 additions & 0 deletions src/frontend/src/icons/freezeAll/freezeAll.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const FreezeAllSvg = (props) => {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
version="1.2"
viewBox="0 0 24 24"
className="h-4 w-4 stroke-[1.5]"
>
<title>snowflake-svg</title>
<path
id="Layer copy"
className="fill-none stroke-current"
d="m6 22.3l-4.4-4.4 4.4-4.3"
/>
<path id="Layer" className="fill-none stroke-current" d="m11 17.9h-9.4" />
<path id="Layer" className="fill-none stroke-current" d="m7.8 8.9h14.6" />
<path
id="Layer"
className="fill-none stroke-current"
d="m15.1 1.6v14.6"
/>
<path
id="Layer"
className="fill-none stroke-current"
d="m21 11.8l-2.9-2.9 2.9-2.9"
/>
<path
id="Layer"
className="fill-none stroke-current"
d="m9.3 6l2.9 2.9-2.9 2.9"
/>
<path
id="Layer"
className="fill-none stroke-current"
d="m18.1 3.1l-3 2.9-2.9-2.9"
/>
<path
id="Layer"
className="fill-none stroke-current"
d="m12.2 14.8l2.9-3 3 3"
/>
</svg>
);
};

export default FreezeAllSvg;
10 changes: 10 additions & 0 deletions src/frontend/src/icons/freezeAll/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { forwardRef } from "react";
import SvgFreezeAll from "./freezeAll";
("./freezeAll.jsx");

export const freezeAllIcon = forwardRef<
SVGSVGElement,
React.PropsWithChildren<{}>
>((props, ref) => {
return <SvgFreezeAll ref={ref} {...props} />;
});
Loading
Loading