Add getMyProcesses logic
This commit is contained in:
parent
74ae167e3c
commit
09e8530c6a
29
src/App.tsx
29
src/App.tsx
@ -23,6 +23,7 @@ function App() {
|
|||||||
const [showAuthModal, setShowAuthModal] = useState(false)
|
const [showAuthModal, setShowAuthModal] = useState(false)
|
||||||
const [showFolderModal, setShowFolderModal] = useState(false)
|
const [showFolderModal, setShowFolderModal] = useState(false)
|
||||||
const [processes, setProcesses] = useState<any>(null)
|
const [processes, setProcesses] = useState<any>(null)
|
||||||
|
const [myProcesses, setMyProcesses] = useState<string[]>([])
|
||||||
const [userPairingId, setUserPairingId] = useState<string | null>(null)
|
const [userPairingId, setUserPairingId] = useState<string | null>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -39,28 +40,22 @@ function App() {
|
|||||||
messageBus.isReady().then(() => {
|
messageBus.isReady().then(() => {
|
||||||
messageBus.getProcesses().then((processes: any) => {
|
messageBus.getProcesses().then((processes: any) => {
|
||||||
setProcesses(processes);
|
setProcesses(processes);
|
||||||
|
|
||||||
for (const key of Object.keys(processes)) {
|
|
||||||
try {
|
|
||||||
const process = processes[key];
|
|
||||||
if (Object.keys(process.states?.[0]?.keys).length === 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
console.log(key);
|
|
||||||
console.log(process);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to retrieve data:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [isConnected, iframeUrl]);
|
}, [isConnected, iframeUrl]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isConnected && processes !== null) {
|
||||||
|
const messageBus = MessageBus.getInstance(iframeUrl);
|
||||||
|
messageBus.isReady().then(() => {
|
||||||
|
messageBus.getMyProcesses().then((res: string[]) => {
|
||||||
|
setMyProcesses(res);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isConnected, processes]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isConnected && userPairingId === null) {
|
if (isConnected && userPairingId === null) {
|
||||||
const messageBus = MessageBus.getInstance(iframeUrl);
|
const messageBus = MessageBus.getInstance(iframeUrl);
|
||||||
|
@ -228,6 +228,41 @@ export default class MessageBus {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getMyProcesses(): Promise<string[]> {
|
||||||
|
return new Promise<string[]>((resolve: (myProcesses: string[]) => void, reject: (error: string) => void) => {
|
||||||
|
this.checkToken().then(() => {
|
||||||
|
const userStore = UserStore.getInstance();
|
||||||
|
const accessToken = userStore.getAccessToken()!;
|
||||||
|
|
||||||
|
const correlationId = uuidv4();
|
||||||
|
this.initMessageListener(correlationId);
|
||||||
|
|
||||||
|
const unsubscribe = EventBus.getInstance().on('GET_MY_PROCESSES', (responseId: string, myProcesses: string[]) => {
|
||||||
|
if (responseId !== correlationId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsubscribe();
|
||||||
|
this.destroyMessageListener();
|
||||||
|
resolve(myProcesses);
|
||||||
|
});
|
||||||
|
|
||||||
|
const unsubscribeError = EventBus.getInstance().on('ERROR_GET_MY_PROCESSES', (responseId: string, error: string) => {
|
||||||
|
if (responseId !== correlationId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsubscribeError();
|
||||||
|
this.destroyMessageListener();
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.sendMessage({
|
||||||
|
type: 'GET_MY_PROCESSES',
|
||||||
|
accessToken,
|
||||||
|
});
|
||||||
|
}).catch(console.error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public getData(processId: string, stateId: string): Promise<any> {
|
public getData(processId: string, stateId: string): Promise<any> {
|
||||||
return new Promise<any>((resolve: (data: any) => void, reject: (error: string) => void) => {
|
return new Promise<any>((resolve: (data: any) => void, reject: (error: string) => void) => {
|
||||||
this.checkToken().then(() => {
|
this.checkToken().then(() => {
|
||||||
@ -444,6 +479,16 @@ export default class MessageBus {
|
|||||||
EventBus.getInstance().emit('PROCESSES_RETRIEVED', correlationId, message.processes);
|
EventBus.getInstance().emit('PROCESSES_RETRIEVED', correlationId, message.processes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'GET_MY_PROCESSES':
|
||||||
|
if (this.errors[correlationId]) {
|
||||||
|
const error = this.errors[correlationId];
|
||||||
|
delete this.errors[correlationId];
|
||||||
|
EventBus.getInstance().emit('ERROR_GET_MY_PROCESSES', correlationId, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventBus.getInstance().emit('GET_MY_PROCESSES', correlationId, message.myProcesses);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'PROFILE_CREATED': // CREATE_PROFILE
|
case 'PROFILE_CREATED': // CREATE_PROFILE
|
||||||
if (this.errors[correlationId]) {
|
if (this.errors[correlationId]) {
|
||||||
const error = this.errors[correlationId];
|
const error = this.errors[correlationId];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user