UNPKG

sls-dev-tools

Version:

The Dev Tools for the Serverless World

55 lines (45 loc) 1.66 kB
"use strict"; var _index = require("./index"); var _box = require("../components/box"); var _modalLayout = require("../components/modalLayout"); var _modalTitle = require("../components/modalTitle"); var _interactiveList = require("../components/interactiveList"); function updateSchemaTable(api, registry, table) { api.listSchemas({ RegistryName: registry }, (err, data) => { if (err) { console.error(err); } else { const schemas = []; data.Schemas.forEach(s => schemas.push(s.SchemaName)); table.setItems(schemas); } }); } const eventSchemaModal = (screen, eventBridge, application, api, registry, injectEvent) => { const eventSchemaLayout = new _modalLayout.ModalLayout(screen, 112, 27, true); const closeModal = () => { // Store all text to populate modal when next opened application.setIsModalOpen(false); application.returnFocus(); eventSchemaLayout.destroy(); }; new _modalTitle.ModalTitle(eventSchemaLayout, 110, "Event Schemas"); const schemaTable = new _interactiveList.InteractiveList(eventSchemaLayout, 110, 20, "Schemas"); new _box.Box(eventSchemaLayout, 110, 4, "Arrow keys to navigate | ENTER to select \nESC to close"); updateSchemaTable(api, registry, schemaTable); schemaTable.focus(); schemaTable.key(["enter"], () => { const schema = schemaTable.ritems[schemaTable.selected]; eventSchemaLayout.destroy(); return (0, _index.eventModal)(screen, eventBridge, application, api, registry, schema, injectEvent); }); schemaTable.key(["escape"], () => { // Discard modal closeModal(); }); }; module.exports = { eventSchemaModal };