Skip to content

Commit

Permalink
Merge pull request #563 from DataRecce/feature/drc-983-guide-users-to…
Browse files Browse the repository at this point in the history
…-download-artifacts-to-target-base

[Feature] Guide users to download artifacts to target base
  • Loading branch information
wcchang1115 authored Dec 31, 2024
2 parents bf5e88a + e249fac commit b034551
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 8 deletions.
27 changes: 22 additions & 5 deletions js/src/components/lineage/PreviewChangeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
trackPreviewChange,
trackPreviewChangeFeedback,
} from "@/lib/api/track";
import { useGuideToast } from "@/lib/hooks/useGuideToast";
import { useRecceServerFlag } from "@/lib/hooks/useRecceServerFlag";

interface PreviewChangeViewProps {
isOpen: boolean;
Expand All @@ -52,15 +54,13 @@ function PreviewChangeTopBar({
onRunResultOpen,
runQuery,
isPending,
feedbackToast,
}: {
current?: NodeData;
primaryKeys: string[];
setPrimaryKeys: (primaryKeys: string[]) => void;
onRunResultOpen: () => void;
runQuery: () => void;
isPending: boolean;
feedbackToast: () => void;
}) {
return (
<Flex
Expand Down Expand Up @@ -95,7 +95,6 @@ function PreviewChangeTopBar({
onClick={() => {
onRunResultOpen();
runQuery();
setTimeout(() => feedbackToast(), 3000);
}}
colorScheme="blue"
isLoading={isPending}
Expand Down Expand Up @@ -148,6 +147,7 @@ export function PreviewChangeView({
);
const { showRunId, clearRunResult } = useRecceActionContext();
const { primaryKeys, setPrimaryKeys } = useRecceQueryContext();
const { data: flags, isLoading } = useRecceServerFlag();

const queryFn = async () => {
const sqlTemplate = modifiedCode;
Expand All @@ -165,6 +165,7 @@ export function PreviewChangeView({

return await waitRun(run_id);
};

const { mutate: runQuery, isPending } = useMutation({
mutationFn: queryFn,
onSuccess(data, variables) {
Expand All @@ -180,9 +181,16 @@ export function PreviewChangeView({
node: current?.name,
status: "success",
});
setTimeout(() => feedbackToast(), 1000);
setTimeout(() => {
if (!isLoading && flags?.single_env_onboarding) {
prepareEnvToast();
}
}, 2000);
}
},
});

const { feedbackToast, closeToast } = useFeedbackCollectionToast({
feedbackId: localStorageKeys.previewChangeFeedbackID,
description: "Enjoy preview change?",
Expand Down Expand Up @@ -210,6 +218,13 @@ export function PreviewChangeView({
externalLinkText: "Give us feedback",
});

const { guideToast: prepareEnvToast, closeGuideToast } = useGuideToast({
guideId: localStorageKeys.prepareEnvGuideID,
description: "Want to compare data changes with production data?",
externalLink: "https://datarecce.io/docs",
externalLinkText: "Learn how.",
});

useEffect(() => {
if (isOpen) {
setModifiedCode(current?.raw_code || "");
Expand All @@ -225,6 +240,7 @@ export function PreviewChangeView({
onRunResultClose();
clearRunResult();
closeToast();
closeGuideToast();
trackPreviewChange({ action: "close", node: current?.name });
}}
>
Expand Down Expand Up @@ -276,7 +292,6 @@ export function PreviewChangeView({
onRunResultOpen={onRunResultOpen}
runQuery={runQuery}
isPending={isPending}
feedbackToast={feedbackToast}
/>
<PreviewChangeEditorLabels height="32pxs" flex="0 0 auto" />
<SqlPreview current={current} onChange={setModifiedCode} />
Expand All @@ -296,7 +311,9 @@ export function PreviewChangeView({
icon={<VscFeedback />}
variant={"ghost"}
size={"md"}
onClick={() => feedbackToast(true)}
onClick={() => {
feedbackToast(true);
}}
/>
</Tooltip>
</Box>
Expand Down
1 change: 1 addition & 0 deletions js/src/lib/api/localStorageKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const prefix = "recce-";
export const localStorageKeys = {
bypassSaveOverwrite: `${prefix}-bypass-save-overwrite`,
previewChangeFeedbackID: `${prefix}-preview-change-feedback`,
prepareEnvGuideID: `${prefix}-prepare-env`,
};
10 changes: 7 additions & 3 deletions js/src/lib/hooks/useFeedbackCollectionToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export function useFeedbackCollectionToast(options: {
description={description}
onLike={() => {
onFeedbackSubmit("like");
toast.closeAll();
onClose();
localStorage.setItem(feedbackId, "true");
}}
onDislike={() => {
onFeedbackSubmit("dislike");
toast.closeAll();
onClose();
localStorage.setItem(feedbackId, "true");
}}
externalLink={externalLink}
Expand All @@ -124,7 +124,11 @@ export function useFeedbackCollectionToast(options: {
onFeedbackSubmit("link");
}}
/>
<CloseButton onClick={onClose} />
<CloseButton
onClick={() => {
onClose();
}}
/>
</HStack>
</AlertDescription>
</Alert>
Expand Down
73 changes: 73 additions & 0 deletions js/src/lib/hooks/useGuideToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
useToast,
Alert,
AlertDescription,
Link,
HStack,
CloseButton,
Text,
} from "@chakra-ui/react";

export function useGuideToast(options: {
guideId: string;
description: string;
externalLink?: string;
externalLinkText?: string;
}) {
const toast = useToast();
const { guideId, description, externalLink, externalLinkText } = options;

function guideToast() {
if (toast.isActive(guideId)) {
// Don't show the toast again if it's already active
return;
}

toast({
id: guideId,
position: "bottom-right",
duration: 3000,
description: "some text",
render: ({ id, onClose }) => (
<Alert
status="success"
variant="subtle"
zIndex={"toast"}
borderColor={"gray.200"}
borderWidth={3}
borderRadius={"md"}
backgroundColor={"white"}
opacity={1}
>
<AlertDescription fontSize="md">
<HStack>
<Text>
{description}{" "}
<Link
textDecor="underline"
isExternal
href={externalLink}
onClick={() => {
onClose();
}}
>
{externalLinkText}
</Link>
</Text>
<CloseButton
onClick={() => {
onClose();
}}
/>
</HStack>
</AlertDescription>
</Alert>
),
});
}

return {
guideToast: guideToast,
closeGuideToast: () => toast.closeAll(),
};
}

0 comments on commit b034551

Please sign in to comment.