Skip to content

Commit 6be8d16

Browse files
authored
Merge pull request #174 from RedisInsight/feature/bugfix
#RIVS-258, #RIVS-245, #RIVS-247
2 parents 6084642 + 6774306 commit 6be8d16

File tree

56 files changed

+413
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+413
-293
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ RI_STDOUT_LOGGER=false
1414
RI_AUTO_BOOTSTRAP=false
1515
RI_MIGRATE_OLD_FOLDERS=false
1616
RI_BUILD_TYPE='VS_CODE'
17+
RI_ENCRYPTION_KEYTAR=false
18+
RI_AGREEMENTS_PATH='../../webviews/resources/agreements-spec.json'
1719
# RI_SEGMENT_WRITE_KEY='SEGMENT_WRITE_KEY'

l10n/bundle.l10n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"To optimize your experience, Redis for VS Code uses third-party tools.\n All data collected is anonymized and will not be used for any purpose without your consent.": "To optimize your experience, Redis for VS Code uses third-party tools.\n All data collected is anonymized and will not be used for any purpose without your consent.",
9292
"To use Redis for VS Code, please accept the terms and conditions: ": "To use Redis for VS Code, please accept the terms and conditions: ",
9393
"Server Side Public License": "Server Side Public License",
94-
"Notice: To avoid automatic execution of malicious code, when adding new Workbench plugins, use files from trusted authors only.": "Notice: To avoid automatic execution of malicious code, when adding new Workbench plugins, use files from trusted authors only.",
9594
"Add Redis database": "Add Redis database",
9695
"Edit Redis database": "Edit Redis database",
9796
"Members": "Members",

package.json

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
11
{
22
"name": "redis-for-vscode",
3-
"productName": "Redis for VS Code",
43
"version": "0.0.3",
5-
"private": true,
6-
"description": "Redis for VS Code",
4+
"displayName": "Redis for VS Code",
5+
"description": "Visually interact with data and build queries in Redis",
6+
"license": "SEE LICENSE IN LICENSE",
77
"main": "dist/extension.js",
88
"l10n": "./l10n",
9-
"publisher": "redis",
9+
"publisher": "Redis",
10+
"pricing": "Free",
11+
"categories": ["Visualization", "Programming Languages"],
12+
"icon": "dist/webviews/resources/256x256.png",
13+
"author": {
14+
"name": "Redis Ltd.",
15+
"email": "support@redis.com",
16+
"url": "https://redis.com/redis-enterprise/redis-insight"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/RedisInsight/Redis-for-VS-Code.git"
21+
},
22+
"bugs": {
23+
"url": "https://github.com/RedisInsight/Redis-for-VS-Code/issues"
24+
},
25+
"qna": "https://github.com/RedisInsight/Redis-for-VS-Code/issues",
26+
"homepage": "https://github.com/RedisInsight/Redis-for-VS-Code#readme",
27+
"keywords": [
28+
"Redis for VS Code",
29+
"redis",
30+
"redis insight",
31+
"vsc",
32+
"visual studio code",
33+
"plugin",
34+
"react",
35+
"node",
36+
"nest",
37+
"typescript",
38+
"vite"
39+
],
1040
"engines": {
1141
"vscode": "^1.87.0"
1242
},
@@ -19,14 +49,14 @@
1949
{
2050
"id": "ri-sidebar-view",
2151
"title": "Redis for VS Code",
22-
"icon": "dist/webviews/resources/redisinsight.svg"
52+
"icon": "dist/webviews/resources/redis_for_vscode.svg"
2353
}
2454
],
2555
"panel": [
2656
{
2757
"id": "ri-panel-view",
2858
"title": "Redis CLI",
29-
"icon": "dist/webviews/resources/redisinsight.svg"
59+
"icon": "dist/webviews/resources/redis_for_vscode.svg"
3060
}
3161
]
3262
},
@@ -36,7 +66,7 @@
3666
"type": "webview",
3767
"id": "ri-sidebar",
3868
"name": "Redis for VS Code",
39-
"icon": "dist/webviews/resources/redisinsight.svg",
69+
"icon": "dist/webviews/resources/redis_for_vscode.svg",
4070
"contextualTitle": "Redis for VS Code"
4171
}
4272
],
@@ -134,31 +164,6 @@
134164
"lint-staged": {
135165
"*.{js,jsx,ts,tsx}": "eslint --fix"
136166
},
137-
"author": {
138-
"name": "Redis Ltd.",
139-
"email": "support@redis.com",
140-
"url": "https://redis.com/redis-enterprise/redis-insight"
141-
},
142-
"repository": {
143-
"type": "git",
144-
"url": "git+https://github.com/RedisInsight/Redis-for-VS-Code.git"
145-
},
146-
"bugs": {
147-
"url": "https://github.com/RedisInsight/Redis-for-VS-Code/issues"
148-
},
149-
"keywords": [
150-
"Redis for VS Code",
151-
"redis",
152-
"redis insight",
153-
"vsc",
154-
"visual studio code",
155-
"plugin",
156-
"react",
157-
"nest",
158-
"typescript",
159-
"vite"
160-
],
161-
"homepage": "https://github.com/RedisInsight/Redis-for-VS-Code#readme",
162167
"devDependencies": {
163168
"@bithero/monaco-editor-vite-plugin": "^1.0.2",
164169
"@githubocto/tailwind-vscode": "^1.0.5",
@@ -201,7 +206,7 @@
201206
"@vitest/coverage-v8": "^1.3.1",
202207
"@vitest/ui": "^1.3.1",
203208
"@vscode/l10n-dev": "^0.0.35",
204-
"@vscode/vsce": "^2.31.1",
209+
"@vscode/vsce": "^3.0.0",
205210
"autoprefixer": "^10.4.16",
206211
"cross-env": "^7.0.3",
207212
"esbuild": "^0.19.5",
@@ -257,8 +262,6 @@
257262
"whatwg-fetch": "^3.6.19"
258263
},
259264
"dependencies": {
260-
"@hediet/node-reload": "^0.8.0",
261-
"@vscode/codicons": "^0.0.36",
262265
"@vscode/l10n": "^0.0.18",
263266
"@vscode/webview-ui-toolkit": "^1.4.0",
264267
"axios": "^1.5.1",
@@ -271,7 +274,6 @@
271274
"dotenv": "^16.4.5",
272275
"file-saver": "^2.0.5",
273276
"formik": "^2.4.5",
274-
"helmet": "^7.0.0",
275277
"history": "^5.3.0",
276278
"html-react-parser": "^5.0.6",
277279
"immer": "^9.0.21",
@@ -303,8 +305,6 @@
303305
"react-vtree": "^3.0.0-beta.3",
304306
"react-window": "^1.8.6",
305307
"reactjs-popup": "^2.0.6",
306-
"reflect-metadata": "^0.1.13",
307-
"rxjs": "^7.8.1",
308308
"ws": "^8.17.1",
309309
"zustand": "^4.5.4"
310310
}

src/WebViewProvider.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { getNonce, handleMessage } from './utils'
3-
import { workspaceStateService } from './lib'
3+
import { getUIStorage } from './lib'
44

55
export class WebViewProvider implements vscode.WebviewViewProvider {
66
_doc?: vscode.TextDocument
@@ -52,8 +52,7 @@ export class WebViewProvider implements vscode.WebviewViewProvider {
5252
)
5353
const viewRoute = this._route
5454

55-
const appPort = workspaceStateService.get('appPort')
56-
const appInfo = workspaceStateService.get('appInfo')
55+
const uiStorage = getUIStorage()
5756

5857
// Use a nonce to only allow a specific script to be run.
5958
const nonce = getNonce()
@@ -79,8 +78,7 @@ export class WebViewProvider implements vscode.WebviewViewProvider {
7978
<meta http-equiv="Content-Security-Policy" content="${contentSecurity.join(';')}">
8079
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8180
<script nonce="${nonce}">
82-
window.appPort=${appPort};
83-
window.appInfo=${JSON.stringify(appInfo)};
81+
window.ri=${JSON.stringify(uiStorage)};
8482
</script>
8583
</head>
8684
<body>

src/Webview.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { getNonce, handleMessage } from './utils'
3-
import { workspaceStateService } from './lib'
3+
import { getUIStorage } from './lib'
44

55
type WebviewOptions = {
66
context?: vscode.ExtensionContext
@@ -10,7 +10,9 @@ type WebviewOptions = {
1010
scriptUri?: vscode.Uri
1111
styleUri?: vscode.Uri
1212
nonce?: string
13-
message?: object
13+
message?: {
14+
data: object
15+
}
1416
column?: vscode.ViewColumn
1517
handleMessage?: (message: any) => any
1618
}
@@ -35,11 +37,13 @@ abstract class Webview {
3537
}
3638
}
3739

38-
protected getWebviewOptions(): vscode.WebviewOptions {
40+
protected getWebviewOptions(): vscode.WebviewPanelOptions & vscode.WebviewOptions {
3941
return {
4042
// Enable javascript in the webview
4143
enableScripts: true,
4244

45+
retainContextWhenHidden: true,
46+
4347
// And restrict the webview to only loading content from our extension's `dist` directory.
4448
localResourceRoots: [vscode.Uri.joinPath(this._opts.context?.extensionUri as vscode.Uri, 'dist')],
4549
}
@@ -54,8 +58,15 @@ abstract class Webview {
5458
const scriptUri = webview.asWebviewUri(this._opts.scriptUri as vscode.Uri)
5559
const styleUri = webview.asWebviewUri(this._opts.styleUri as vscode.Uri)
5660

57-
const appInfo = workspaceStateService.get('appInfo')
58-
const appPort = workspaceStateService.get('appPort')
61+
const uiStorage = getUIStorage()
62+
const database = (this._opts?.message?.data as any)?.database || (uiStorage as any)?.database
63+
const keyInfo = (this._opts?.message?.data as any)?.keyInfo || (uiStorage as any)?.keyInfo
64+
65+
const uiStorageStringify = JSON.stringify({
66+
...uiStorage,
67+
database,
68+
keyInfo,
69+
})
5970

6071
const contentSecurity = [
6172
`img-src ${webview.cspSource} 'self' data:`,
@@ -88,8 +99,7 @@ abstract class Webview {
8899
<link href="${styleUri}" rel="stylesheet" />
89100
<script nonce="${this._opts.nonce}">
90101
window.acquireVsCodeApi = acquireVsCodeApi;
91-
window.appPort=${appPort};
92-
window.appInfo=${JSON.stringify(appInfo)};
102+
window.ri=${uiStorageStringify};
93103
</script>
94104
95105
<title>Redis for VS Code Webview</title>
@@ -102,6 +112,7 @@ abstract class Webview {
102112
}
103113

104114
public abstract update(opts?: WebviewOptions): void
115+
public abstract setTitle(title: string): void
105116
}
106117

107118
export class WebviewPanel extends Webview implements vscode.Disposable {
@@ -129,6 +140,9 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
129140
if (opts.message) {
130141
instance.panel.webview.postMessage(opts.message)
131142
}
143+
if (opts.title) {
144+
instance.panel.title = opts.title
145+
}
132146
} else {
133147
// Otherwise, create an instance
134148
instance = new WebviewPanel(options)
@@ -147,8 +161,9 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
147161
opts.column || vscode.ViewColumn.One,
148162
this.getWebviewOptions(),
149163
)
164+
150165
// Update the content
151-
this.update()
166+
this.update(opts)
152167

153168
// Listen for when the panel is disposed
154169
// This happens when the user closes the panel or when the panel is closed programmatically
@@ -157,11 +172,6 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
157172
this.dispose()
158173
}, null, this._disposables)
159174

160-
// todo: connection between webviews
161-
if (opts.message) {
162-
this.panel.webview.postMessage(opts.message)
163-
}
164-
165175
// Update the content based on view changes
166176
// this.panel.onDidChangeViewState(
167177
// e => {
@@ -188,7 +198,7 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
188198
this.panel.title = title || this._opts.title || ''
189199
this.panel.iconPath = vscode.Uri.joinPath(
190200
this._opts.context?.extensionUri as vscode.Uri,
191-
'dist/webviews/resources/redisinsight.svg',
201+
'dist/webviews/resources/redis_for_vscode.svg',
192202
)
193203
this.panel.webview.html = this._getContent(this.panel.webview)
194204

@@ -197,6 +207,10 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
197207
}
198208
}
199209

210+
public setTitle(title: string) {
211+
this.panel.title = title
212+
}
213+
200214
public dispose() {
201215
// Disposes of this instance
202216
// Next time getInstance() is called, it will construct a new instance

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export enum ViewId {
99
}
1010

1111
export const MAX_TITLE_KEY_LENGTH = 30
12-
export const EXTENSION_ID = 'redis.redis-for-vscode'
12+
export const EXTENSION_ID = 'Redis.redis-for-vscode'
1313

1414
export const EXTERNAL_LINKS = {
1515
releaseNotes: 'https://github.com/RedisInsight/RedisInsight/releases',

src/extension.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import * as path from 'path'
44
import { WebviewPanel } from './Webview'
55
import { startBackend, getBackendGracefulShutdown } from './server/bootstrapBackend'
66
import { startBackendE2E } from './server/bootstrapBackendE2E'
7-
import { checkVersionUpdate, initWorkspaceState } from './lib'
7+
import { checkVersionUpdate, initWorkspaceState, setUIStorageField } from './lib'
88
import { WebViewProvider } from './WebViewProvider'
9-
import { handleMessage, truncateText } from './utils'
10-
import { MAX_TITLE_KEY_LENGTH, ViewId } from './constants'
9+
import { getTitleForKey, handleMessage } from './utils'
10+
import { ViewId } from './constants'
1111
import { logger } from './logger'
1212

1313
dotenv.config({ path: path.join(__dirname, '..', '.env') })
@@ -48,16 +48,21 @@ export async function activate(context: vscode.ExtensionContext) {
4848
vscode.window.registerWebviewViewProvider('ri-sidebar', sidebarProvider),
4949
vscode.window.registerWebviewViewProvider('ri-panel', panelProvider, { webviewOptions: { retainContextWhenHidden: true } }),
5050

51-
vscode.commands.registerCommand('RedisForVSCode.addCli', (args) => {
51+
vscode.commands.registerCommand('RedisForVSCode.addCli', async (args) => {
52+
await setUIStorageField('database', args.data?.database)
53+
5254
vscode.commands.executeCommand('setContext', 'RedisForVSCode.showCliPanel', true)
5355
vscode.commands.executeCommand('ri-panel.focus')
54-
setTimeout(() => {
55-
panelProvider.view?.webview.postMessage({ action: 'AddCli', data: args.data })
56-
}, 100)
56+
57+
panelProvider.view?.webview.postMessage({ action: 'AddCli', data: args.data })
5758
}),
5859

59-
vscode.commands.registerCommand('RedisForVSCode.openKey', (args) => {
60-
const title = `${args?.data?.displayedKeyType?.toLowerCase()}:${truncateText(args?.data?.keyString, MAX_TITLE_KEY_LENGTH)}`
60+
vscode.commands.registerCommand('RedisForVSCode.openKey', async (args) => {
61+
const keyInfo = args.data?.keyInfo
62+
const title = getTitleForKey(keyInfo?.displayedKeyType, keyInfo?.keyString)
63+
64+
await setUIStorageField('keyInfo', keyInfo)
65+
await setUIStorageField('database', args.data?.database)
6166

6267
WebviewPanel.getInstance({
6368
context,
@@ -66,10 +71,12 @@ export async function activate(context: vscode.ExtensionContext) {
6671
viewId: ViewId.Key,
6772
// todo: connection between webviews
6873
message: args,
69-
})?.update({ title })
74+
})
7075
}),
7176

72-
vscode.commands.registerCommand('RedisForVSCode.addKeyOpen', (args) => {
77+
vscode.commands.registerCommand('RedisForVSCode.addKeyOpen', async (args) => {
78+
await setUIStorageField('database', args.data?.database)
79+
7380
WebviewPanel.getInstance({
7481
context,
7582
route: 'main/add_key',
@@ -177,6 +184,8 @@ export async function activate(context: vscode.ExtensionContext) {
177184

178185
vscode.commands.registerCommand('RedisForVSCode.editKeyName', (args) => {
179186
sidebarProvider.view?.webview.postMessage({ action: 'RefreshTree', data: args })
187+
const title = getTitleForKey(args.keyInfo?.displayedKeyType, args.keyInfo?.newKeyString)
188+
WebviewPanel.getInstance({ viewId: ViewId.Key }).setTitle(title)
180189
}),
181190

182191
vscode.commands.registerCommand('RedisForVSCode.resetSelectedKey', () => {

0 commit comments

Comments
 (0)