-
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
dc9f067
0b8f976
9b06d85
a92d4b8
3b818b9
14f4b43
4c6734b
c0e60d7
ad9317c
ce7138f
2020d7b
581aebf
8417fb8
7e3fe1b
cfdd620
cdb2729
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,93 @@ | |
|
|
||
| import Tooltip from 'components/UI/Tooltip/Tooltip'; | ||
| import styles from './FlowEditor.module.css'; | ||
| import axios from 'axios'; | ||
|
|
||
| const glificBase = FLOW_EDITOR_API; | ||
|
|
||
| const DB_NAME = 'FlowDefinitionDB'; | ||
| const VERSION = 1; | ||
| const STORE_NAME = 'flowDefinitions'; | ||
| let dbInstance: IDBDatabase | null = null; | ||
|
|
||
| async function initDB(): Promise<IDBDatabase> { | ||
| if (dbInstance) { | ||
| return dbInstance; | ||
| } | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| const request = indexedDB.open(DB_NAME, VERSION); | ||
|
|
||
| request.onerror = () => { | ||
| reject(new Error('Failed to open IndexedDB')); | ||
| }; | ||
|
|
||
| request.onsuccess = () => { | ||
| dbInstance = request.result; | ||
| resolve(dbInstance); | ||
| }; | ||
|
|
||
| request.onupgradeneeded = (event) => { | ||
| const db = (event.target as IDBOpenDBRequest).result; | ||
|
|
||
| if (!db.objectStoreNames.contains(STORE_NAME)) { | ||
| const store = db.createObjectStore(STORE_NAME, { keyPath: 'uuid' }); | ||
| store.createIndex('timestamp', 'timeStamp', { unique: false }); | ||
| } | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| export const getFlowDefinition = async (uuid: string): Promise<any | null> => { | ||
| const db = dbInstance || (await initDB()); | ||
| if (!db) { | ||
| console.warn('Database not initialized. Call initDB() first.'); | ||
| return null; | ||
| } | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| const transaction = db.transaction([STORE_NAME], 'readonly'); | ||
| const store = transaction.objectStore(STORE_NAME); | ||
| const request = store.get(uuid); | ||
|
|
||
| request.onsuccess = () => { | ||
| const result = request.result; | ||
| resolve(result ? result : null); | ||
| }; | ||
|
|
||
| request.onerror = () => { | ||
| reject(new Error('Failed to get flow definition')); | ||
| }; | ||
| }); | ||
| }; | ||
|
|
||
| export const fetchLatestRevision = async (uuid: string) => { | ||
| let latestRevision; | ||
| const response = await axios(`${glificBase}revisions/${uuid}`); | ||
| if (response.data.results.length > 0) { | ||
| latestRevision = response.data.results.reduce((latest: any, current: any) => { | ||
| return new Date(latest.created_on) > new Date(current.created_on) ? latest : current; | ||
| }); | ||
| } | ||
kurund marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return latestRevision; | ||
| }; | ||
kurund marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const postLatestRevision = async (uuid: any, definition: any) => { | ||
akanshaaa19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const url = `${glificBase}revisions/${uuid}`; | ||
|
|
||
| try { | ||
| const response = await axios.post(url, definition); | ||
| if (response.status === 200) { | ||
| return true; | ||
| } | ||
|
Check failure on line 86 in src/components/floweditor/FlowEditor.helper.tsx
|
||
| return false; | ||
| } catch (error) { | ||
| console.error('Error posting latest revision:', error); | ||
| return false; | ||
| } | ||
| }; | ||
akanshaaa19 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| export const setConfig = (uuid: any, isTemplate: boolean, skipValidation: boolean) => { | ||
| const services = JSON.parse(localStorage.getItem('organizationServices') || '{}'); | ||
|
|
||
|
|
@@ -109,7 +193,7 @@ | |
| return config; | ||
| }; | ||
|
|
||
| export const loadfiles = (startFlowEditor: any) => { | ||
| export const loadfiles = async (startFlowEditor: any) => { | ||
|
||
| const files: Array<HTMLScriptElement | HTMLLinkElement> = []; | ||
| const filesToLoad: any = Manifest.files; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.