Skip to content

Commit 7ca9de7

Browse files
author
Artyom Podymov
committed
refactoring
1 parent b879174 commit 7ca9de7

File tree

3 files changed

+33
-49
lines changed

3 files changed

+33
-49
lines changed

redisinsight/ui/src/components/query-card/QueryCardCliPlugin/QueryCardCliPlugin.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,32 @@ const QueryCardCliPlugin = (props: Props) => {
4747

4848
const dispatch = useDispatch()
4949

50+
const sendMessageToPlugin = (data = {}) => {
51+
const event: any = document.createEvent('Event')
52+
event.initEvent('message', false, false)
53+
event.data = data
54+
event.origin = '*'
55+
pluginIframeRef?.current?.contentWindow?.dispatchEvent(event)
56+
}
57+
5058
const executeCommand = () => {
51-
const event:any = document.createEvent('Event')
52-
event.initEvent('message', true, true)
53-
event.data = {
59+
sendMessageToPlugin({
5460
event: 'executeCommand',
5561
method: currentView.activationMethod,
5662
data: { command: query, data: result, status }
57-
}
58-
event.origin = '*'
59-
pluginIframeRef?.current?.contentWindow?.dispatchEvent(event)
63+
})
6064
}
6165

6266
const sendRedisCommand = (command: string, requestId: string) => {
6367
dispatch(
6468
sendPluginCommandAction({
6569
command,
6670
onSuccessAction: (response) => {
67-
const event:any = document.createEvent('Event')
68-
event.initEvent('message', true, true)
69-
event.data = {
71+
sendMessageToPlugin({
7072
event: 'executeRedisCommand',
7173
requestId,
7274
data: response
73-
}
74-
event.origin = '*'
75-
pluginIframeRef?.current?.contentWindow?.dispatchEvent(event)
75+
})
7676
}
7777
})
7878
)
@@ -115,7 +115,6 @@ const QueryCardCliPlugin = (props: Props) => {
115115
bodyClass: theme === Theme.Dark ? 'theme_DARK' : 'theme_LIGHT',
116116
modules
117117
})
118-
// pluginIframeRef.current.src = `data:text/html;charset=utf-8,${encodeURI(html)}`
119118
// @ts-ignore
120119
pluginIframeRef.current.srcdoc = html
121120
}

redisinsight/ui/src/plugins/pluginImport.ts

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable sonarjs/no-nested-template-literals */
2+
/* eslint-disable no-restricted-globals */
23
// @ts-nocheck
34
export const importPluginScript = () => (config) => {
45
const { scriptSrc, stylesSrc, iframeId, modules, baseUrl } = JSON.parse(config)
@@ -21,10 +22,9 @@ export const importPluginScript = () => (config) => {
2122

2223
const sendMessageToMain = (data = {}) => {
2324
const event = document.createEvent('Event')
24-
event.initEvent('message', true, true)
25+
event.initEvent('message', false, false)
2526
event.data = data
2627
event.origin = '*'
27-
// eslint-disable-next-line no-restricted-globals
2828
parent.dispatchEvent(event)
2929
}
3030

@@ -36,26 +36,26 @@ export const importPluginScript = () => (config) => {
3636
iframeId,
3737
text
3838
})
39+
},
40+
setPluginLoadSucceed: () => {
41+
sendMessageToMain({
42+
event: 'loaded',
43+
iframeId,
44+
})
45+
},
46+
setPluginLoadFailed: (error) => {
47+
sendMessageToMain({
48+
event: 'error',
49+
iframeId,
50+
error,
51+
})
3952
}
4053
}
4154
}
4255

4356
const listenEvents = () => {
44-
4557
globalThis.onmessage = (e) => {
4658
if (e.data.event === events.EXECUTE_COMMAND) {
47-
const event = document.createEvent('Event')
48-
event.initEvent('message', true, true)
49-
event.data = {
50-
event: events.EXECUTE_COMMAND,
51-
method: e.data.method,
52-
data: e.data.data,
53-
plugin: globalThis.plugin,
54-
iframeId: `${iframeId}`
55-
}
56-
event.origin = '*'
57-
// eslint-disable-next-line no-restricted-globals
58-
parent.dispatchEvent(event)
5959
globalThis.plugin[e.data.method] && globalThis.plugin[e.data.method](e.data.data)
6060
}
6161

@@ -89,7 +89,7 @@ export const importPluginScript = () => (config) => {
8989

9090
export const prepareIframeHtml = (config) => {
9191
const importPluginScriptInner: string = importPluginScript().toString()
92-
const { scriptSrc, scriptPath, stylesSrc, iframeId, bodyClass } = config
92+
const { scriptSrc, scriptPath, stylesSrc, bodyClass } = config
9393
const stylesLinks = stylesSrc.map((styleSrc: string) => `<link rel="stylesheet" href=${styleSrc} />`).join('')
9494
const configString = JSON.stringify(config)
9595

@@ -106,25 +106,11 @@ export const prepareIframeHtml = (config) => {
106106
import(\`${scriptSrc}\`)
107107
.then((module) => {
108108
globalThis.plugin = { ...module.default };
109-
var event = document.createEvent('Event')
110-
event.initEvent("message", true, true);
111-
event.data = {
112-
event: 'loaded',
113-
iframeId: \`${iframeId}\`
114-
}
115-
event.origin = '*'
116-
parent.dispatchEvent(event);
109+
globalThis.PluginSDK.setPluginLoadSucceed();
117110
})
118111
.catch((e) => {
119-
var event = document.createEvent('Event')
120-
event.initEvent("message", true, true);
121-
event.data = {
122-
event: 'error',
123-
iframeId: \`${iframeId}\`,
124-
error: \`${scriptPath} not found. Check if it has been renamed or deleted and try again.\`
125-
}
126-
event.origin = '*'
127-
parent.dispatchEvent(event);
112+
var error = \`${scriptPath} not found. Check if it has been renamed or deleted and try again.\`
113+
globalThis.PluginSDK.setPluginLoadFailed(error)
128114
})
129115
</script>
130116
<script src="${scriptSrc}" type="module"></script>

tests/e2e/tests/critical-path/workbench/scripting-area.e2e.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ test.skip('Verify that user when he have more than 10 results can request to vie
8888
await workbenchPage.sendCommandInWorkbench('FT.DROPINDEX products DD');
8989
});
9090
//skipped due the inaccessibility of the iframe
91-
test.only.after(async t => {
91+
test.skip
92+
.after(async t => {
9293
//Drop index and documents
9394
await workbenchPage.sendCommandInWorkbench('FT.DROPINDEX products DD');
9495
})
@@ -104,8 +105,6 @@ test.only.after(async t => {
104105
//Send search command
105106
await workbenchPage.sendCommandInWorkbench(searchCommand);
106107
//Check that result is displayed in Table view
107-
t.wait(10000)
108-
t.debug()
109108
await t.expect(workbenchPage.queryTableResult.exists).ok('The result is displayed in Table view');
110109
//Select Text view type
111110
await workbenchPage.selectViewTypeText();

0 commit comments

Comments
 (0)