From 9b773c7a040922bdcf3245e873c45b00d6b01df0 Mon Sep 17 00:00:00 2001 From: Cameron Yick Date: Thu, 20 Apr 2023 01:03:12 -0400 Subject: [PATCH] prf: Convert column metadata names in column actions --- datasette/static/datasette-manager.js | 7 ++++--- datasette/static/table.js | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/datasette/static/datasette-manager.js b/datasette/static/datasette-manager.js index f650959dcb..6ca129013b 100644 --- a/datasette/static/datasette-manager.js +++ b/datasette/static/datasette-manager.js @@ -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 = []; diff --git a/datasette/static/table.js b/datasette/static/table.js index 933e46fa17..eaf9a64c7e 100644 --- a/datasette/static/table.js +++ b/datasette/static/table.js @@ -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`);