diff --git a/actionbutton/actionbutton.css b/actionbutton/actionbutton.css index c64be6f4..03eac90f 100644 --- a/actionbutton/actionbutton.css +++ b/actionbutton/actionbutton.css @@ -18,11 +18,18 @@ body { #app { - margin: 32px 16px; + margin: 8px; +} + +.container { + width: 100%; + display: flex; + flex-direction: row; + flex-wrap: wrap; } .description, .result, .button { - margin: 16px 0; + margin: 4px 0; } .message { @@ -33,6 +40,7 @@ body { border: none; border-radius: 6px; background-color: #1486ff; + margin: 4px; padding: 8px 16px; color: white; font-size: inherit; diff --git a/actionbutton/actionbutton.js b/actionbutton/actionbutton.js index 29b8a13d..4cc714d3 100644 --- a/actionbutton/actionbutton.js +++ b/actionbutton/actionbutton.js @@ -11,11 +11,12 @@ let app = undefined; let data = { status: 'waiting', result: null, - input: { + inputs: [{ description: null, button: null, actions: null, - } + }], + desc: null } function handleError(err) { @@ -23,10 +24,10 @@ function handleError(err) { data.status = String(err).replace(/^Error: /, ''); } -async function applyActions() { +async function applyActions(actions) { data.results = "Working..."; try { - await grist.docApi.applyUserActions(data.input.actions); + await grist.docApi.applyUserActions(actions); data.message = 'Done'; } catch (e) { data.message = `Please grant full access for writing. (${e})`; @@ -42,15 +43,22 @@ function onRecord(row, mappings) { if (!row.hasOwnProperty(column)) { throw new Error(`Need a visible column named "${column}". You can map a custom column in the Creator Panel.`); } + let btns = row[column] + // If only one action button is defined, put it within an Array + if (!Array.isArray(btns)) { + btns = [ btns ] + } const keys = ['button', 'description', 'actions']; - if (!row[column] || keys.some(k => !row[column][k])) { - const allKeys = keys.map(k => JSON.stringify(k)).join(", "); - const missing = keys.filter(k => !row[column]?.[k]).map(k => JSON.stringify(k)).join(", "); - const gristName = mappings?.[column] || column; - throw new Error(`"${gristName}" cells should contain an object with keys ${allKeys}. ` + - `Missing keys: ${missing}`); + for (btn of btns) { + if (!btn || keys.some(k => !btn[k])) { + const allKeys = keys.map(k => JSON.stringify(k)).join(", "); + const missing = keys.filter(k => !btn?.[k]).map(k => JSON.stringify(k)).join(", "); + const gristName = mappings?.[column] || column; + throw new Error(`"${gristName}" cells should contain an object with keys ${allKeys}. ` + + `Missing keys: ${missing}`); + } } - data.input = row[column]; + data.inputs = btns; } catch (err) { handleError(err); } diff --git a/actionbutton/index.html b/actionbutton/index.html index c4475fe3..c0f5e7ec 100644 --- a/actionbutton/index.html +++ b/actionbutton/index.html @@ -22,8 +22,12 @@