MCPcopy Create free account
hub / github.com/apitable/apitable / linkLookUpField

Function linkLookUpField

packages/widget-sdk/src/subscribe/datasheet_map.ts:41–92  ·  view source on GitHub ↗
(datasheetId: string, visitedDst?: Set<string>)

Source from the content-addressed store, hash-verified

39 let datasheetMap: IDatasheetMap = {};
40
41 function linkLookUpField(datasheetId: string, visitedDst?: Set<string>) {
42 const _visitedDst = visitedDst || new Set();
43 if (_visitedDst.has(datasheetId)) {
44 return;
45 }
46 const state = store.getState();
47 const datasheet = Selectors.getDatasheet(state, datasheetId);
48 const shareId = state.pageParams.shareId;
49 const formId = state.pageParams.formId;
50 if (shareId && formId) {
51 return;
52 }
53 _visitedDst.add(datasheetId);
54 if (!datasheet) {
55 console.log(`go go go load the data of (${datasheetId})`);
56 return store.dispatch(StoreActions.fetchDatasheet(datasheetId) as any);
57 }
58 const fieldMap = Selectors.getFieldMap(state, datasheetId)!;
59 const lookUpFields = Object.values(fieldMap).filter(field => field.type === FieldType.LookUp) as ILookUpField[];
60 let index = 1;
61
62 const findNextLookUpField = (field: ILookUpField, fieldMap: IFieldMap, visitedField?: Set<string>) => {
63 const _visitedField = visitedField || new Set();
64 if (_visitedField.has(field.id)) {
65 return;
66 }
67 _visitedField.add(field.id);
68 // The actual fields of this table lookup query.
69 const lookUpTargetField = (Field.bindModel(field) as LookUpField).getLookUpTargetField();
70 if (!lookUpTargetField) {
71 // The foreign key data for this table is not loaded.
72 const foreignField = fieldMap[field.property.relatedLinkFieldId] as ILinkField;
73 if (foreignField && (foreignField.type === FieldType.Link || foreignField.type === FieldType.OneWayLink)) {
74 console.log(`2.${index}.1 "${field.name}" the data of the queried table (${foreignField.property.foreignDatasheetId}) is not loaded`);
75 linkLookUpField(foreignField.property.foreignDatasheetId, _visitedDst);
76 }
77 } else {
78 console.log(`2.${index}.1 "${field.name}" the actual field of the query is: 「${lookUpTargetField.name}」`, { lookUpTargetField });
79 }
80 // lookup lookup le lookup
81 // The lookup of this table looks up another lookup field of the foreign key table.
82 if (lookUpTargetField && lookUpTargetField.type === FieldType.LookUp) {
83 console.log(`2.${index}.2 "${lookUpTargetField.name}" is also a lookup field`);
84 findNextLookUpField(lookUpTargetField, fieldMap, _visitedField);
85 }
86 };
87
88 for (const field of lookUpFields) {
89 findNextLookUpField(field, fieldMap);
90 index++;
91 }
92 }
93
94 return store.subscribe(function datasheetMapChange() {
95 const state = store.getState();

Callers 2

findNextLookUpFieldFunction · 0.85
subscribeDatasheetMapFunction · 0.85

Calls 9

findNextLookUpFieldFunction · 0.85
getFieldMapMethod · 0.80
hasMethod · 0.65
addMethod · 0.65
getDatasheetMethod · 0.45
logMethod · 0.45
dispatchMethod · 0.45
fetchDatasheetMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected