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: resolve component update notification state persistence after dismissal #6032

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -11,6 +11,7 @@ import { track } from "@/customization/utils/analytics";
import { useDarkStore } from "@/stores/darkStore";
import useFlowStore from "@/stores/flowStore";
import { useShortcutsStore } from "@/stores/shortcuts";
import { useUtilityStore } from "@/stores/utilityStore";
import { VertexBuildTypeAPI } from "@/types/api";
import { NodeDataType } from "@/types/flow";
import { findLastNode } from "@/utils/reactflowUtils";
Expand All @@ -34,6 +35,7 @@ export default function NodeStatus({
isOutdated,
isUserEdited,
getValidationStatus,
handleUpdateComponent,
}: {
nodeId: string;
display_name: string;
Expand All @@ -46,6 +48,7 @@ export default function NodeStatus({
isOutdated: boolean;
isUserEdited: boolean;
getValidationStatus: (data) => VertexBuildTypeAPI | null;
handleUpdateComponent: () => void;
}) {
const nodeId_ = data.node?.flow?.data
? (findLastNode(data.node?.flow.data!)?.id ?? nodeId)
Expand Down Expand Up @@ -84,14 +87,18 @@ export default function NodeStatus({
getValidationStatus,
);

const dismissAll = useUtilityStore((state) => state.dismissAll);

const getBaseBorderClass = (selected) => {
let className =
selected && !isBuilding
? " border ring-[0.75px] ring-muted-foreground border-muted-foreground hover:shadow-node"
: "border ring-[0.5px] hover:shadow-node ring-border";
let frozenClass = selected ? "border-ring-frozen" : "border-frozen";
let updateClass =
isOutdated && !isUserEdited ? "border-warning ring-2 ring-warning" : "";
isOutdated && !isUserEdited && !dismissAll
? "border-warning ring-2 ring-warning"
: "";
return cn(frozen ? frozenClass : className, updateClass);
};
const getNodeBorderClassName = (
Expand Down Expand Up @@ -122,6 +129,7 @@ export default function NodeStatus({
isOutdated,
isUserEdited,
frozen,
dismissAll,
]);

useEffect(() => {
Expand Down Expand Up @@ -248,6 +256,36 @@ export default function NodeStatus({
)}
</div>
</ShadTooltip>
{dismissAll && isOutdated && !isUserEdited && (
<ShadTooltip content="Update component">
<div
className="button-run-bg hit-area-icon ml-1 bg-warning hover:bg-warning/80"
onClick={(e) => {
e.stopPropagation();
handleUpdateComponent();
e.stopPropagation();
}}
>
{showNode && (
<Button
unstyled
type="button"
onClick={(e) => e.preventDefault()}
>
<div
data-testid={`button_update_` + display_name.toLowerCase()}
>
<IconComponent
name={"AlertTriangle"}
strokeWidth={ICON_STROKE_WIDTH}
className="icon-size text-black"
/>
</div>
</Button>
)}
</div>
</ShadTooltip>
)}
</div>
</>
) : (
Expand Down
13 changes: 11 additions & 2 deletions src/frontend/src/CustomNodes/GenericNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { NodeDataType } from "../../types/flow";
import { checkHasToolMode } from "../../utils/reactflowUtils";
import { classNames, cn } from "../../utils/utils";

import { useUtilityStore } from "@/stores/utilityStore";
import { processNodeAdvancedFields } from "../helpers/process-node-advanced-fields";
import useCheckCodeValidity from "../hooks/use-check-code-validity";
import useUpdateNodeCode from "../hooks/use-update-node-code";
Expand Down Expand Up @@ -87,6 +88,7 @@ function GenericNode({
const edges = useFlowStore((state) => state.edges);
const shortcuts = useShortcutsStore((state) => state.shortcuts);
const buildStatus = useBuildStatus(data, data.id);
const dismissAll = useUtilityStore((state) => state.dismissAll);

const showNode = data.showNode ?? true;

Expand Down Expand Up @@ -322,6 +324,7 @@ function GenericNode({
isOutdated={isOutdated}
isUserEdited={isUserEdited}
getValidationStatus={getValidationStatus}
handleUpdateComponent={handleUpdateCode}
/>
);
}, [
Expand All @@ -332,6 +335,8 @@ function GenericNode({
isOutdated,
isUserEdited,
getValidationStatus,
dismissAll,
handleUpdateCode,
]);

const renderDescription = useCallback(() => {
Expand Down Expand Up @@ -359,7 +364,11 @@ function GenericNode({
}, [data, types, isToolMode, showNode, shownOutputs, showHiddenOutputs]);

return (
<div className={cn(isOutdated && !isUserEdited ? "relative -mt-10" : "")}>
<div
className={cn(
isOutdated && !isUserEdited && !dismissAll ? "relative -mt-10" : "",
)}
>
<div
className={cn(
borderColor,
Expand All @@ -369,7 +378,7 @@ function GenericNode({
)}
>
{memoizedNodeToolbarComponent}
{isOutdated && !isUserEdited && (
{isOutdated && !isUserEdited && !dismissAll && (
<div className="flex h-10 w-full items-center gap-4 rounded-t-[0.69rem] bg-warning p-2 px-4 text-warning-foreground">
<ForwardedIconComponent
name="AlertTriangle"
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/components/core/appHeaderComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "@/customization/feature-flags";
import { useCustomNavigate } from "@/customization/hooks/use-custom-navigate";
import useTheme from "@/customization/hooks/use-custom-theme";
import { useResetDismissUpdateAll } from "@/hooks/use-reset-dismiss-update-all";
import useAlertStore from "@/stores/alertStore";
import { useEffect, useRef, useState } from "react";
import { AccountMenu } from "./components/AccountMenu";
Expand Down Expand Up @@ -46,6 +47,8 @@ export default function AppHeader(): JSX.Element {
};
}, []);

useResetDismissUpdateAll();

return (
<div className="flex h-[62px] w-full items-center justify-between gap-2 border-b px-5 py-2.5 dark:bg-background">
{/* Left Section */}
Expand Down
14 changes: 14 additions & 0 deletions src/frontend/src/hooks/use-reset-dismiss-update-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect } from "react";
import { useLocation } from "react-router-dom";
import { useUtilityStore } from "../stores/utilityStore";
export const useResetDismissUpdateAll = () => {
const location = useLocation();
const flowLocationPath = location.pathname.includes("flow");
const setDismissAll = useUtilityStore((state) => state.setDismissAll);

useEffect(() => {
if (flowLocationPath) {
setDismissAll(false);
}
}, [location]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useAlertStore from "@/stores/alertStore";
import useFlowsManagerStore from "@/stores/flowsManagerStore";
import useFlowStore from "@/stores/flowStore";
import { useTypesStore } from "@/stores/typesStore";
import { useUtilityStore } from "@/stores/utilityStore";
import { cn } from "@/utils/utils";
import { useUpdateNodeInternals } from "@xyflow/react";
import { useState } from "react";
Expand All @@ -27,6 +28,8 @@ export default function UpdateAllComponents() {

const [dismissed, setDismissed] = useState(false);

const setDismissAll = useUtilityStore((state) => state.setDismissAll);

const handleUpdateAllComponents = () => {
setLoadingUpdate(true);
takeSnapshot();
Expand Down Expand Up @@ -124,8 +127,10 @@ export default function UpdateAllComponents() {
variant="link"
size="icon"
className="shrink-0 text-sm text-warning-foreground"
onClick={() => {
onClick={(e) => {
setDismissed(true);
setDismissAll(true);
e.stopPropagation();
}}
>
Dismiss
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/stores/utilityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { UtilityStoreType } from "@/types/zustand/utility";
import { create } from "zustand";

export const useUtilityStore = create<UtilityStoreType>((set, get) => ({
dismissAll: false,
setDismissAll: (dismissAll: boolean) => set({ dismissAll }),
chatValueStore: "",
setChatValueStore: (value: string) => set({ chatValueStore: value }),
selectedItems: [],
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@

--datatype-fuchsia: 291.1 93.1% 82.9%;
--datatype-fuchsia-foreground: 293.4 69.5% 48.8%;

--datatype-purple: 268.6 100% 91.8%;
--datatype-purple-foreground: 272.1 71.7% 47.1%;

Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/types/zustand/utility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ export type UtilityStoreType = {
setFeatureFlags: (featureFlags: Record<string, any>) => void;
chatValueStore: string;
setChatValueStore: (value: string) => void;
dismissAll: boolean;
setDismissAll: (dismissAll: boolean) => void;
};
Loading