ConceptPortal-public/rsconcept/frontend/src/models/miscellaneousAPI.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

/**
2023-12-26 14:23:51 +03:00
* Module: API for miscellaneous frontend model types. Future targets for refactoring aimed at extracting modules.
*/
2023-12-26 14:23:51 +03:00
import { DependencyMode } from './miscellaneous';
import { IConstituenta, IRSForm } from './rsform';
/**
* Filter list of {@link ILibraryItem} to a given query.
*/
export function applyGraphFilter(target: IRSForm, start: number, mode: DependencyMode): IConstituenta[] {
if (mode === DependencyMode.ALL) {
2023-12-28 14:04:44 +03:00
return target.items;
}
2023-12-28 14:04:44 +03:00
let ids: number[] | undefined = undefined;
switch (mode) {
2023-12-28 14:04:44 +03:00
case DependencyMode.OUTPUTS: {
ids = target.graph.nodes.get(start)?.outputs;
break;
}
case DependencyMode.INPUTS: {
ids = target.graph.nodes.get(start)?.inputs;
break;
}
case DependencyMode.EXPAND_OUTPUTS: {
ids = target.graph.expandOutputs([start]);
break;
}
case DependencyMode.EXPAND_INPUTS: {
ids = target.graph.expandInputs([start]);
break;
}
}
if (!ids) {
2023-12-28 14:04:44 +03:00
return target.items;
} else {
2023-12-28 14:04:44 +03:00
return target.items.filter(cst => ids!.find(id => id === cst.id));
}
2023-12-28 14:04:44 +03:00
}