MCPcopy
hub / github.com/chartdb/chartdb / DiffProvider

Function DiffProvider

src/context/diff-context/diff-provider.tsx:21–693  ·  view source on GitHub ↗
({
    children,
})

Source from the content-addressed store, hash-verified

19import type { ChartDBDiff, DiffMap } from '@/lib/domain/diff/diff';
20
21export const DiffProvider: React.FC<React.PropsWithChildren> = ({
22 children,
23}) => {
24 const [newDiagram, setNewDiagram] = React.useState<Diagram | null>(null);
25 const [originalDiagram, setOriginalDiagram] =
26 React.useState<Diagram | null>(null);
27 const [diffMap, setDiffMap] = React.useState<DiffMap>(
28 new Map<string, ChartDBDiff>()
29 );
30 const [tablesChanged, setTablesChanged] = React.useState<
31 Map<string, boolean>
32 >(new Map<string, boolean>());
33 const [fieldsChanged, setFieldsChanged] = React.useState<
34 Map<string, boolean>
35 >(new Map<string, boolean>());
36 const [relationshipsChanged, setRelationshipsChanged] = React.useState<
37 Map<string, boolean>
38 >(new Map<string, boolean>());
39 const [relationshipIdMap, setRelationshipIdMap] = React.useState<
40 Map<string, string>
41 >(new Map<string, string>());
42 const [isSummaryOnly, setIsSummaryOnly] = React.useState<boolean>(false);
43
44 const events = useEventEmitter<DiffEvent>();
45
46 const generateFieldsToAddMap = useCallback(
47 ({
48 diffMap,
49 newDiagram,
50 }: {
51 diffMap: DiffMap;
52 newDiagram: Diagram;
53 }) => {
54 const newFieldsMap = new Map<string, DBField[]>();
55
56 diffMap.forEach((diff) => {
57 if (diff.object === 'field' && diff.type === 'added') {
58 const field = newDiagram?.tables
59 ?.find((table) => table.id === diff.tableId)
60 ?.fields.find((f) => f.id === diff.newField.id);
61
62 if (field) {
63 newFieldsMap.set(diff.tableId, [
64 ...(newFieldsMap.get(diff.tableId) ?? []),
65 field,
66 ]);
67 }
68 }
69 });
70
71 return newFieldsMap;
72 },
73 []
74 );
75
76 const findRelationshipsToAdd = useCallback(
77 ({
78 diffMap,

Callers

nothing calls this directly

Calls 2

getDiffMapKeyFunction · 0.90
generateDiffFunction · 0.90

Tested by

no test coverage detected