Add getDescription
This commit is contained in:
parent
02d134d0a0
commit
5fb4c87f1d
@ -1,6 +1,7 @@
|
|||||||
import { addSubscription } from '../../utils/subscription.utils';
|
import { addSubscription } from '../../utils/subscription.utils';
|
||||||
import Services from '../../services/service';
|
import Services from '../../services/service';
|
||||||
import { getCorrectDOM } from '~/utils/html.utils';
|
import { getCorrectDOM } from '~/utils/html.utils';
|
||||||
|
import { Process } from 'pkg/sdk_client';
|
||||||
|
|
||||||
// Initialize function, create initial tokens with itens that are already selected by the user
|
// Initialize function, create initial tokens with itens that are already selected by the user
|
||||||
export async function init() {
|
export async function init() {
|
||||||
@ -39,13 +40,19 @@ export async function init() {
|
|||||||
// Create a new process with hardcoded members for demonstration purpose
|
// Create a new process with hardcoded members for demonstration purpose
|
||||||
await createMessagingProcess();
|
await createMessagingProcess();
|
||||||
|
|
||||||
|
setTimeout(async () => {
|
||||||
const processes = await getProcesses();
|
const processes = await getProcesses();
|
||||||
for (let process of processes) {
|
for (const {key, value} of processes) {
|
||||||
const processName = process['description'];
|
const processName = await getDescription(key, value);
|
||||||
|
// const processName = value['description'];
|
||||||
|
if (processName) {
|
||||||
|
console.log('adding process name to list:', processName);
|
||||||
const opt = new Option(processName);
|
const opt = new Option(processName);
|
||||||
opt.value = processName;
|
opt.value = processName;
|
||||||
element.add(opt);
|
element.add(opt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}, 1000)
|
||||||
// set the wrapper as child (instead of the element)
|
// set the wrapper as child (instead of the element)
|
||||||
element.parentNode?.replaceChild(wrapper, element);
|
element.parentNode?.replaceChild(wrapper, element);
|
||||||
// set element as child of wrapper
|
// set element as child of wrapper
|
||||||
@ -457,6 +464,41 @@ async function createMessagingProcess(): Promise<void> {
|
|||||||
await service.handleApiReturn(apiReturn);
|
await service.handleApiReturn(apiReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getDescription(processId: string, process: Process): Promise<string | null> {
|
||||||
|
const service = await Services.getInstance();
|
||||||
|
// Get the `commited_in` value of the last state and remove it from the array
|
||||||
|
const currentCommitedIn = process.states.pop()?.commited_in;
|
||||||
|
|
||||||
|
if (currentCommitedIn === undefined) {
|
||||||
|
return null; // No states available
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the last state where `commited_in` is different
|
||||||
|
let lastDifferentState = process.states.findLast(
|
||||||
|
state => state.commited_in !== currentCommitedIn
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!lastDifferentState) {
|
||||||
|
// It means that we only have one state that is not commited yet, that can happen with process we just created
|
||||||
|
// let's assume that the right description is in the last concurrent state and not handle the (arguably rare) case where we have multiple concurrent states on a creation
|
||||||
|
lastDifferentState = process.states.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Take the description out of the state, if any
|
||||||
|
const description = lastDifferentState!.pcd_commitment['description'];
|
||||||
|
if (description) {
|
||||||
|
const userDiff = await service.getDiffByValue(description);
|
||||||
|
if (userDiff) {
|
||||||
|
console.log("Successfully retrieved userDiff:", userDiff);
|
||||||
|
return userDiff.new_value;
|
||||||
|
} else {
|
||||||
|
console.log("Failed to retrieve a non-null userDiff.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
async function getProcesses(): Promise<any[]> {
|
async function getProcesses(): Promise<any[]> {
|
||||||
const service = await Services.getInstance();
|
const service = await Services.getInstance();
|
||||||
const processes = await service.getProcesses();
|
const processes = await service.getProcesses();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user