prf: getColumnActions -> makeColumnActions for a more action oriented verb

pull/2052/head
Cameron Yick 2023-04-20 01:09:50 -04:00
rodzic cf504fe492
commit 0536f5d662
3 zmienionych plików z 13 dodań i 11 usunięć

Wyświetl plik

@ -16,7 +16,7 @@ const DOM_SELECTORS = {
aboveTablePanel: '.above-table-panel', aboveTablePanel: '.above-table-panel',
// These could have multiple matches // These could have multiple matches
/** Used for selecting table headers. Use getColumnActions if you want to add menu items. */ /** Used for selecting table headers. Use makeColumnActions if you want to add menu items. */
tableHeaders: `table.rows-and-columns th`, tableHeaders: `table.rows-and-columns th`,
/** Used to add "where" clauses to query using direct manipulation */ /** Used to add "where" clauses to query using direct manipulation */
@ -65,20 +65,22 @@ const datasetteManager = {
* - columnType: sqlite datatype enum (text, number, etc) * - columnType: sqlite datatype enum (text, number, etc)
* - isPk: boolean * - isPk: boolean
*/ */
getColumnActions: (columnMeta) => { makeColumnActions: (columnMeta) => {
let items = []; let columnActions = [];
// Accept function that returns list of items with keys
// Accept function that returns list of columnActions with keys
// Required: label (text) // Required: label (text)
// Optional: onClick or href // Optional: onClick or href
datasetteManager.plugins.forEach(plugin => { datasetteManager.plugins.forEach(plugin => {
if (plugin.getColumnActions) { if (plugin.makeColumnActions) {
// Plugins can provide multiple items if they want // Plugins can provide multiple columnActions if they want
// If multiple try to create entry with same label, the last one deletes the others // If multiple try to create entry with same label, the last one deletes the others
items.push(...plugin.getColumnActions(columnMeta)); columnActions.push(...plugin.makeColumnActions(columnMeta));
} }
}); });
// TODO: Validate item configs and give informative error message if missing keys.
return items; // TODO: Validate columnAction configs and give informative error message if missing keys.
return columnActions;
}, },
/** /**

Wyświetl plik

@ -15,7 +15,7 @@ const addPlugins = (manager) => {
manager.registerPlugin("column-name-plugin", { manager.registerPlugin("column-name-plugin", {
version: 0.1, version: 0.1,
getColumnActions: (columnMeta) => { makeColumnActions: (columnMeta) => {
const { column } = columnMeta; const { column } = columnMeta;
return [ return [

Wyświetl plik

@ -194,7 +194,7 @@ const initDatasetteTable = function (manager) {
columnType: th.dataset.columnType, columnType: th.dataset.columnType,
isPk: th.dataset.isPk === '1' isPk: th.dataset.isPk === '1'
}; };
const columnItemConfigs = manager.getColumnActions(columnActionsPayload); const columnItemConfigs = manager.makeColumnActions(columnActionsPayload);
const menuList = menu.querySelector('ul'); const menuList = menu.querySelector('ul');
columnItemConfigs.forEach(itemConfig => { columnItemConfigs.forEach(itemConfig => {