From 7941e59b120bf279f68eb27670eb007fc858ac73 Mon Sep 17 00:00:00 2001 From: Sandra Illi Villarreal Date: Tue, 20 Jul 2021 16:49:16 -0700 Subject: [PATCH 1/2] Notes input block and context block testing --- nodejs/listeners/views/newTaskModal.js | 2 +- .../20210715225839-add-task-notes.js | 17 ++++++++++ nodejs/models/task.js | 2 ++ .../app-home/open-tasks-view.js | 34 +++++++++++++++++-- nodejs/user-interface/modals/new-task.js | 7 ++++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 nodejs/migrations/20210715225839-add-task-notes.js diff --git a/nodejs/listeners/views/newTaskModal.js b/nodejs/listeners/views/newTaskModal.js index ea5dd45..f5eb07a 100644 --- a/nodejs/listeners/views/newTaskModal.js +++ b/nodejs/listeners/views/newTaskModal.js @@ -73,7 +73,7 @@ module.exports = (app) => { await task.save(); await task.setCreator(user); await task.setCurrentAssignee(selectedUserObject); - + if (task.dueDate) { const dateObject = DateTime.fromJSDate(task.dueDate); // The `chat.scheduleMessage` endpoint only accepts messages in the next 120 days, diff --git a/nodejs/migrations/20210715225839-add-task-notes.js b/nodejs/migrations/20210715225839-add-task-notes.js new file mode 100644 index 0000000..82da775 --- /dev/null +++ b/nodejs/migrations/20210715225839-add-task-notes.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => queryInterface.addColumn( + 'Tasks', + 'notes', + { + type: Sequelize.STRING, + allowNull: true, + }, + ), + + down: async (queryInterface) => queryInterface.removeColumn( + 'Tasks', + 'notes', + ), +}; diff --git a/nodejs/models/task.js b/nodejs/models/task.js index 61b61cb..2e19113 100644 --- a/nodejs/models/task.js +++ b/nodejs/models/task.js @@ -24,6 +24,8 @@ module.exports = (sequelize, DataTypes) => { }, dueDate: DataTypes.DATE, scheduledMessageId: DataTypes.STRING, + //maybe delete later? + notes: DataTypes.STRING, }, { sequelize, diff --git a/nodejs/user-interface/app-home/open-tasks-view.js b/nodejs/user-interface/app-home/open-tasks-view.js index 3e24456..c3fe077 100644 --- a/nodejs/user-interface/app-home/open-tasks-view.js +++ b/nodejs/user-interface/app-home/open-tasks-view.js @@ -1,5 +1,6 @@ +// added Blocks and Context blocks const { - HomeTab, Header, Divider, Section, Actions, Elements, Input, Bits, + HomeTab, Header, Divider, Section, Actions, Elements, Input, Bits, Context, Blocks, } = require('slack-block-builder'); const pluralize = require('pluralize'); const { DateTime } = require('luxon'); @@ -13,6 +14,8 @@ module.exports = (openTasks) => { ), ); + //console.log(body) + if (openTasks.length === 0) { homeTab.blocks( Header({ text: 'No open tasks' }), @@ -33,21 +36,48 @@ module.exports = (openTasks) => { const end = openTasks.length; const maxOptionsLength = 10; + // LEAVING THIS UNTOUCHED FOR NOW + + // for (start, end; start < end; start += maxOptionsLength) { + // holdingArray = openTasks.slice(start, start + maxOptionsLength); + // tasksInputsArray.push( + // Input({ label: ' ', blockId: `open-task-status-change-${start}` }).dispatchAction().element(Elements.Checkboxes({ actionId: 'blockOpenTaskCheckboxClicked' }).options(holdingArray.map((task) => { + // const option = { + // text: `*${task.title}*`, + // value: `open-task-${task.id}`, + // }; + // if (task.dueDate) { + // option.description = `Due ${DateTime.fromJSDate(task.dueDate).toRelativeCalendar()}`; + // } + // return Bits.Option(option); + // }))), + // ); + // } + + // SANDRA TESTING + for (start, end; start < end; start += maxOptionsLength) { holdingArray = openTasks.slice(start, start + maxOptionsLength); tasksInputsArray.push( Input({ label: ' ', blockId: `open-task-status-change-${start}` }).dispatchAction().element(Elements.Checkboxes({ actionId: 'blockOpenTaskCheckboxClicked' }).options(holdingArray.map((task) => { + //Below adding a context block as a variable and passed it Bits.Option + //let context = Blocks.Context().elements([Elements.TextInput({text:"this is a context block"})],[Elements.TextInput({text:"this is another context block"})]) const option = { text: `*${task.title}*`, value: `open-task-${task.id}`, }; if (task.dueDate) { - option.description = `Due ${DateTime.fromJSDate(task.dueDate).toRelativeCalendar()}`; + option.description = `:spiral_calendar_pad:Due ${DateTime.fromJSDate(task.dueDate).toRelativeCalendar()}`; } + //Tried adding this line with some hardcoded text for each element but that didn't work either. + //I don't think TextInput can be passed in .elements but if that's the case documentation does not show how add mrkdwn elements to a Context block? + //Context().elements([Elements.TextInput({text:`something`})],[Elements.TextInput({text:`something else`})]) return Bits.Option(option); }))), ); } + + homeTab.blocks( Header({ text: `You have ${openTasks.length} open ${pluralize('task', openTasks.length)}` }), Divider(), diff --git a/nodejs/user-interface/modals/new-task.js b/nodejs/user-interface/modals/new-task.js index bc058be..75d5166 100644 --- a/nodejs/user-interface/modals/new-task.js +++ b/nodejs/user-interface/modals/new-task.js @@ -35,5 +35,12 @@ module.exports = (prefilledTitle, currentUser) => { actionId: 'taskDueTime', }), ), + Blocks.Input({ label: 'Notes', blockId: 'taskNotes', optional: true }).element( + Elements.TextInput({ + actionId: 'taskNotes', + maxLength: 300, + }) + .multiline(true), + ), ).buildToJSON(); }; From 63e3ee22a9cfa57d26cb7fdbcfc8c15f3b6d42e2 Mon Sep 17 00:00:00 2001 From: Sandra Illi Villarreal Date: Tue, 20 Jul 2021 16:57:59 -0700 Subject: [PATCH 2/2] fix linting errors --- nodejs/listeners/views/newTaskModal.js | 1 - nodejs/migrations/20210715225839-add-task-notes.js | 2 -- nodejs/models/task.js | 2 +- nodejs/user-interface/app-home/open-tasks-view.js | 13 +++++-------- nodejs/user-interface/modals/new-task.js | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/nodejs/listeners/views/newTaskModal.js b/nodejs/listeners/views/newTaskModal.js index f5eb07a..0be27a2 100644 --- a/nodejs/listeners/views/newTaskModal.js +++ b/nodejs/listeners/views/newTaskModal.js @@ -73,7 +73,6 @@ module.exports = (app) => { await task.save(); await task.setCreator(user); await task.setCurrentAssignee(selectedUserObject); - if (task.dueDate) { const dateObject = DateTime.fromJSDate(task.dueDate); // The `chat.scheduleMessage` endpoint only accepts messages in the next 120 days, diff --git a/nodejs/migrations/20210715225839-add-task-notes.js b/nodejs/migrations/20210715225839-add-task-notes.js index 82da775..f7360b3 100644 --- a/nodejs/migrations/20210715225839-add-task-notes.js +++ b/nodejs/migrations/20210715225839-add-task-notes.js @@ -1,5 +1,3 @@ -'use strict'; - module.exports = { up: async (queryInterface, Sequelize) => queryInterface.addColumn( 'Tasks', diff --git a/nodejs/models/task.js b/nodejs/models/task.js index 2e19113..04b72c3 100644 --- a/nodejs/models/task.js +++ b/nodejs/models/task.js @@ -24,7 +24,7 @@ module.exports = (sequelize, DataTypes) => { }, dueDate: DataTypes.DATE, scheduledMessageId: DataTypes.STRING, - //maybe delete later? + // Unsure if this is necessary notes: DataTypes.STRING, }, { diff --git a/nodejs/user-interface/app-home/open-tasks-view.js b/nodejs/user-interface/app-home/open-tasks-view.js index c3fe077..1d4d4c3 100644 --- a/nodejs/user-interface/app-home/open-tasks-view.js +++ b/nodejs/user-interface/app-home/open-tasks-view.js @@ -14,8 +14,6 @@ module.exports = (openTasks) => { ), ); - //console.log(body) - if (openTasks.length === 0) { homeTab.blocks( Header({ text: 'No open tasks' }), @@ -60,8 +58,8 @@ module.exports = (openTasks) => { holdingArray = openTasks.slice(start, start + maxOptionsLength); tasksInputsArray.push( Input({ label: ' ', blockId: `open-task-status-change-${start}` }).dispatchAction().element(Elements.Checkboxes({ actionId: 'blockOpenTaskCheckboxClicked' }).options(holdingArray.map((task) => { - //Below adding a context block as a variable and passed it Bits.Option - //let context = Blocks.Context().elements([Elements.TextInput({text:"this is a context block"})],[Elements.TextInput({text:"this is another context block"})]) + // Below adding a context block as a variable and passed it Bits.Option + // let context = Blocks.Context().elements([Elements.TextInput({text:"this is a context block"})],[Elements.TextInput({text:"this is another context block"})]) const option = { text: `*${task.title}*`, value: `open-task-${task.id}`, @@ -69,15 +67,14 @@ module.exports = (openTasks) => { if (task.dueDate) { option.description = `:spiral_calendar_pad:Due ${DateTime.fromJSDate(task.dueDate).toRelativeCalendar()}`; } - //Tried adding this line with some hardcoded text for each element but that didn't work either. - //I don't think TextInput can be passed in .elements but if that's the case documentation does not show how add mrkdwn elements to a Context block? - //Context().elements([Elements.TextInput({text:`something`})],[Elements.TextInput({text:`something else`})]) + // Tried adding this line with some hardcoded text for each element but that didn't work either. + // I don't think TextInput can be passed in .elements but if that's the case documentation does not show how add mrkdwn elements to a Context block? + // Context().elements([Elements.TextInput({text:`something`})],[Elements.TextInput({text:`something else`})]) return Bits.Option(option); }))), ); } - homeTab.blocks( Header({ text: `You have ${openTasks.length} open ${pluralize('task', openTasks.length)}` }), Divider(), diff --git a/nodejs/user-interface/modals/new-task.js b/nodejs/user-interface/modals/new-task.js index 75d5166..c88180e 100644 --- a/nodejs/user-interface/modals/new-task.js +++ b/nodejs/user-interface/modals/new-task.js @@ -41,6 +41,6 @@ module.exports = (prefilledTitle, currentUser) => { maxLength: 300, }) .multiline(true), - ), + ), ).buildToJSON(); };