From f4c5447c483be0b2415fc5a74f17b78cba16cf01 Mon Sep 17 00:00:00 2001 From: Peter Fitzgibbons Date: Fri, 8 Sep 2023 15:23:25 -0700 Subject: [PATCH] Remove Zeppelin Parser from Notebook Signed-off-by: Peter Fitzgibbons --- .../__tests__/sampleZeppelinNotebooks.tsx | 359 ------------------ .../__tests__/zeppelin_parser.test.tsx | 44 --- .../components/helpers/default_parser.tsx | 79 ++-- .../components/helpers/zeppelin_parser.tsx | 149 -------- .../notebooks/components/notebook.tsx | 43 +-- 5 files changed, 44 insertions(+), 630 deletions(-) delete mode 100644 public/components/notebooks/components/helpers/__tests__/sampleZeppelinNotebooks.tsx delete mode 100644 public/components/notebooks/components/helpers/__tests__/zeppelin_parser.test.tsx delete mode 100644 public/components/notebooks/components/helpers/zeppelin_parser.tsx diff --git a/public/components/notebooks/components/helpers/__tests__/sampleZeppelinNotebooks.tsx b/public/components/notebooks/components/helpers/__tests__/sampleZeppelinNotebooks.tsx deleted file mode 100644 index db07da1c5..000000000 --- a/public/components/notebooks/components/helpers/__tests__/sampleZeppelinNotebooks.tsx +++ /dev/null @@ -1,359 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -// Sample notebook with all input and output -export const sampleNotebook1 = { - paragraphs: [ - { - text: - "%md \n\n### Hi Everyone\n* Here's a demo on **OpenSearch Dashboards Notebooks**\n* You may use the top left buttons to play around with notebooks and Paragraphs", - user: 'anonymous', - dateUpdated: '2020-08-20 21:15:04.590', - config: {}, - settings: { params: {}, forms: {} }, - results: { - code: 'SUCCESS', - msg: [ - { - type: 'HTML', - data: - '
\n

Hi Everyone

\n
    \n
  • Here’s a demo on OpenSearch Dashboards Notebooks
  • \n
  • You may use the top left buttons to play around with notebooks and Paragraphs
  • \n
\n\n
', - }, - ], - }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958104590_901298942', - id: 'paragraph_1596519508360_932236116', - dateCreated: '2020-08-20 21:15:04.590', - status: 'READY', - }, - { - title: 'VISUALIZATION', - text: - '%sh #vizobject:{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - user: 'anonymous', - dateUpdated: '2020-08-20 21:25:28.588', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958728587_1310320520', - id: 'paragraph_1597958728587_1310320520', - dateCreated: '2020-08-20 21:25:28.587', - status: 'READY', - }, - ], - name: 'Embed Vizualization', - id: '2FJH8PW8K', - defaultInterpreterGroup: 'spark', - version: '0.9.0-preview2', - noteParams: {}, - noteForms: {}, - angularObjects: {}, - config: { isZeppelinNotebookCronEnable: false }, - info: {}, -}; - -// Parsed Output of sample notebook1 -export const sampleParsedParagraghs1 = [ - { - uniqueId: 'paragraph_1596519508360_932236116', - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: false, - vizObjectInput: '', - id: 1, - inp: - "%md \n\n### Hi Everyone\n* Here's a demo on **OpenSearch Dashboards Notebooks**\n* You may use the top left buttons to play around with notebooks and Paragraphs", - lang: 'text/x-', - editorLanguage: '', - typeOut: ['HTML'], - out: [ - '
\n

Hi Everyone

\n
    \n
  • Here’s a demo on OpenSearch Dashboards Notebooks
  • \n
  • You may use the top left buttons to play around with notebooks and Paragraphs
  • \n
\n\n
', - ], - }, - { - uniqueId: 'paragraph_1597958728587_1310320520', - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: true, - vizObjectInput: - '{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - id: 2, - inp: - '%sh #vizobject:{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - lang: 'text/x-', - editorLanguage: '', - typeOut: [], - out: [], - }, -]; - -// Sample notebook with all input and cleared outputs -export const sampleNotebook2 = { - paragraphs: [ - { - text: - "%md \n\n### Hi Everyone\n* Here's a demo on **OpenSearch Dashboards Notebooks**\n* You may use the top left buttons to play around with notebooks and Paragraphs", - user: 'anonymous', - dateUpdated: '2020-08-20 21:15:04.590', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958104590_901298942', - id: 'paragraph_1596519508360_932236116', - dateCreated: '2020-08-20 21:15:04.590', - status: 'READY', - }, - { - title: 'Paragraph inserted', - text: '%md\n\n## Greetings!\n* Yay! you may import and export me ', - user: 'anonymous', - dateUpdated: '2020-08-20 21:15:04.590', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958104590_1715920734', - id: 'paragraph_1596742076640_674206137', - dateCreated: '2020-08-20 21:15:04.590', - status: 'READY', - }, - { - title: 'Paragraph inserted', - text: - "%md\n\n### Let's use Visualization API with dashboard container to embed Visualizations in notebooks\n2. **Unpin** the container to *edit the size* or *delete it*\n3. **Refresh** the container after *date is changed*", - user: 'anonymous', - dateUpdated: '2020-08-20 21:15:04.590', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958104590_931410594', - id: 'paragraph_1596524302932_2112910756', - dateCreated: '2020-08-20 21:15:04.590', - status: 'READY', - }, - { - title: 'VISUALIZATION', - text: - '%sh #vizobject:{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - user: 'anonymous', - dateUpdated: '2020-08-20 21:25:28.588', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958728587_1310320520', - id: 'paragraph_1597958728587_1310320520', - dateCreated: '2020-08-20 21:25:28.587', - status: 'READY', - }, - ], - name: 'Embed Vizualization', - id: '2FJH8PW8K', - defaultInterpreterGroup: 'spark', - version: '0.9.0-preview2', - noteParams: {}, - noteForms: {}, - angularObjects: {}, - config: { isZeppelinNotebookCronEnable: false }, - info: {}, -}; - -// Parsed Output of sample notebook2 -export const sampleParsedParagraghs2 = [ - { - uniqueId: 'paragraph_1596519508360_932236116', - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: false, - vizObjectInput: '', - id: 1, - inp: - "%md \n\n### Hi Everyone\n* Here's a demo on **OpenSearch Dashboards Notebooks**\n* You may use the top left buttons to play around with notebooks and Paragraphs", - lang: 'text/x-', - editorLanguage: '', - typeOut: [], - out: [], - }, - { - uniqueId: 'paragraph_1596742076640_674206137', - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: false, - vizObjectInput: '', - id: 2, - inp: '%md\n\n## Greetings!\n* Yay! you may import and export me ', - lang: 'text/x-md', - editorLanguage: 'md', - typeOut: [], - out: [], - }, - { - uniqueId: 'paragraph_1596524302932_2112910756', - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: false, - vizObjectInput: '', - id: 3, - inp: - "%md\n\n### Let's use Visualization API with dashboard container to embed Visualizations in notebooks\n2. **Unpin** the container to *edit the size* or *delete it*\n3. **Refresh** the container after *date is changed*", - lang: 'text/x-md', - editorLanguage: 'md', - typeOut: [], - out: [], - }, - { - uniqueId: 'paragraph_1597958728587_1310320520', - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: true, - vizObjectInput: - '{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - id: 4, - inp: - '%sh #vizobject:{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - lang: 'text/x-', - editorLanguage: '', - typeOut: [], - out: [], - }, -]; - -// Sample notebook with no paragraph Id -export const sampleNotebook3 = { - paragraphs: [ - { - text: - "%md \n\n### Hi Everyone\n* Here's a demo on **OpenSearch Dashboards Notebooks**\n* You may use the top left buttons to play around with notebooks and Paragraphs", - user: 'anonymous', - dateUpdated: '2020-08-20 21:15:04.590', - config: {}, - settings: { params: {}, forms: {} }, - results: { - code: 'SUCCESS', - msg: [ - { - type: 'HTML', - data: - '
\n

Hi Everyone

\n
    \n
  • Here’s a demo on OpenSearch Dashboards Notebooks
  • \n
  • You may use the top left buttons to play around with notebooks and Paragraphs
  • \n
\n\n
', - }, - ], - }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958104590_901298942', - dateCreated: '2020-08-20 21:15:04.590', - status: 'READY', - }, - ], - name: 'Embed Vizualization', - id: '2FJH8PW8K', - defaultInterpreterGroup: 'spark', - version: '0.9.0-preview2', - noteParams: {}, - noteForms: {}, - angularObjects: {}, - config: { isZeppelinNotebookCronEnable: false }, - info: {}, -}; - -// Sample notebook with no VISUALIZAITON title -export const sampleNotebook4 = { - paragraphs: [ - { - text: - '%sh #vizobject:{"viewMode":"view","panels":{"1":{"gridData":{"x":15,"y":0,"w":20,"h":20,"i":"1"},"type":"visualization","explicitInput":{"id":"1","savedObjectId":"06cf9c40-9ee8-11e7-8711-e7a007dcef99"}}},"isFullScreenMode":false,"filters":[],"useMargins":false,"id":"iab4eaba1-e32b-11ea-aac8-99f209533253","timeRange":{"to":"2020-08-20T21:25:28.538Z","from":"2020-07-21T21:25:28.538Z"},"title":"embed_viz_iab4eaba1-e32b-11ea-aac8-99f209533253","query":{"query":"","language":"lucene"},"refreshConfig":{"pause":true,"value":15}}', - user: 'anonymous', - dateUpdated: '2020-08-20 21:25:28.588', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958728587_1310320520', - id: 'paragraph_1597958728587_1310320520', - dateCreated: '2020-08-20 21:25:28.587', - status: 'READY', - }, - ], - name: 'Embed Vizualization', - id: '2FJH8PW8K', - defaultInterpreterGroup: 'spark', - version: '0.9.0-preview2', - noteParams: {}, - noteForms: {}, - angularObjects: {}, - config: { isZeppelinNotebookCronEnable: false }, - info: {}, -}; - -// Sample notebook with no input and output -export const sampleNotebook5 = { - paragraphs: [ - { - user: 'anonymous', - dateUpdated: '2020-08-20 21:25:28.588', - config: {}, - settings: { params: {}, forms: {} }, - apps: [], - runtimeInfos: {}, - progressUpdateIntervalMs: 500, - jobName: 'paragraph_1597958728587_1310320520', - id: 'paragraph_1597958728587_1310320520', - dateCreated: '2020-08-20 21:25:28.587', - status: 'READY', - }, - ], - name: 'Embed Vizualization', - id: '2FJH8PW8K', - defaultInterpreterGroup: 'spark', - version: '0.9.0-preview2', - noteParams: {}, - noteForms: {}, - angularObjects: {}, - config: { isZeppelinNotebookCronEnable: false }, - info: {}, -}; diff --git a/public/components/notebooks/components/helpers/__tests__/zeppelin_parser.test.tsx b/public/components/notebooks/components/helpers/__tests__/zeppelin_parser.test.tsx deleted file mode 100644 index e6c5b351e..000000000 --- a/public/components/notebooks/components/helpers/__tests__/zeppelin_parser.test.tsx +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { zeppelinParagraphParser } from '../zeppelin_parser'; -import { - sampleNotebook1, - sampleNotebook2, - sampleNotebook3, - sampleNotebook4, - sampleNotebook5, - sampleParsedParagraghs1, - sampleParsedParagraghs2, -} from './sampleZeppelinNotebooks'; - -// Perfect schema -describe('Testing Zeppelin backend parser function with perfect schema', () => { - test('zeppelinParagraphParserTest1', (done) => { - const parsedParagraphs1 = zeppelinParagraphParser(sampleNotebook1.paragraphs); - const parsedParagraphs2 = zeppelinParagraphParser(sampleNotebook2.paragraphs); - const parsedParagraphs3 = zeppelinParagraphParser([]); - expect(parsedParagraphs1).toEqual(sampleParsedParagraghs1); - expect(parsedParagraphs2).toEqual(sampleParsedParagraghs2); - expect(parsedParagraphs3).toEqual([]); - done(); - }); -}); - -// Issue in schema -describe('Testing default backend parser function with wrong schema', () => { - test('zeppelinParagraphParserTest2', (done) => { - expect(() => { - const parsedParagraphs1 = zeppelinParagraphParser(sampleNotebook3.paragraphs); - }).toThrow(Error); - expect(() => { - const parsedParagraphs2 = zeppelinParagraphParser(sampleNotebook4.paragraphs); - }).toThrow(Error); - expect(() => { - const parsedParagraphs3 = zeppelinParagraphParser(sampleNotebook5.paragraphs); - }).toThrow(Error); - done(); - }); -}); diff --git a/public/components/notebooks/components/helpers/default_parser.tsx b/public/components/notebooks/components/helpers/default_parser.tsx index c38dad3cd..7647d80f3 100644 --- a/public/components/notebooks/components/helpers/default_parser.tsx +++ b/public/components/notebooks/components/helpers/default_parser.tsx @@ -3,21 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ParaType } from '../../../../../common/types/notebooks'; - // Get the type of output and result in a default notebook paragraph // Param: Default Backend Paragraph const parseOutput = (paraObject: any) => { try { - let outputType = []; - let result = []; - paraObject.output.map((output: { outputType: string; result: string }) => { - outputType.push(output.outputType); - result.push(output.result); - }); return { - outputType: outputType, - outputData: result, + outputType: paraObject.output.map(({ outputType }) => outputType), + outputData: paraObject.output.map(({ result }) => result), }; } catch (error) { return { @@ -46,7 +38,7 @@ const parseInputType = (paraObject: any) => { const parseVisualization = (paraObject: any) => { try { if (paraObject.input.inputType.includes('VISUALIZATION')) { - let vizContent = paraObject.input.inputText; + const vizContent = paraObject.input.inputText; const startDate = new Date(); startDate.setDate(startDate.getDate() - 30); let visStartTime = startDate.toISOString(); @@ -76,43 +68,42 @@ const parseVisualization = (paraObject: any) => { } }; +const parseBackendParagraph = (paraObject, index) => { + const codeLanguage = parseInputType(paraObject); + const vizParams = parseVisualization(paraObject); + const message = parseOutput(paraObject); + + return { + uniqueId: paraObject.id, + isRunning: false, + inQueue: false, + isSelected: false, + isInputHidden: false, + isOutputHidden: false, + showAddPara: false, + isVizualisation: vizParams.isViz, + vizObjectInput: vizParams.VizObject, + id: index + 1, + inp: paraObject.input.inputText || '', + lang: 'text/x-' + codeLanguage, + editorLanguage: codeLanguage, + typeOut: message.outputType, + out: message.outputData, + isInputExpanded: false, + isOutputStale: false, + paraRef: undefined, + paraDivRef: undefined, + visStartTime: vizParams.visStartTime, + visEndTime: vizParams.visEndTime, + visSavedObjId: vizParams.visSavedObjId, + }; +}; + // Placeholder for default parser // Param: Default Backend Paragraph export const defaultParagraphParser = (defaultBackendParagraphs: any) => { - let parsedPara: Array = []; try { - defaultBackendParagraphs.map((paraObject: any, index: number) => { - const codeLanguage = parseInputType(paraObject); - const vizParams = parseVisualization(paraObject); - const message = parseOutput(paraObject); - - let tempPara: ParaType = { - uniqueId: paraObject.id, - isRunning: false, - inQueue: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: vizParams.isViz, - vizObjectInput: vizParams.VizObject, - id: index + 1, - inp: paraObject.input.inputText || '', - lang: 'text/x-' + codeLanguage, - editorLanguage: codeLanguage, - typeOut: message.outputType, - out: message.outputData, - isInputExpanded: false, - isOutputStale: false, - paraRef: undefined, - paraDivRef: undefined, - visStartTime: vizParams.visStartTime, - visEndTime: vizParams.visEndTime, - visSavedObjId: vizParams.visSavedObjId, - }; - parsedPara.push(tempPara); - }); - return parsedPara; + return defaultBackendParagraphs.map(parseBackendParagraph); } catch (error) { throw new Error('Parsing Paragraph Issue ' + error); } diff --git a/public/components/notebooks/components/helpers/zeppelin_parser.tsx b/public/components/notebooks/components/helpers/zeppelin_parser.tsx deleted file mode 100644 index f2293c3a7..000000000 --- a/public/components/notebooks/components/helpers/zeppelin_parser.tsx +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -/* This file contains parsing functions - * These functions have to be changed based on backend configuration - * If backend changes the incoming paragraph structures may change, so parsing adapts to it - */ - -import { ParaType } from '../../../common'; - -const visualizationPrefix = '%sh #vizobject:'; -const observabilityVisualizationPrefix = '%sh #observabilityviz:'; - -const langSupport = { - '%sh': 'shell', - '%md': 'md', - '%python': 'python', - '%opensearchsql': 'sql', - '%elasticsearch': 'json', -}; - -// Get the coding language from a Zeppelin paragraph input -// Param: textHeader-> header on a Zeppelin paragraph example "%md" -const parseCodeLanguage = (textHeader: string) => { - const codeLanguage = langSupport[textHeader]; - return codeLanguage || ''; -}; - -// Get the type of output message from a Zeppelin paragraph -// Param: Zeppelin Paragraph -const parseMessage = (paraObject: any) => { - try { - let mtype = []; - let mdata = []; - paraObject.results.msg.map((msg: { type: string; data: string }) => { - mtype.push(msg.type); - mdata.push(msg.data); - }); - return { - outputType: mtype, - outputData: mdata, - }; - } catch (error) { - return { - outputType: [], - outputData: [], - }; - } -}; - -// Get the type of output message from a Zeppelin paragraph -// Param: Zeppelin Paragraph -const parseText = (paraObject: any) => { - if ('text' in paraObject) { - return paraObject.text; - } else { - throw new Error('Input text parse issue'); - } -}; - -// Get the visualization from a Zeppelin Paragraph input -// All Visualizations in Zeppelin are stored as shell comment -> "%sh #vizobject:" -// TODO: This is a workaround need to look for better solutions -// Param: Zeppelin Paragraph -const parseVisualization = (paraObject: any) => { - let vizContent = ''; - if ( - paraObject.hasOwnProperty('text') && - paraObject.text.substring(0, 15) === visualizationPrefix - ) { - if (paraObject.title !== 'VISUALIZATION') { - throw new Error('Visualization parse issue'); - } - vizContent = paraObject.text.substring(15); - return { - isViz: true, - VizObject: vizContent, - }; - } - - if ( - paraObject.hasOwnProperty('text') && - paraObject.text.substring(0, 22) === observabilityVisualizationPrefix - ) { - if (paraObject.title !== 'OBSERVABILITY_VISUALIZATION') { - throw new Error('Visualization parse issue'); - } - vizContent = paraObject.text.substring(22); - return { - isViz: true, - VizObject: vizContent, - }; - } - - return { - isViz: false, - VizObject: vizContent, - }; -}; - -// This parser is used to get paragraph id -// Param: Zeppelin Paragraph -const parseId = (paraObject: any) => { - if ('id' in paraObject) { - return paraObject.id; - } else { - throw new Error('Id not found in paragraph'); - } -}; - -// This parser helps to convert Zeppelin paragraphs to a common ParaType format -// This parsing makes any backend notebook compatible with notebooks plugin -export const zeppelinParagraphParser = (zeppelinBackendParagraphs: any) => { - let parsedPara: Array = []; - try { - zeppelinBackendParagraphs.map((paraObject: ParaType, index: number) => { - const paragraphId = parseId(paraObject); - const vizParams = parseVisualization(paraObject); - const inputParam = parseText(paraObject); - const codeLanguage = parseCodeLanguage(inputParam.split('\n')[0].split('.')[0]); - const message = parseMessage(paraObject); - - let tempPara = { - uniqueId: paragraphId, - isRunning: false, - inQueue: false, - ishovered: false, - isSelected: false, - isInputHidden: false, - isOutputHidden: false, - showAddPara: false, - isVizualisation: vizParams.isViz, - vizObjectInput: vizParams.VizObject, - id: index + 1, - inp: inputParam, - lang: 'text/x-' + codeLanguage, - editorLanguage: codeLanguage, - typeOut: message.outputType, - out: message.outputData, - }; - parsedPara.push(tempPara); - }); - return parsedPara; - } catch (error) { - throw new Error('Parsing Paragraph Issue ' + error); - } -}; diff --git a/public/components/notebooks/components/notebook.tsx b/public/components/notebooks/components/notebook.tsx index e5494ebed..9a7d720a7 100644 --- a/public/components/notebooks/components/notebook.tsx +++ b/public/components/notebooks/components/notebook.tsx @@ -30,11 +30,7 @@ import { RouteComponentProps } from 'react-router-dom'; import PPLService from '../../../services/requests/ppl'; import { ChromeBreadcrumb, CoreStart } from '../../../../../../src/core/public'; import { DashboardStart } from '../../../../../../src/plugins/dashboard/public'; -import { - CREATE_NOTE_MESSAGE, - NOTEBOOKS_API_PREFIX, - NOTEBOOKS_SELECTED_BACKEND, -} from '../../../../common/constants/notebooks'; +import { CREATE_NOTE_MESSAGE, NOTEBOOKS_API_PREFIX } from '../../../../common/constants/notebooks'; import { UI_DATE_FORMAT } from '../../../../common/constants/shared'; import { ParaType } from '../../../../common/types/notebooks'; import { GenerateReportLoadingModal } from './helpers/custom_modals/reporting_loading_modal'; @@ -45,7 +41,6 @@ import { contextMenuViewReports, generateInContextReport, } from './helpers/reporting_context_menu_helper'; -import { zeppelinParagraphParser } from './helpers/zeppelin_parser'; import { Paragraphs } from './paragraph_components/paragraphs'; const panelStyles: CSS.Properties = { float: 'left', @@ -90,7 +85,6 @@ interface NotebookState { dateModified: string; paragraphs: any; // notebook paragraphs fetched from API parsedPara: ParaType[]; // paragraphs parsed to a common format - vizPrefix: string; // prefix for visualizations in Zeppelin Adaptor isAddParaPopoverOpen: boolean; isParaActionsPopoverOpen: boolean; isNoteActionsPopoverOpen: boolean; @@ -112,7 +106,6 @@ export class Notebook extends Component { dateModified: '', paragraphs: [], parsedPara: [], - vizPrefix: '', isAddParaPopoverOpen: false, isParaActionsPopoverOpen: false, isNoteActionsPopoverOpen: false, @@ -138,20 +131,12 @@ export class Notebook extends Component { // parse paragraphs based on backend parseParagraphs = (paragraphs: any[]): ParaType[] => { try { - let parsedPara; - // @ts-ignore - if (NOTEBOOKS_SELECTED_BACKEND === 'ZEPPELIN') { - parsedPara = zeppelinParagraphParser(paragraphs); - this.setState({ vizPrefix: '%sh #vizobject:' }); - } else { - parsedPara = defaultParagraphParser(paragraphs); - } - parsedPara.forEach((para: ParaType) => { - para.isInputExpanded = this.state.selectedViewId === 'input_only'; - para.paraRef = React.createRef(); - para.paraDivRef = React.createRef(); - }); - return parsedPara; + return defaultParagraphParser(paragraphs).map((para) => ({ + ...para, + isInputExpanded: this.state.selectedViewId === 'input_only', + paraRef: React.createRef(), + paraDivRef: React.createRef(), + })); } catch (err) { this.props.setToast( 'Error parsing paragraphs, please make sure you have the correct permission.', @@ -184,8 +169,7 @@ export class Notebook extends Component { paragraphSelector = (index: number) => { const parsedPara = this.state.parsedPara; this.state.parsedPara.map((_: ParaType, idx: number) => { - if (index === idx) parsedPara[idx].isSelected = true; - else parsedPara[idx].isSelected = false; + parsedPara[idx].isSelected = index === idx; }); this.setState({ parsedPara }); }; @@ -471,22 +455,13 @@ export class Notebook extends Component { }; // Backend call to update and run contents of paragraph - updateRunParagraph = ( - para: ParaType, - index: number, - vizObjectInput?: string, - paraType?: string - ) => { + updateRunParagraph = (para: ParaType, index: number) => { this.showParagraphRunning(index); - if (vizObjectInput) { - para.inp = this.state.vizPrefix + vizObjectInput; // "%sh check" - } const paraUpdateObject = { noteId: this.props.openedNoteId, paragraphId: para.uniqueId, paragraphInput: para.inp, - paragraphType: paraType || '', }; return this.props.http