dtable-utils 5.0.6 → 5.0.7-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/link/core.js CHANGED
@@ -70,23 +70,30 @@ var getLinkedTableID = function getLinkedTableID(currentTableID, tableID, otherT
70
70
  /**
71
71
  * Get linked rows ids by the given row id
72
72
  * @param {array} links e.g. [ { _id, table1_id, table2_id, table1_table2_map, table2_table1_map, ... }, ... ]
73
- * @param {string} linkId
74
- * @param {string} table1Id
75
- * @param {string} table2Id
76
- * @param {string} rowId
73
+ * @param {string} link_id
74
+ * @param {string} table1_id
75
+ * @param {string} table2_id
76
+ * @param {string} row_id
77
+ * @param {boolean} is_linked_back, determine the self-link column which use 'table1_table2_map'
77
78
  * @returns linked rows ids, array
78
79
  */
79
- var getLinkCellValue = function getLinkCellValue(links, linkId, table1Id, table2Id, rowId) {
80
- if (!Array.isArray(links) || links.length === 0 || !table1Id || !table2Id || !rowId) return [];
81
- var linkBetween2Tables = getLinkById(links, linkId);
80
+ var getLinkCellValue = function getLinkCellValue(_ref) {
81
+ var links = _ref.links,
82
+ link_id = _ref.link_id,
83
+ table1_id = _ref.table1_id,
84
+ table2_id = _ref.table2_id,
85
+ row_id = _ref.row_id,
86
+ is_linked_back = _ref.is_linked_back;
87
+ if (!Array.isArray(links) || links.length === 0 || !table1_id || !table2_id || !row_id) return [];
88
+ var linkBetween2Tables = getLinkById(links, link_id);
82
89
  if (!linkBetween2Tables) return [];
83
90
  var linkMap = {};
84
- if (table1Id === table2Id) {
85
- linkMap = linkBetween2Tables.table2_table1_map;
91
+ if (table1_id === table2_id) {
92
+ linkMap = is_linked_back ? linkBetween2Tables.table1_table2_map : linkBetween2Tables.table2_table1_map;
86
93
  } else {
87
- linkMap = linkBetween2Tables.table1_id === table1Id ? linkBetween2Tables.table1_table2_map : linkBetween2Tables.table2_table1_map;
94
+ linkMap = linkBetween2Tables.table1_id === table1_id ? linkBetween2Tables.table1_table2_map : linkBetween2Tables.table2_table1_map;
88
95
  }
89
- var linkedRowIds = linkMap[rowId];
96
+ var linkedRowIds = linkMap[row_id];
90
97
  if (!linkedRowIds) {
91
98
  return [];
92
99
  }
@@ -103,21 +110,29 @@ var getTableLinkRows = function getTableLinkRows(operateRows, table, value) {
103
110
  linkColumns.forEach(function (column) {
104
111
  var key = column.key,
105
112
  data = column.data;
106
- var _ref = data || {},
107
- link_id = _ref.link_id,
108
- table_id = _ref.table_id,
109
- other_table_id = _ref.other_table_id;
113
+ var _ref2 = data || {},
114
+ link_id = _ref2.link_id,
115
+ table_id = _ref2.table_id,
116
+ other_table_id = _ref2.other_table_id,
117
+ is_linked_back = _ref2.is_linked_back;
110
118
  var linkedTableId = currentTableId === table_id ? other_table_id : table_id;
111
119
  var linkedTable = core$2.getTableById(tables, linkedTableId);
112
120
  rows.forEach(function (row) {
113
- var rowId = row._id;
114
- var linkedRowIds = linkedTable && getLinkCellValue(links, link_id, currentTableId, linkedTableId, rowId) || [];
121
+ var row_id = row._id;
122
+ var linkedRowIds = linkedTable && getLinkCellValue({
123
+ links: links,
124
+ link_id: link_id,
125
+ table1_id: currentTableId,
126
+ table2_id: linkedTableId,
127
+ row_id: row_id,
128
+ is_linked_back: is_linked_back
129
+ }) || [];
115
130
 
116
131
  // Handle the linked row has been deleted, but link still exists
117
132
  linkedRowIds = linkedRowIds.filter(function (linkedRowId) {
118
133
  return linkedTable.id_row_map[linkedRowId];
119
134
  });
120
- linkRows[rowId] = _objectSpread(_objectSpread({}, linkRows[rowId]), {}, _defineProperty__default["default"]({}, key, linkedRowIds));
135
+ linkRows[row_id] = _objectSpread(_objectSpread({}, linkRows[row_id]), {}, _defineProperty__default["default"]({}, key, linkedRowIds));
121
136
  });
122
137
  });
123
138
  return linkRows;
@@ -161,10 +161,18 @@ var convertRow = function convertRow(row, value, table, view, formulaResults, co
161
161
  var _column$data = column.data,
162
162
  link_id = _column$data.link_id,
163
163
  table_id = _column$data.table_id,
164
- other_table_id = _column$data.other_table_id;
164
+ other_table_id = _column$data.other_table_id,
165
+ is_linked_back = _column$data.is_linked_back;
165
166
  var otherTableID = tableID === table_id ? other_table_id : table_id;
166
167
  var links = value.links;
167
- result[columnName] = core.getLinkCellValue(links, link_id, tableID, otherTableID, row._id);
168
+ result[columnName] = core.getLinkCellValue({
169
+ links: links,
170
+ link_id: link_id,
171
+ is_linked_back: is_linked_back,
172
+ table1_id: tableID,
173
+ table2_id: otherTableID,
174
+ row_id: row._id
175
+ });
168
176
  break;
169
177
  }
170
178
  case cellType.CellType.FORMULA:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-utils",
3
- "version": "5.0.6",
3
+ "version": "5.0.7-beta.2",
4
4
  "description": "dtable common utils",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",