Files
lucent-laravel/front/js/svelte/records/elements/reference.js
T
2026-05-07 22:50:02 +03:00

37 lines
807 B
JavaScript

import { arrayUniqueCb } from "../../../helpers";
export function insertEdges(
graph,
sourceRecord,
targetRecords,
fieldName,
action = "",
) {
let newEdges = targetRecords.map((r) => {
return {
target: r.id,
source: sourceRecord.id,
sourceSchema: sourceRecord.schema,
targetSchema: r.schema,
field: fieldName,
depth: 1,
rank: "",
};
});
let replacedEdges = graph.edges;
if (action === "replace") {
replacedEdges = replacedEdges.filter((edge) => edge.field !== field.name);
}
graph.records = arrayUniqueCb(
[...graph.records, ...targetRecords],
(r) => r.id,
);
graph.edges = arrayUniqueCb(
[...replacedEdges, ...newEdges],
(edge) => edge.source + edge.target + edge.field + edge.depth,
);
return graph;
}