Skip to content

Commit 0379e07

Browse files
committed
Merge remote-tracking branch 'origin/redisgraph-plugin' into redisgraph-plugin
2 parents cec8a6e + 4da60f6 commit 0379e07

File tree

9 files changed

+114
-21
lines changed

9 files changed

+114
-21
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ const QueryCardCliPlugin = (props: Props) => {
6666
pluginIframeRef?.current?.contentWindow?.dispatchEvent(event)
6767
}
6868

69-
const executeCommand = () => {
69+
const executeCommand = (method: string) => {
7070
sendMessageToPlugin({
7171
event: 'executeCommand',
72-
method: currentView.activationMethod,
72+
method,
7373
data: { command: query, data: result }
7474
})
7575
}
@@ -167,7 +167,7 @@ const QueryCardCliPlugin = (props: Props) => {
167167
pluginApi.onEvent(generatedIframeNameRef.current, PluginEvents.loaded, () => {
168168
setIsPluginLoaded(true)
169169
setError('')
170-
executeCommand()
170+
executeCommand(currentView.activationMethod)
171171
})
172172

173173
pluginApi.onEvent(generatedIframeNameRef.current, PluginEvents.error, (error: string) => {
@@ -226,7 +226,7 @@ const QueryCardCliPlugin = (props: Props) => {
226226
setCurrentPlugin(plugin?.name || null)
227227
return
228228
}
229-
executeCommand()
229+
executeCommand(view.activationMethod)
230230
}
231231
}, [result, id])
232232

redisinsight/ui/src/components/query/Query/Query.tsx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,33 @@ import { KeyboardShortcut } from 'uiSrc/components'
2727
import { ThemeContext } from 'uiSrc/contexts/themeContext'
2828
import { appRedisCommandsSelector } from 'uiSrc/slices/app/redis-commands'
2929
import { IEditorMount, ISnippetController } from 'uiSrc/pages/workbench/interfaces'
30+
import { CommandExecutionUI } from 'uiSrc/slices/interfaces'
3031

32+
import { workbenchResultsSelector } from 'uiSrc/slices/workbench/wb-results'
3133
import styles from './styles.module.scss'
3234

3335
export interface Props {
34-
query: string;
35-
loading: boolean;
36-
setQueryEl: Function;
37-
setQuery: (script: string) => void;
38-
onSubmit: (query?: string) => void;
39-
onKeyDown?: (e: React.KeyboardEvent, script: string) => void;
36+
query: string
37+
loading: boolean
38+
setQueryEl: Function
39+
setQuery: (script: string) => void
40+
onSubmit: (query?: string) => void
41+
onKeyDown?: (e: React.KeyboardEvent, script: string) => void
4042
}
4143

4244
let decorations: string[] = []
45+
let execHistoryPos: number = 0
46+
let execHistory: CommandExecutionUI[] = []
4347

4448
const Query = (props: Props) => {
4549
const { query = '', setQuery, onKeyDown, onSubmit, setQueryEl } = props
4650
let contribution: Nullable<ISnippetController> = null
4751

48-
const {
49-
commandsArray: REDIS_COMMANDS_ARRAY,
50-
spec: REDIS_COMMANDS_SPEC
51-
} = useSelector(appRedisCommandsSelector)
52+
const { commandsArray: REDIS_COMMANDS_ARRAY, spec: REDIS_COMMANDS_SPEC } = useSelector(appRedisCommandsSelector)
53+
const { items: execHistoryItems } = useSelector(workbenchResultsSelector)
5254
const { theme } = useContext(ThemeContext)
5355
const monacoObjects = useRef<Nullable<IEditorMount>>(null)
56+
5457
let disposeCompletionItemProvider = () => {}
5558
let disposeSignatureHelpProvider = () => {}
5659

@@ -63,6 +66,12 @@ const Query = (props: Props) => {
6366
},
6467
[])
6568

69+
useEffect(() => {
70+
// HACK: The Monaco editor memoize the state and ignores updates to it
71+
execHistory = execHistoryItems
72+
execHistoryPos = 0
73+
}, [execHistoryItems])
74+
6675
useEffect(() => {
6776
if (!monacoObjects.current) return
6877
const commands = query.split('\n')
@@ -93,6 +102,7 @@ const Query = (props: Props) => {
93102
}
94103

95104
const handleSubmit = (value?: string) => {
105+
execHistoryPos = 0
96106
onSubmit(value)
97107
}
98108

@@ -112,6 +122,20 @@ const Query = (props: Props) => {
112122
}
113123
}
114124

125+
const onQuickHistoryAccess = () => {
126+
if (!monacoObjects.current) return
127+
const { editor } = monacoObjects?.current
128+
129+
const position = editor.getPosition()
130+
if (position?.lineNumber !== 1) return
131+
132+
if (execHistory[execHistoryPos]) {
133+
const command = execHistory[execHistoryPos].command || ''
134+
editor.setValue(command)
135+
execHistoryPos++
136+
}
137+
}
138+
115139
const onKeyDownMonaco = (e: monacoEditor.IKeyboardEvent) => {
116140
// trigger parameter hints
117141
if (
@@ -123,6 +147,12 @@ const Query = (props: Props) => {
123147
onTriggerParameterHints()
124148
}
125149

150+
if (
151+
e.keyCode === monaco.KeyCode.UpArrow
152+
) {
153+
onQuickHistoryAccess()
154+
}
155+
126156
if (e.keyCode === monaco.KeyCode.Enter || e.keyCode === monaco.KeyCode.Space) {
127157
onExitSnippetMode()
128158
}

redisinsight/ui/src/components/query/QueryWrapper.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import Query from './Query'
1111
import styles from './Query/styles.module.scss'
1212

1313
export interface Props {
14-
query: string;
15-
loading: boolean;
16-
setQuery: (script: string) => void;
17-
setQueryEl: Function;
18-
onKeyDown?: (e: React.KeyboardEvent, script: string) => void;
19-
onSubmit: (value?: string) => void;
14+
query: string
15+
loading: boolean
16+
setQuery: (script: string) => void
17+
setQueryEl: Function
18+
onKeyDown?: (e: React.KeyboardEvent, script: string) => void
19+
onSubmit: (value?: string) => void
2020
}
2121
const QueryWrapper = (props: Props) => {
2222
const { query = '', loading, setQuery, setQueryEl, onKeyDown, onSubmit } = props

redisinsight/ui/src/components/shortcuts-flyout/schema.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const SHORTCUTS: ShortcutGroup[] = [
4141
KEYBOARD_SHORTCUTS.workbench.nextLine,
4242
KEYBOARD_SHORTCUTS.workbench.listOfCommands,
4343
KEYBOARD_SHORTCUTS.workbench.triggerHints,
44+
KEYBOARD_SHORTCUTS.workbench.quickHistoryAccess,
4445
]
4546
},
4647
]

redisinsight/ui/src/constants/keyboardShortcuts.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const COMMON_SHORTCUTS = {
5353
triggerHints: {
5454
description: 'Trigger Command Hints',
5555
keys: ['Ctrl', 'Shift', 'Space']
56+
},
57+
quickHistoryAccess: {
58+
description: 'Quick-access to command history',
59+
keys: ['Up Arrow']
5660
}
5761
}
5862
}
@@ -108,6 +112,10 @@ const MAC_SHORTCUTS = {
108112
triggerHints: {
109113
description: 'Trigger Command Hints',
110114
keys: [(<span className="cmdSymbol"></span>), (<span className="shiftSymbol"></span>), 'Space']
115+
},
116+
quickHistoryAccess: {
117+
description: 'Quick-access to command history',
118+
keys: ['Up Arrow']
111119
}
112120
}
113121
}

scripts/build-statics.cmd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ if not exist "%PLUGINS_DIR%\redisearch" mkdir "%PLUGINS_DIR%\redisearch"
2020
if not exist "%PLUGINS_DIR%\redisearch\dist" mkdir "%PLUGINS_DIR%\redisearch\dist"
2121
xcopy "%REDISEARCH_DIR%\dist" "%PLUGINS_DIR%\redisearch\dist\" /s /e /y
2222
copy "%REDISEARCH_DIR%\package.json" "%PLUGINS_DIR%\redisearch\"
23+
24+
:: Build redisgraph plugin
25+
set REDISGRAPH_DIR=".\redisinsight\ui\src\packages\redisgraph"
26+
call yarn --cwd "%REDISGRAPH_DIR%"
27+
call yarn --cwd "%REDISGRAPH_DIR%" build
28+
if not exist "%PLUGINS_DIR%\redisgraph" mkdir "%PLUGINS_DIR%\redisgraph"
29+
if not exist "%PLUGINS_DIR%\redisgraph\dist" mkdir "%PLUGINS_DIR%\redisgraph\dist"
30+
xcopy "%REDISGRAPH_DIR%\dist" "%PLUGINS_DIR%\redisgraph\dist\" /s /e /y
31+
copy "%REDISGRAPH_DIR%\package.json" "%PLUGINS_DIR%\redisgraph\"

scripts/build-statics.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,10 @@ yarn --cwd "${REDISEARCH_DIR}"
1818
yarn --cwd "${REDISEARCH_DIR}" build
1919
mkdir -p "${PLUGINS_DIR}/redisearch"
2020
cp -R "${REDISEARCH_DIR}/dist" "${REDISEARCH_DIR}/package.json" "${PLUGINS_DIR}/redisearch"
21+
22+
# Build redisgraph plugin
23+
REDISGRAPH_DIR="./redisinsight/ui/src/packages/redisgraph"
24+
yarn --cwd "${REDISGRAPH_DIR}"
25+
yarn --cwd "${REDISGRAPH_DIR}" build
26+
mkdir -p "${PLUGINS_DIR}/redisgraph"
27+
cp -R "${REDISGRAPH_DIR}/dist" "${REDISGRAPH_DIR}/package.json" "${PLUGINS_DIR}/redisgraph"

tests/e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"redis:last": "docker run --name redis-last-version -p 7777:6379 -d redislabs/redismod",
1414
"start:app": "cross-env SERVER_STATIC_CONTENT=true yarn start:api",
1515
"test:chrome": "testcafe --concurrency 1 chrome tests/ -r html:./report/report.html,spec -e",
16-
"test:chrome:ci": "testcafe chromium:headless ${TEST_FILES:-tests/**/*.e2e.ts} -r spec,json:results/e2e.results.json,xunit:results/results.xml -e -q attemptLimit=3,successThreshold=1",
16+
"test:chrome:ci": "ts-node ./web.runner.ts",
1717
"test": "yarn test:chrome",
1818
"lint": "eslint . --ext .ts,.js,.tsx,.jsx",
1919
"test:desktop:ci": "ts-node ./desktop.runner.ts",

tests/e2e/web.runner.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import testcafe from 'testcafe';
2+
3+
(async(): Promise<void> => {
4+
await testcafe('localhost')
5+
.then(t => {
6+
return t
7+
.createRunner()
8+
.src((process.env.TEST_FILES || 'tests/**/*.e2e.ts').split('\n'))
9+
.browsers(['chromium:headless'])
10+
.filter((_testName, _fixtureName, _fixturePath, testMeta): boolean => {
11+
return testMeta.env !== 'desktop'
12+
})
13+
.reporter([
14+
'spec',
15+
{
16+
name: 'xunit',
17+
output: './results/results.xml'
18+
},
19+
{
20+
name: 'json',
21+
output: './results/e2e.results.json'
22+
}
23+
])
24+
.run({
25+
skipJsErrors: true,
26+
browserInitTimeout: 60000,
27+
speed: 1,
28+
quarantineMode: { successThreshold: '1', attemptLimit: '3' }
29+
});
30+
})
31+
.then(() => {
32+
process.exit(0);
33+
})
34+
.catch((e) => {
35+
console.error(e)
36+
process.exit(1);
37+
});
38+
})();

0 commit comments

Comments
 (0)