Skip to content

Commit 2da5cdc

Browse files
committed
#RI-31 - fix pr comments
1 parent cc61be2 commit 2da5cdc

File tree

12 files changed

+104
-51
lines changed

12 files changed

+104
-51
lines changed

src/webviews/src/modules/keys-tree/KeysTree.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ export const KeysTree = ({ database }: Props) => {
111111
if (isUndefined(type)) {
112112
return
113113
}
114-
fetchKeyInfo({ key: name, databaseId: database.id, dbIndex: dbIndex! }, false, () => {
114+
fetchKeyInfo({ key: name, databaseId: database.id, dbIndex }, false, () => {
115115
vscodeApi.postMessage({
116116
action: VscodeMessageAction.SelectKey,
117117
data: {
118-
database: { ...database, db: dbIndex! },
118+
database: { ...database, db: dbIndex },
119119
keyInfo: { key: name, keyString, keyType: type, displayedKeyType: getGroupTypeDisplay(type) },
120120
},
121121
})
@@ -152,7 +152,7 @@ export const KeysTree = ({ database }: Props) => {
152152

153153
return (
154154
<div className="pl-8">
155-
<NoKeysMessage total={keysState.total} database={database} />
155+
<NoKeysMessage total={keysState.total} database={database} dbIndex={dbIndex} />
156156
</div>
157157
)
158158
}

src/webviews/src/modules/keys-tree/components/database-wrapper/DatabaseWrapper.tsx

+6-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react'
22
import cx from 'classnames'
3-
import { VscChevronRight, VscChevronDown, VscEdit } from 'react-icons/vsc'
3+
import { VscEdit } from 'react-icons/vsc'
44
import { isUndefined, toNumber } from 'lodash'
55
import * as l10n from '@vscode/l10n'
66
import { VSCodeButton } from '@vscode/webview-ui-toolkit/react'
@@ -12,9 +12,7 @@ import {
1212
sendEventTelemetry,
1313
} from 'uiSrc/utils'
1414
import { ContextStoreProvider, Database, DatabaseOverview, checkConnectToDatabase, deleteDatabases } from 'uiSrc/store'
15-
import DatabaseOfflineIconSvg from 'uiSrc/assets/database/database_icon_offline.svg?react'
16-
import DatabaseActiveIconSvg from 'uiSrc/assets/database/database_icon_active.svg?react'
17-
import { Tooltip } from 'uiSrc/ui'
15+
import { Chevron, DatabaseIcon, Tooltip } from 'uiSrc/ui'
1816
import { PopoverDelete } from 'uiSrc/components'
1917
import { POPOVER_WINDOW_BORDER_WIDTH, VscodeMessageAction } from 'uiSrc/constants'
2018
import { vscodeApi } from 'uiSrc/services'
@@ -86,18 +84,6 @@ export const DatabaseWrapper = React.memo(({ database }: Props) => {
8684
})
8785
}
8886

89-
const Chevron = () => (showTree ? (
90-
<VscChevronDown className={cx(styles.icon, styles.iconNested)} />
91-
) : (
92-
<VscChevronRight className={cx(styles.icon, styles.iconNested)} />
93-
))
94-
95-
const DatabaseIcon = () => (showTree ? (
96-
<DatabaseActiveIconSvg className={styles.icon} />
97-
) : (
98-
<DatabaseOfflineIconSvg className={styles.icon} />
99-
))
100-
10187
const LogicalDatabase = (
10288
{ database, open, dbTotal }:
10389
{ database: Database, open?: boolean, dbTotal?: number },
@@ -127,8 +113,8 @@ export const DatabaseWrapper = React.memo(({ database }: Props) => {
127113
className={styles.databaseNameWrapper}
128114
data-testid={`database-${id}`}
129115
>
130-
{<Chevron/>}
131-
{<DatabaseIcon/>}
116+
{<Chevron open={showTree} />}
117+
{<DatabaseIcon open={showTree} />}
132118
<Tooltip
133119
content={formatLongName(name, 100, 20)}
134120
position="bottom center"
@@ -164,23 +150,20 @@ export const DatabaseWrapper = React.memo(({ database }: Props) => {
164150
</div>
165151
</div>
166152
{showTree && (<>
167-
{!isUndefined(totalKeysPerDb) && Object.keys(totalKeysPerDb!).map((databaseIndex) => (
153+
{!isUndefined(totalKeysPerDb) && Object.keys(totalKeysPerDb).map((databaseIndex) => (
168154
<LogicalDatabase
169155
key={id + databaseIndex}
170-
open={Object.keys(totalKeysPerDb!)?.length === 1}
156+
open={Object.keys(totalKeysPerDb)?.length === 1}
171157
dbTotal={totalKeysPerDb?.[databaseIndex]}
172-
// database={database}
173158
database={{
174159
...database,
175160
db: toNumber(databaseIndex.replace('db', '')),
176161
}}
177-
// dbIndex={toNumber(databaseIndex.replace('db', ''))}
178162
/>
179163
))}
180164
{isUndefined(totalKeysPerDb) && (
181165
<LogicalDatabase
182166
key={id}
183-
// database={database}
184167
database={{ ...database, db: 0 }}
185168
open={true}
186169
/>

src/webviews/src/modules/keys-tree/components/keys-summary/KeysSummary.tsx

+8-17
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import * as l10n from '@vscode/l10n'
33
import cx from 'classnames'
44
import { VSCodeButton } from '@vscode/webview-ui-toolkit/react'
55
import { BiSortDown, BiSortUp } from 'react-icons/bi'
6-
import { VscAdd, VscChevronDown, VscChevronRight, VscDatabase, VscTerminal } from 'react-icons/vsc'
6+
import { VscAdd, VscDatabase, VscTerminal } from 'react-icons/vsc'
77
import { isUndefined } from 'lodash'
88

99
import { TelemetryEvent, nullableNumberWithSpaces, numberWithSpaces, sendEventTelemetry } from 'uiSrc/utils'
1010
import { vscodeApi } from 'uiSrc/services'
1111
import { SortOrder, VscodeMessageAction } from 'uiSrc/constants'
1212
import { checkDatabaseIndexAction, Database, useContextApi, useContextInContext } from 'uiSrc/store'
13-
import { Nullable } from 'uiSrc/interfaces'
14-
import { RefreshBtn, Tooltip } from 'uiSrc/ui'
13+
import { Maybe, Nullable } from 'uiSrc/interfaces'
14+
import { Chevron, RefreshBtn, Tooltip } from 'uiSrc/ui'
1515

1616
import { KeyTreeFilter } from '../keys-tree-filter'
1717
import { useKeysApi, useKeysInContext } from '../../hooks/useKeys'
@@ -24,7 +24,7 @@ export interface Props {
2424
loading: boolean
2525
total: Nullable<number>
2626
showTree: boolean
27-
dbIndex: number
27+
dbIndex: Maybe<number>
2828
toggleShowTree: (value?: boolean) => void
2929
}
3030

@@ -46,7 +46,7 @@ export const KeysSummary = (props: Props) => {
4646
})
4747
vscodeApi.postMessage({
4848
action: VscodeMessageAction.AddKey,
49-
data: { database: { ...database, db: dbIndex! } },
49+
data: { database: { ...database, db: dbIndex } },
5050
})
5151
}
5252

@@ -69,7 +69,7 @@ export const KeysSummary = (props: Props) => {
6969
return
7070
}
7171
if (!showTree) {
72-
checkDatabaseIndexAction(database.id, dbIndex!, () => toggleShowTree())
72+
checkDatabaseIndexAction(database.id, dbIndex, () => toggleShowTree())
7373
return
7474
}
7575
toggleShowTree()
@@ -78,23 +78,14 @@ export const KeysSummary = (props: Props) => {
7878
const openCliClickHandle = () => {
7979
vscodeApi.postMessage({
8080
action: VscodeMessageAction.AddCli,
81-
data: { database: { ...database, db: dbIndex! } },
81+
data: { database: { ...database, db: dbIndex } },
8282
})
8383
}
8484

8585
const refreshHandle = () => {
8686
keysApi.fetchPatternKeysAction()
8787
}
8888

89-
const Chevron = () => {
90-
if (!isMultiDbIndex) return null
91-
return showTree ? (
92-
<VscChevronDown className={cx(styles.icon, styles.iconNested)} />
93-
) : (
94-
<VscChevronRight className={cx(styles.icon, styles.iconNested)} />
95-
)
96-
}
97-
9889
const DbIndex = () => {
9990
if (!isMultiDbIndex) return null
10091
return (
@@ -137,7 +128,7 @@ export const KeysSummary = (props: Props) => {
137128
onClick={handleToggleShowTree}
138129
data-testid="keys-summary"
139130
>
140-
{<Chevron />}
131+
{<Chevron open={showTree} display={isMultiDbIndex} />}
141132
{<DbIndex />}
142133
{<Summary />}
143134
</div>

src/webviews/src/modules/keys-tree/components/keys-tree-header/KeysTreeHeader.spec.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import React from 'react'
22

33
import { render, constants } from 'testSrc/helpers'
4-
import { KeysTreeHeader } from './KeysTreeHeader'
4+
import { KeysTreeHeader, Props } from './KeysTreeHeader'
55
import * as useKeys from '../../hooks/useKeys'
66

77
const useKeysInContextMock = vi.spyOn(useKeys, 'useKeysInContext')
88

99
const mockDatabase = constants.DATABASE
1010
const mockedProps: Props = {
1111
database: mockDatabase,
12-
total: 1,
13-
scanned: 1,
14-
showTree: true,
15-
resultsLength: 1,
16-
loading: false,
17-
toggleShowTree: () => {},
12+
dbTotal: 1,
13+
open: true,
14+
children: <div/>,
1815
}
1916

2017
describe('KeysTreeHeaders', () => {

src/webviews/src/modules/keys-tree/components/keys-tree-header/KeysTreeHeader.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const KeysTreeHeader = ({ database, open, dbTotal, children }: Props) =>
6767
loading={loading}
6868
scanned={scanned}
6969
total={dbTotal ?? total}
70-
dbIndex={dbIndex!}
70+
dbIndex={dbIndex}
7171
resultsLength={resultsLength}
7272
showTree={showTree}
7373
toggleShowTree={handleToggleShowTree}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { instance, mock } from 'ts-mockito'
3+
4+
import { render } from 'testSrc/helpers'
5+
import { Chevron, Props } from './Chevron'
6+
7+
const mockedProps = mock<Props>()
8+
9+
describe('Chevron', () => {
10+
it('should render', async () => {
11+
expect(render(<Chevron {...instance(mockedProps)} />)).toBeTruthy()
12+
})
13+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import cx from 'classnames'
3+
4+
import { VscChevronDown, VscChevronRight } from 'react-icons/vsc'
5+
import styles from './styles.module.scss'
6+
7+
export interface Props {
8+
open?: boolean
9+
display?: boolean
10+
}
11+
12+
export const Chevron = ({ open = false, display = true }: Props) => {
13+
if (!display) return null
14+
15+
return open ? (
16+
<VscChevronDown className={cx(styles.icon, styles.iconNested)} />
17+
) : (
18+
<VscChevronRight className={cx(styles.icon, styles.iconNested)} />
19+
)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.icon {
2+
@apply mr-2 w-[14px] h-[14px] min-w-[14px] ml-[3px];
3+
4+
&Nested {
5+
@apply m-0;
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { instance, mock } from 'ts-mockito'
3+
4+
import { render } from 'testSrc/helpers'
5+
import { DatabaseIcon, Props } from './DatabaseIcon'
6+
7+
const mockedProps = mock<Props>()
8+
9+
describe('DatabaseIcon', () => {
10+
it('should render', async () => {
11+
expect(render(<DatabaseIcon {...instance(mockedProps)} />)).toBeTruthy()
12+
})
13+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
3+
import DatabaseOfflineIconSvg from 'uiSrc/assets/database/database_icon_offline.svg?react'
4+
import DatabaseActiveIconSvg from 'uiSrc/assets/database/database_icon_active.svg?react'
5+
import styles from './styles.module.scss'
6+
7+
export interface Props {
8+
open?: boolean
9+
display?: boolean
10+
}
11+
12+
export const DatabaseIcon = ({ open = false, display = true }: Props) => {
13+
if (!display) return null
14+
15+
return open ? (
16+
<DatabaseActiveIconSvg className={styles.icon} />
17+
) : (
18+
<DatabaseOfflineIconSvg className={styles.icon} />
19+
)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.icon {
2+
@apply mr-2 w-[14px] h-[14px] min-w-[14px] ml-[3px];
3+
4+
&Nested {
5+
@apply m-0;
6+
}
7+
}

src/webviews/src/ui/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export { Spacer } from './spacer/Spacer'
1212
export { PromoLink } from './promo-link/PromoLink'
1313
export { Tooltip } from './tooltip/Tooltip'
1414
export { RiButton } from './button/RiButton'
15+
export { Chevron } from './icons/chevron/Chevron'
16+
export { DatabaseIcon } from './icons/database/DatabaseIcon'
1517

1618
export type { RadioGroupOption } from './radio-group/RadioGroup'
1719
export type { SelectOption } from './select/Select'

0 commit comments

Comments
 (0)