Skip to content

Commit af9586c

Browse files
committed
* #RIVS-258 - Change analytics page text for vscode
* #RIVS-245 - [Regression] Cli does not connect to the database when opened for the first time * #RIVS-247 - [Regression] Invalid database is displayed for some period of time after installing the extension
1 parent 33464fe commit af9586c

File tree

16 files changed

+68
-69
lines changed

16 files changed

+68
-69
lines changed

src/Webview.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -57,6 +59,14 @@ abstract class Webview {
5759
const styleUri = webview.asWebviewUri(this._opts.styleUri as vscode.Uri)
5860

5961
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+
})
6070

6171
const contentSecurity = [
6272
`img-src ${webview.cspSource} 'self' data:`,
@@ -89,7 +99,7 @@ abstract class Webview {
8999
<link href="${styleUri}" rel="stylesheet" />
90100
<script nonce="${this._opts.nonce}">
91101
window.acquireVsCodeApi = acquireVsCodeApi;
92-
window.ri=${JSON.stringify(uiStorage)};
102+
window.ri=${uiStorageStringify};
93103
</script>
94104
95105
<title>Redis for VS Code Webview</title>

src/webviews/src/actions/selectKeyAction.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VscodeMessageAction } from 'uiSrc/constants'
22
import { PostMessage } from 'uiSrc/interfaces'
3-
import { fetchKeyInfo, resetZustand, useDatabasesStore, useSelectedKeyStore } from 'uiSrc/store'
3+
import { fetchDatabaseOverview, fetchKeyInfo, useDatabasesStore, useSelectedKeyStore } from 'uiSrc/store'
44
import { TelemetryEvent, isEqualBuffers, sendEventTelemetry } from 'uiSrc/utils'
55

66
export const selectKeyAction = (message: PostMessage) => {
@@ -11,15 +11,18 @@ export const selectKeyAction = (message: PostMessage) => {
1111
const { keyInfo, database } = message?.data
1212
const { key } = keyInfo || {}
1313
const prevKey = useSelectedKeyStore.getState().data?.name
14+
const prevDatabaseId = useDatabasesStore.getState().connectedDatabase?.id
1415

15-
if (isEqualBuffers(key, prevKey)) {
16+
const isTheSameKey = prevDatabaseId === database?.id && isEqualBuffers(prevKey, key)
17+
18+
if (isTheSameKey || !prevKey) {
1619
return
1720
}
1821

1922
window.ri.database = database
20-
resetZustand()
2123

2224
fetchKeyInfo({ key }, true, ({ type: keyType, length }) => {
25+
fetchDatabaseOverview()
2326
useDatabasesStore.getState().setConnectedDatabase(database)
2427
sendEventTelemetry({
2528
event: TelemetryEvent.TREE_VIEW_KEY_VALUE_VIEWED,

src/webviews/src/modules/key-details/KeyDetails.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ const KeyDetails = () => {
6262
const onEditKey = (key: RedisString, newKey: RedisString) => {
6363
vscodeApi.postMessage({
6464
action: VscodeMessageAction.EditKeyName,
65-
data: { type: SelectedKeyActionType.Renamed, database: database!, keyInfo: { key, newKey } },
65+
data: {
66+
type: SelectedKeyActionType.Renamed,
67+
database: database!,
68+
keyInfo: { key, newKey },
69+
},
6670
})
6771
}
6872

src/webviews/src/modules/key-details/components/hash-details/hooks/useHashStore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand'
22
import { AxiosError } from 'axios'
3-
import { devtools, persist } from 'zustand/middleware'
3+
import { devtools } from 'zustand/middleware'
44
import * as l10n from '@vscode/l10n'
55
import { immer } from 'zustand/middleware/immer'
66
import { cloneDeep, findIndex, map, remove } from 'lodash'
@@ -36,7 +36,7 @@ export const initialState: HashState = {
3636
}
3737

3838
export const useHashStore = create<HashState & HashActions>()(
39-
immer(devtools(persist((set) => ({
39+
immer(devtools((set) => ({
4040
...initialState,
4141
// actions
4242
resetHashStore: () => set(initialState),
@@ -76,8 +76,7 @@ export const useHashStore = create<HashState & HashActions>()(
7676
state.updateValue = cloneDeep(initialState.updateValue)
7777
}),
7878

79-
}),
80-
{ name: 'keyHash' }))),
79+
}))),
8180
)
8281

8382
// async actions

src/webviews/src/modules/key-details/components/list-details/hooks/useListStore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand'
22
import { AxiosError } from 'axios'
3-
import { devtools, persist } from 'zustand/middleware'
3+
import { devtools } from 'zustand/middleware'
44
import { immer } from 'zustand/middleware/immer'
55

66
import { refreshKeyInfo, useSelectedKeyStore } from 'uiSrc/store'
@@ -40,7 +40,7 @@ export const initialState: ListState = {
4040
}
4141

4242
export const useListStore = create<ListState & ListActions>()(
43-
immer(devtools(persist((set) => ({
43+
immer(devtools((set) => ({
4444
...initialState,
4545
// actions
4646
resetListStore: () => set(initialState),
@@ -73,8 +73,7 @@ export const useListStore = create<ListState & ListActions>()(
7373
state.data.elements[state.data.elements.length === 1 ? 0 : element.index] = element
7474
}),
7575

76-
}),
77-
{ name: 'keyList' }))),
76+
}))),
7877
)
7978

8079
// async actions

src/webviews/src/modules/key-details/components/rejson-details/hooks/useRejsonStore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand'
22
import axios, { AxiosError, CancelTokenSource } from 'axios'
3-
import { devtools, persist } from 'zustand/middleware'
3+
import { devtools } from 'zustand/middleware'
44
import { immer } from 'zustand/middleware/immer'
55
import { isNumber } from 'lodash'
66

@@ -38,15 +38,14 @@ export const initialState: RejsonState = {
3838
}
3939

4040
export const useRejsonStore = create<RejsonState & RejsonActions>()(
41-
immer(devtools(persist((set) => ({
41+
immer(devtools((set) => ({
4242
...initialState,
4343
// actions
4444
resetRejsonStore: () => set(initialState),
4545
processRejson: () => set({ loading: true }),
4646
processRejsonFinal: () => set({ loading: false }),
4747
processRejsonSuccess: (data) => set({ data }),
48-
}),
49-
{ name: 'keyRejson' }))),
48+
}))),
5049
)
5150

5251
// async actions

src/webviews/src/modules/key-details/components/set-details/hooks/useSetStore.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { create } from 'zustand'
22
import { immer } from 'zustand/middleware/immer'
33
import { AxiosError } from 'axios'
4-
import { devtools, persist } from 'zustand/middleware'
4+
import { devtools } from 'zustand/middleware'
55
import { remove } from 'lodash'
66
import * as l10n from '@vscode/l10n'
77

@@ -39,7 +39,7 @@ export const initialState: SetState = {
3939
}
4040

4141
export const useSetStore = create<SetState & SetActions>()(
42-
immer(devtools(persist((set) => ({
42+
immer(devtools((set) => ({
4343
...initialState,
4444
// actions
4545
processSet: () => set(() => ({ loading: true })),
@@ -65,8 +65,7 @@ export const useSetStore = create<SetState & SetActions>()(
6565
remove(state.data.members, (member) =>
6666
members.findIndex((item) => isEqualBuffers(item, member)) > -1)
6767
}),
68-
}),
69-
{ name: 'keySet' }))),
68+
}))),
7069
)
7170

7271
// Async action

src/webviews/src/modules/key-details/components/string-details/hooks/useStringStore.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand'
22
import { AxiosError, AxiosResponseHeaders } from 'axios'
3-
import { devtools, persist } from 'zustand/middleware'
3+
import { devtools } from 'zustand/middleware'
44
import { immer } from 'zustand/middleware/immer'
55
import { IFetchKeyArgs, RedisString } from 'uiSrc/interfaces'
66
import { apiService } from 'uiSrc/services'
@@ -28,19 +28,16 @@ export const initialState: StringState = {
2828
export const useStringStore = create<StringState & StringActions>()(
2929
immer(
3030
devtools(
31-
persist(
32-
(set) => ({
33-
...initialState,
34-
// actions
35-
resetStringStore: () => set(initialState),
36-
processString: () => set({ loading: true }),
37-
processStringFinal: () => set({ loading: false }),
38-
processStringSuccess: ({ keyName, value }: any) =>
39-
set({ data: { key: keyName, value } }),
40-
setIsStringCompressed: (isCompressed) => set({ isCompressed }),
41-
}),
42-
{ name: 'keyString' },
43-
),
31+
(set) => ({
32+
...initialState,
33+
// actions
34+
resetStringStore: () => set(initialState),
35+
processString: () => set({ loading: true }),
36+
processStringFinal: () => set({ loading: false }),
37+
processStringSuccess: ({ keyName, value }: any) =>
38+
set({ data: { key: keyName, value } }),
39+
setIsStringCompressed: (isCompressed) => set({ isCompressed }),
40+
}),
4441
),
4542
),
4643
)
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import React from 'react'
22

3-
import * as useDatabases from 'uiSrc/store/hooks/use-databases-store/useDatabasesStore'
4-
import { render } from 'testSrc/helpers'
3+
import * as useSelectedKey from 'uiSrc/store/hooks/use-selected-key-store/useSelectedKeyStore'
4+
import { constants, render } from 'testSrc/helpers'
55
import { KeyDetailsPage } from './KeyDetailsPage'
66

7-
vi.spyOn(useDatabases, 'fetchDatabaseOverview')
7+
vi.spyOn(useSelectedKey, 'fetchKeyInfo')
8+
9+
beforeEach(() => {
10+
vi.stubGlobal('ri', { })
11+
})
812

913
describe('KeyDetailsPage', () => {
1014
it('should render', () => {
1115
expect(render(<KeyDetailsPage />)).toBeTruthy()
1216
})
13-
it('should call fetchDatabaseOverview', () => {
17+
it('should call fetchKeyInfo', () => {
18+
vi.stubGlobal('ri', { database: constants.DATABASE, keyInfo: { key: constants.KEY_NAME_1 } })
1419
expect(render(<KeyDetailsPage />)).toBeTruthy()
15-
expect(useDatabases.fetchDatabaseOverview).toBeCalled()
20+
expect(useSelectedKey.fetchKeyInfo).toBeCalled()
1621
})
1722
})

src/webviews/src/store/hooks/use-certificates-store/useCertificatesStore.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { create } from 'zustand'
22
import { AxiosError } from 'axios'
3-
import { devtools, persist } from 'zustand/middleware'
3+
import { devtools } from 'zustand/middleware'
44
import { immer } from 'zustand/middleware/immer'
55
import { apiService } from 'uiSrc/services'
66
import { ApiEndpoints } from 'uiSrc/constants'
@@ -14,16 +14,14 @@ export const initialCertsState: CertificatesStore = {
1414
}
1515

1616
export const useCertificatesStore = create<CertificatesStore & CertificatesActions>()(
17-
immer(devtools(persist((set) => ({
17+
immer(devtools((set) => ({
1818
...initialCertsState,
1919
// actions
2020
processCerts: () => set({ loading: true }),
2121
processCertsFinal: () => set({ loading: false }),
2222
processCertsSuccess: (caCerts: Certificate[], clientCerts: Certificate[]) =>
2323
set({ caCerts, clientCerts }),
24-
25-
}),
26-
{ name: 'certificates' }))),
24+
}))),
2725
)
2826

2927
// Asynchronous thunk action

0 commit comments

Comments
 (0)