-
Notifications
You must be signed in to change notification settings - Fork 48
Implement IndexedDB for flow definitions and add revision handling logic #3380
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
Open
akanshaaa19
wants to merge
16
commits into
master
Choose a base branch
from
enhancements/save-revision-before-publish
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dc9f067
Implement IndexedDB for flow definitions and add revision handling logic
akanshaaa19 0b8f976
Refactor axios call in fetchLatestRevision to use axios.get and add I…
akanshaaa19 9b06d85
Refactor fetchLatestRevision to use fetch API and improve error handl…
akanshaaa19 a92d4b8
Implement IndexedDB for flow definitions and add revision handling logic
akanshaaa19 3b818b9
Refactor axios call in fetchLatestRevision to use axios.get and add I…
akanshaaa19 14f4b43
Refactor fetchLatestRevision to use fetch API and improve error handl…
akanshaaa19 4c6734b
Add deleteFlowDefinition function and integrate it into FlowEditor on…
akanshaaa19 c0e60d7
Merge branch 'enhancements/save-revision-before-publish' of github.co…
akanshaaa19 ad9317c
Remove unused import of deleteFlowDefinition in FlowEditor component
akanshaaa19 ce7138f
Merge branch 'master' into enhancements/save-revision-before-publish
akanshaaa19 2020d7b
Add publishFlowWithSuccess mock and update tests for flow publishing
akanshaaa19 581aebf
Merge branch 'enhancements/save-revision-before-publish' of github.co…
akanshaaa19 8417fb8
Refactor error handling and logging in FlowEditor helper and tests
akanshaaa19 7e3fe1b
Change loadfiles function from async to synchronous
akanshaaa19 cfdd620
Skip inactive flow test
akanshaaa19 cdb2729
Merge branch 'master' of github.com:glific/glific-frontend into enhan…
akanshaaa19 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -19,9 +19,20 @@ import { Loading } from 'components/UI/Layout/Loading/Loading'; | |
| import Track from 'services/TrackService'; | ||
| import { exportFlowMethod } from 'common/utils'; | ||
| import styles from './FlowEditor.module.css'; | ||
| import { checkElementInRegistry, getKeywords, loadfiles, setConfig } from './FlowEditor.helper'; | ||
| import { | ||
| checkElementInRegistry, | ||
| deleteFlowDefinition, | ||
| fetchLatestRevision, | ||
| getFlowDefinition, | ||
| getKeywords, | ||
| loadfiles, | ||
| postLatestRevision, | ||
| setConfig, | ||
| } from './FlowEditor.helper'; | ||
| import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; | ||
| import { BackdropLoader, FlowTranslation } from 'containers/Flow/FlowTranslation'; | ||
| import dayjs from 'dayjs'; | ||
| import setLogs from 'config/logs'; | ||
| import ShareResponderLink from 'containers/Flow/ShareResponderLink/ShareResponderLink'; | ||
|
|
||
| declare function showFlowEditor(node: any, config: any): void; | ||
|
|
@@ -116,14 +127,15 @@ export const FlowEditor = () => { | |
| }); | ||
|
|
||
| const [publishFlow] = useMutation(PUBLISH_FLOW, { | ||
| onCompleted: (data) => { | ||
| onCompleted: async (data) => { | ||
| if (data.publishFlow.errors && data.publishFlow.errors.length > 0) { | ||
| setFlowValidation(data.publishFlow.errors); | ||
| setIsError(true); | ||
| } else if (data.publishFlow.success) { | ||
| setPublished(true); | ||
| } | ||
| setPublishLoading(false); | ||
| if (uuid) await deleteFlowDefinition(uuid); | ||
| }, | ||
| onError: () => { | ||
| setPublishLoading(false); | ||
|
|
@@ -252,8 +264,10 @@ export const FlowEditor = () => { | |
| Track('Flow opened'); | ||
|
|
||
| return () => { | ||
| Object.keys(files).forEach((node: any) => { | ||
| Object.keys(files).forEach((node) => { | ||
| // @ts-ignore | ||
| if (files[node] && document.body.contains(files[node])) { | ||
| // @ts-ignore | ||
| document.body.removeChild(files[node]); | ||
| } | ||
| }); | ||
|
|
@@ -271,8 +285,37 @@ export const FlowEditor = () => { | |
| return () => {}; | ||
| }, [flowId]); | ||
|
|
||
| const handlePublishFlow = () => { | ||
| publishFlow({ variables: { uuid: params.uuid } }); | ||
| const checkLatestRevision = async () => { | ||
| let revisionSaved = false; | ||
| if (uuid) { | ||
| const latestRevision = await fetchLatestRevision(uuid); | ||
| const flowDefinition = await getFlowDefinition(uuid); | ||
|
|
||
| if (latestRevision && flowDefinition) { | ||
| const latestRevisionTime = dayjs(latestRevision.created_on); | ||
| const flowDefinitionTime = dayjs(flowDefinition.timestamp); | ||
|
|
||
| if (flowDefinitionTime.isAfter(latestRevisionTime)) { | ||
| const timeDifferenceSeconds = flowDefinitionTime.diff(latestRevisionTime, 'seconds'); | ||
| revisionSaved = | ||
| timeDifferenceSeconds > 300 ? await postLatestRevision(uuid, flowDefinition.definition) : true; | ||
| } else { | ||
| revisionSaved = true; | ||
| } | ||
| } else if (!flowDefinition) { | ||
| setLogs(`Local Flow definition not found ${uuid}`, 'info'); | ||
|
|
||
| // If flowDefinition is not found, we assume the revision is saved | ||
| revisionSaved = true; | ||
| } | ||
| } | ||
| return revisionSaved; | ||
| }; | ||
|
Comment on lines
+288
to
+313
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. Surface failure when revisions can't be synced When fetchLatestRevision/getFlowDefinition returns null we bail with false, but nothing informs the user why publish didn't proceed; dialog just spins. Add error notification + reset loading. 🤖 Prompt for AI Agents |
||
|
|
||
| const handlePublishFlow = async () => { | ||
| if (await checkLatestRevision()) { | ||
| publishFlow({ variables: { uuid: params.uuid } }); | ||
| } | ||
| }; | ||
akanshaaa19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const handleCancelFlow = () => { | ||
|
|
||
This file contains hidden or 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.
Include
Bearerprefix on Authorization headerThe flow-editor API expects standard bearer auth. Here we send the raw token (
authorization: token), which the backend treats as missing credentials, returning 401. This regresses publishing after idle periods—the exact bug reported in PR comments. Prefix the header withBearer(and bail early iftokenis falsy) so the request reuses our auth session correctly.📝 Committable suggestion
🤖 Prompt for AI Agents