sls-dev-tools
Version:
The Dev Tools for the Serverless World
52 lines (42 loc) • 1.35 kB
JavaScript
;
var _box = require("../components/box");
var _modalLayout = require("../components/modalLayout");
var _modalTitle = require("../components/modalTitle");
var _interactiveList = require("../components/interactiveList");
function updateStackTable(table, stacks) {
table.setItems(stacks);
}
function updateStackNames(api, table, screen) {
api.describeStacks({}, (err, data) => {
if (err) {
console.error(err);
} else {
const stacks = [];
data.Stacks.forEach(stack => {
stacks.push(stack.StackName);
});
updateStackTable(table, stacks);
screen.render();
}
});
}
const stackWizardModal = (screen, cloudformation, application) => {
const wizardLayout = new _modalLayout.ModalLayout(screen, 112, 27, true);
const closeModal = () => {
application.returnFocus();
wizardLayout.destroy();
};
new _modalTitle.ModalTitle(wizardLayout, 110, "Select your stack");
const stackTable = new _interactiveList.InteractiveList(wizardLayout, 110, 20, "Stacks");
new _box.Box(wizardLayout, 110, 4, "Arrow keys to navigate | ENTER to select stack");
updateStackNames(cloudformation, stackTable, screen);
stackTable.focus();
stackTable.key(["enter"], () => {
closeModal();
});
screen.render();
return stackTable;
};
module.exports = {
stackWizardModal
};