Skip to content

Commit

Permalink
prf: Convert column metadata names in column actions
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrosquall committed Apr 20, 2023
1 parent 8f744e7 commit 9b773c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions datasette/static/datasette-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ const datasetteManager = {
},

/**
* New DOM elements created each time the button is clicked so the data is not stale.
* New DOM elements are created on each click, so the data is not stale.
*
* Items
* - must provide label (text)
* - might provide href (string) or an onclick ((evt) => void)
*
* columnMeta is metadata stored on the column header (TH) as a DOMStringMap
* - column: string
* - columnNotNull: 0 or 1
* - columnNotNull: boolean
* - columnType: sqlite datatype enum (text, number, etc)
* - isPk: 0 or 1
* - isPk: boolean
*/
getColumnActions: (columnMeta) => {
let items = [];
Expand Down
11 changes: 8 additions & 3 deletions datasette/static/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,15 @@ const initDatasetteTable = function (manager) {

// Custom menu items on each render
// Plugin hook: allow adding JS-based additional menu items
const menuList = menu.querySelector('ul');

const columnItemConfigs = manager.getColumnActions({ ...th.dataset });
const columnActionsPayload = {
columnName: th.dataset.column,
columnNotNull: th.dataset.columnNotNull === '1',
columnType: th.dataset.columnType,
isPk: th.dataset.isPk === '1'
};
const columnItemConfigs = manager.getColumnActions(columnActionsPayload);

const menuList = menu.querySelector('ul');
columnItemConfigs.forEach(itemConfig => {
// Remove items from previous render. We assume entries have unique labels.
const existingItems = menuList.querySelectorAll(`li`);
Expand Down

0 comments on commit 9b773c7

Please sign in to comment.