-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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(dashboard): in-app editor preview only call when tab is opened #7186
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
629ebff
fix(dashboard): in-app editor preview only call when tab is opened
LetItRock 7df7c4d
Merge branch 'next' into nv-4931-in-app-preview-improvements
LetItRock bbb7fec
chore(dashboard): improve in-app preview and handle gracefully api fa…
LetItRock f17eec1
chore(dashboard): sentry capture errors on the preview endpoint
LetItRock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 0 additions & 66 deletions
66
apps/dashboard/src/components/workflow-editor/steps/use-debounced-preview.tsx
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
apps/dashboard/src/components/workflow-editor/steps/use-editor-preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useCallback, useEffect, useState } from 'react'; | ||
|
||
import { usePreviewStep } from '@/hooks'; | ||
import { NovuApiError } from '@/api/api.client'; | ||
import { ToastIcon } from '@/components/primitives/sonner'; | ||
import { showToast } from '@/components/primitives/sonner-helpers'; | ||
import { useDataRef } from '@/hooks/use-data-ref'; | ||
|
||
export const useEditorPreview = ({ | ||
workflowSlug, | ||
stepSlug, | ||
stepName, | ||
controlValues, | ||
}: { | ||
workflowSlug: string; | ||
stepSlug: string; | ||
stepName: string; | ||
controlValues: Record<string, unknown>; | ||
}) => { | ||
const [editorValue, setEditorValue] = useState('{}'); | ||
const { | ||
previewStep, | ||
data: previewData, | ||
isPending: isPreviewPending, | ||
} = usePreviewStep({ | ||
onSuccess: (res) => { | ||
setEditorValue(JSON.stringify(res.previewPayloadExample, null, 2)); | ||
}, | ||
onError: (error) => { | ||
if (error instanceof NovuApiError) { | ||
LetItRock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
showToast({ | ||
children: () => ( | ||
<> | ||
<ToastIcon variant="error" /> | ||
<span className="text-sm"> | ||
Failed to preview step <span className="font-bold">{stepName}</span> with error: {error.message} | ||
</span> | ||
</> | ||
), | ||
options: { | ||
position: 'bottom-right', | ||
classNames: { | ||
toast: 'ml-10 mb-4', | ||
}, | ||
}, | ||
}); | ||
} | ||
}, | ||
}); | ||
const dataRef = useDataRef({ | ||
workflowSlug, | ||
stepSlug, | ||
controlValues, | ||
editorValue, | ||
}); | ||
|
||
useEffect(() => { | ||
previewStep({ | ||
workflowSlug: dataRef.current.workflowSlug, | ||
stepSlug: dataRef.current.stepSlug, | ||
data: { controlValues: dataRef.current.controlValues, previewPayload: JSON.parse(dataRef.current.editorValue) }, | ||
}); | ||
}, [dataRef, previewStep]); | ||
Comment on lines
+29
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. on mount call the preview endpoint |
||
|
||
const previewStepCallback = useCallback(() => { | ||
return previewStep({ | ||
workflowSlug, | ||
stepSlug, | ||
data: { controlValues, previewPayload: JSON.parse(editorValue) }, | ||
}); | ||
}, [workflowSlug, stepSlug, controlValues, editorValue, previewStep]); | ||
Comment on lines
+44
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used for the apply button click |
||
|
||
return { editorValue, setEditorValue, previewStep: previewStepCallback, previewData, isPreviewPending }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this, but unfortunately, with the current implementation, we can't show the skeleton loader optimistically.
To have the types automatically picked we need to do check for the type:
This requires a lot of refactoring in this file.