mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-17 07:41:26 +00:00
feat: sf metadata display (#6249)
* feat: sf metadata display * feat: update code * feat: update code * feat: lock react version * feat: bug * feat: optimize code * feat: update transalte * feat: update transalte * feat: rebase code * Feat: update code * Feat: update code --------- Co-authored-by: 杨国璇 <ygx@192.168.1.5> Co-authored-by: 杨国璇 <ygx@Hello-word.local> Co-authored-by: 杨国璇 <ygx@192.168.1.13>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Get column by key from table
|
||||
* @param {object} table
|
||||
* @param {string} columnKey
|
||||
* @returns column, object
|
||||
*/
|
||||
const getTableColumnByKey = (table, columnKey) => {
|
||||
if (!table || !Array.isArray(table.columns) || !columnKey) return null;
|
||||
return table.columns.find((column) => column.key === columnKey);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get table column by name
|
||||
* @param {object} table
|
||||
* @param {string} columnName
|
||||
* @returns column, object
|
||||
*/
|
||||
const getTableColumnByName = (table, columnName) => {
|
||||
if (!table || !Array.isArray(table.columns) || !columnName) return null;
|
||||
return table.columns.find((column) => column.name === columnName);
|
||||
};
|
||||
|
||||
export {
|
||||
getTableColumnByKey,
|
||||
getTableColumnByName,
|
||||
};
|
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Get table by id
|
||||
* @param {array} tables
|
||||
* @param {string} tableId
|
||||
* @returns table, object
|
||||
*/
|
||||
const getTableById = (tables, tableId) => {
|
||||
if (!Array.isArray(tables) || !tableId) return null;
|
||||
return tables.find((table) => table._id === tableId);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get table by name
|
||||
* @param {array} tables
|
||||
* @param {string} tableName
|
||||
* @returns table, object
|
||||
*/
|
||||
const getTableByName = (tables, tableName) => {
|
||||
if (!Array.isArray(tables) || !tableName) return null;
|
||||
return tables.find((table) => table.name === tableName);
|
||||
};
|
||||
|
||||
const getTableByIndex = (tables, tableIndex) => {
|
||||
if (!Array.isArray(tables) || tableIndex < 0) return null;
|
||||
return tables[tableIndex];
|
||||
};
|
||||
|
||||
export {
|
||||
getTableById,
|
||||
getTableByName,
|
||||
getTableByIndex,
|
||||
};
|
@@ -0,0 +1,5 @@
|
||||
export {
|
||||
getTableById, getTableByName, getTableByIndex,
|
||||
} from './core';
|
||||
export { getTableColumnByKey, getTableColumnByName } from './column';
|
||||
export { getRowById, getRowsByIds } from './row';
|
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Get table row by id
|
||||
* @param {object} table
|
||||
* @param {string} rowId the id of row
|
||||
* @returns row, object
|
||||
*/
|
||||
const getRowById = (table, rowId) => {
|
||||
if (!table || !table.id_row_map || !rowId) return null;
|
||||
return table.id_row_map[rowId];
|
||||
};
|
||||
|
||||
/**
|
||||
* Get table rows by ids
|
||||
* @param {object} table { id_row_map, ... }
|
||||
* @param {array} rowsIds [ row._id, ... ]
|
||||
* @returns rows, array
|
||||
*/
|
||||
const getRowsByIds = (table, rowsIds) => {
|
||||
if (!table || !table.id_row_map || !Array.isArray(rowsIds)) return [];
|
||||
return rowsIds.map((rowId) => table.id_row_map[rowId]).filter(Boolean);
|
||||
};
|
||||
|
||||
export {
|
||||
getRowById,
|
||||
getRowsByIds,
|
||||
};
|
Reference in New Issue
Block a user