Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const MultiSearch = (props: Props) => {
color="primary"
aria-label="Search"
className={styles.searchButton}
onClick={onSubmit}
onClick={() => onSubmit()}
data-testid="search-btn"
/>
</div>
Expand Down
48 changes: 30 additions & 18 deletions redisinsight/ui/src/components/virtual-grid/VirtualGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Maybe, Nullable } from 'uiSrc/utils'
import { SortOrder } from 'uiSrc/constants'
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
import { IProps } from './interfaces'
import { columnWidth, useInnerElementType } from './utils'
import { getColumnWidth, useInnerElementType } from './utils'

import styles from './styles.module.scss'

Expand Down Expand Up @@ -46,14 +46,23 @@ const VirtualGrid = (props: IProps) => {
const [expandedRows, setExpandedRows] = useState<number[]>([])

const gridRef = useRef<Nullable<Grid>>()
const sizeMap = useRef<{ [key: number]: number }>({})
const setSize = useCallback((index, size) => {
sizeMap.current = { ...sizeMap.current, [index]: size }
const rowHeightsMap = useRef<{ [key: number]: { [key: number]: number } }>({})
const setRowHeight = useCallback((rowIndex: number, columnIndex:number, size:number) => {
rowHeightsMap.current = {
...rowHeightsMap.current,
[rowIndex]: {
...(rowHeightsMap.current[rowIndex] || {}),
[columnIndex]: size
}
}

gridRef.current?.resetAfterRowIndex?.(index)
gridRef.current?.resetAfterRowIndex?.(rowIndex)
}, [])
const getSize = (index: number) =>
(expandedRows.indexOf(index) !== -1 ? sizeMap.current[index] : rowHeight)

const getRowHeight = (index: number) =>
(expandedRows.indexOf(index) !== -1
? Math.max(...Object.values(rowHeightsMap.current[index]))
: rowHeight)

useEffect(() =>
() => {
Expand All @@ -63,7 +72,7 @@ const VirtualGrid = (props: IProps) => {

useEffect(() => {
setExpandedRows([])
sizeMap.current = {}
rowHeightsMap.current = {}
gridRef.current?.resetAfterRowIndex?.(0)
}, [totalItemsCount])

Expand Down Expand Up @@ -137,11 +146,11 @@ const VirtualGrid = (props: IProps) => {
const paddingSize = 24
const cellHeight = cellRef.current?.children?.[0]?.getBoundingClientRect?.().height + paddingSize

if (cellHeight > getSize(rowIndex) && rowIndex !== 0) {
setSize(rowIndex, cellHeight)
if (rowIndex !== 0) {
setRowHeight(rowIndex, columnIndex, cellHeight)
}
}
}, [setSize, rowIndex, expanded, width])
}, [setRowHeight, rowIndex, expanded])

if (rowIndex === 0) {
return (
Expand Down Expand Up @@ -176,7 +185,9 @@ const VirtualGrid = (props: IProps) => {
}
if (columnIndex === 0) {
const lastColumn = columns[columns.length - 1]
const allDynamicRowsHeight: number[] = Object.values(sizeMap.current)
const allDynamicRowsHeight: number[] = Object.values(rowHeightsMap.current)
.map((row) => Math.max(...Object.values(row)))

const allRowsHeight = allDynamicRowsHeight.reduce((a, b) => a + b, 0)
+ (items.length - allDynamicRowsHeight.length) * rowHeight

Expand All @@ -201,7 +212,7 @@ const VirtualGrid = (props: IProps) => {
: styles.gridItemEven)}
style={{
width: lastColumn?.minWidth,
height: getSize(rowIndex),
height: getRowHeight(rowIndex),
marginLeft: width - lastColumn?.minWidth - (hasHorizontalScrollOffset ? 29 : 13)
}}
>
Expand All @@ -228,10 +239,11 @@ const VirtualGrid = (props: IProps) => {

const innerElementType = useInnerElementType(
Cell,
(i) => columnWidth(i, width, columns),
getSize,
getColumnWidth,
getRowHeight,
columns.length - 1,
width,
Math.max(maxTableWidth, width),
columns,
)

return (
Expand Down Expand Up @@ -274,10 +286,10 @@ const VirtualGrid = (props: IProps) => {
})}
className={styles.grid}
columnCount={columns.length}
columnWidth={(i) => columnWidth(i, width, columns)}
columnWidth={(i) => getColumnWidth(i, width, columns)}
height={height}
rowCount={items.length}
rowHeight={getSize}
rowHeight={getRowHeight}
width={width}
innerElementType={innerElementType}
onScroll={onScroll}
Expand Down
57 changes: 45 additions & 12 deletions redisinsight/ui/src/components/virtual-grid/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export const getShownIndicies = (children: typeof React.Children) => {

export const useInnerElementType = (
Cell: GridChildComponentProps<null>,
columnWidth:(index: number) => number,
columnWidth:(index: number, width: number, columns: ITableColumn[]) => number,
rowHeight:(index: number) => number,
columnCount: number,
width: number,
tableWidth: number,
columns: ITableColumn[],
) => React.useMemo(
() =>
React.forwardRef((props:ReactNode, ref) => {
Expand All @@ -55,7 +56,7 @@ export const useInnerElementType = (
let sum = 0

while (index > 1) {
sum += columnWidth(index - 1)
sum += columnWidth(index - 1, tableWidth, columns)
index -= 1
}

Expand All @@ -64,25 +65,58 @@ export const useInnerElementType = (

const shownIndecies = getShownIndicies(props.children)

const children = React.Children.map(props.children, (child) => {
let children = React.Children.map(props.children, (child, index) => {
const { column, row } = getCellIndicies(child)

// do not show non-sticky cell
if (column === 0 || row === 0 || column === columnCount) {
return null
}

return child
return {
...child,
props: {
...child.props,
style: {
...child.props.style,
width: columnWidth(column, tableWidth, columns),
}
}
}
})

children = React.Children.toArray(children)

for (let i = 1; i < children.length; i++) {
const child = children[i]
const prevChild = children[i - 1]
const { row } = getCellIndicies(child)
const { row: prevRow } = getCellIndicies(prevChild)

if (prevRow !== row) {
children[i] = child
} else {
children[i] = {
...child,
props: {
...child.props,
style: {
...child.props.style,
left: prevChild.props.style.left + prevChild.props.style.width,
}
}
}
}
}

children.push(
React.createElement(Cell, {
key: '0:0',
rowIndex: 0,
columnIndex: 0,
style: {
display: 'inline-flex',
width: columnWidth(0),
width: columnWidth(0, tableWidth, columns),
height: rowHeight(0),
position: 'sticky',
top: 0,
Expand All @@ -98,7 +132,7 @@ export const useInnerElementType = (
for (let i = 1; i <= shownColumnsCount; i += 1) {
const columnIndex = i + shownIndecies.from.column
const rowIndex = 0
const width = columnWidth(columnIndex)
const width = columnWidth(columnIndex, tableWidth, columns)
const height = rowHeight(rowIndex)

const marginLeft = i === 1 ? sumColumnWidths(columnIndex) : undefined
Expand Down Expand Up @@ -126,7 +160,7 @@ export const useInnerElementType = (
for (let i = 1; i <= shownRowsCount; i += 1) {
const columnIndex = 0
const rowIndex = i + shownIndecies.from.row
const width = columnWidth(columnIndex)
const width = columnWidth(columnIndex, tableWidth, columns)
const height = rowHeight(rowIndex)

const marginTop = i === 1 ? sumRowsHeights(rowIndex) : undefined
Expand All @@ -150,16 +184,15 @@ export const useInnerElementType = (
}

return (
<div ref={ref} {...props}>
<div ref={ref} {...props} style={{ ...props?.style, width: tableWidth }}>
{children}
</div>
)
}),
[Cell, columnWidth, rowHeight, columnCount, width]
[Cell, columnWidth, rowHeight, columnCount, tableWidth]
)

export const columnWidth = (i: number, width: number, columns: ITableColumn[], minColumnWidth: number = 190) => {
const scrollWidth = 16
export const getColumnWidth = (i: number, width: number, columns: ITableColumn[], minColumnWidth: number = 190) => {
const maxTableWidth = columns.reduce((a, { maxWidth = minColumnWidth }) => a + maxWidth, 0)

if (maxTableWidth < width) {
Expand Down
36 changes: 23 additions & 13 deletions redisinsight/ui/src/constants/cliOutput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,29 @@ export enum CliOutputFormatterType {
Raw = 'RAW',
}

export const InitOutputText = (host: string = '', port: number = 0, dbIndex: number = 0, onClick: () => void) => [
<span className="color-green" key={Math.random()}>
{'Try '}
<EuiLink
onClick={onClick}
className="color-green"
style={{ fontSize: 'inherit', fontFamily: 'inherit' }}
data-test-subj="cli-workbench-page-btn"
>
Workbench
</EuiLink>
, our advanced CLI. Check out our Quick Guides to learn more about Redis capabilities.
</span>,
export const InitOutputText = (
host: string = '',
port: number = 0,
dbIndex: number = 0,
emptyOutput: boolean,
onClick: () => void,
) => [
<>
{ emptyOutput && (
<span className="color-green" key={Math.random()}>
{'Try '}
<EuiLink
onClick={onClick}
className="color-green"
style={{ fontSize: 'inherit', fontFamily: 'inherit' }}
data-test-subj="cli-workbench-page-btn"
>
Workbench
</EuiLink>
, our advanced CLI. Check out our Quick Guides to learn more about Redis capabilities.
</span>
)}
</>,
'\n\n',
'Connecting...',
'\n\n',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const BulkActionsInfo = (props: Props) => {
)}
{status === BulkActionsStatus.Completed && (
<EuiText className={cx(styles.progress, styles.progressCompleted)}>
Action complete
Action completed
</EuiText>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
import { SCAN_COUNT_DEFAULT } from 'uiSrc/constants/api'
import HelpTexts from 'uiSrc/constants/help-texts'
import { KeyTypes, TableCellAlignment } from 'uiSrc/constants'
import { columnWidth } from 'uiSrc/components/virtual-grid'
import { getColumnWidth } from 'uiSrc/components/virtual-grid'
import { StopPropagation } from 'uiSrc/components/virtual-table'
import {
GetHashFieldsResponse,
Expand Down Expand Up @@ -369,7 +369,7 @@ const HashDetails = (props: Props) => {
onChangeWidth={setWidth}
columns={columns.map((column, i, arr) => ({
...column,
width: columnWidth(i, width, arr)
width: getColumnWidth(i, width, arr)
}))}
footerHeight={0}
loadMoreItems={loadMoreItems}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const KeyDetailsWrapper = (props: Props) => {
break
}
case KeyTypes.ReJSON: {
dispatch(fetchReJSON(key, '.', resetData))
dispatch(fetchReJSON(key, '.', true))
break
}
case KeyTypes.Stream: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { NoResultsFoundText } from 'uiSrc/constants/texts'
import VirtualTable from 'uiSrc/components/virtual-table/VirtualTable'
import InlineItemEditor from 'uiSrc/components/inline-item-editor/InlineItemEditor'
import { StopPropagation } from 'uiSrc/components/virtual-table'
import { columnWidth } from 'uiSrc/components/virtual-grid'
import { getColumnWidth } from 'uiSrc/components/virtual-grid'
import {
SetListElementDto,
SetListElementResponse,
Expand Down Expand Up @@ -323,7 +323,7 @@ const ListDetails = (props: Props) => {
onChangeWidth={setWidth}
columns={columns.map((column, i, arr) => ({
...column,
width: columnWidth(i, width, arr)
width: getColumnWidth(i, width, arr)
}))}
loadMoreItems={loadMoreItems}
loading={loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import HelpTexts from 'uiSrc/constants/help-texts'
import { NoResultsFoundText } from 'uiSrc/constants/texts'
import VirtualTable from 'uiSrc/components/virtual-table'
import PopoverDelete from 'uiSrc/pages/browser/components/popover-delete/PopoverDelete'
import { columnWidth } from 'uiSrc/components/virtual-grid'
import { getColumnWidth } from 'uiSrc/components/virtual-grid'
import { IColumnSearchState, ITableColumn } from 'uiSrc/components/virtual-table/interfaces'
import { GetSetMembersResponse } from 'apiSrc/modules/browser/dto/set.dto'
import styles from './styles.module.scss'
Expand Down Expand Up @@ -256,7 +256,7 @@ const SetDetails = (props: Props) => {
onSearch={handleSearch}
columns={columns.map((column, i, arr) => ({
...column,
width: columnWidth(i, width, arr)
width: getColumnWidth(i, width, arr)
}))}
onChangeWidth={setWidth}
cellCache={cellCache}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import VirtualTable from 'uiSrc/components/virtual-table/VirtualTable'
import InlineItemEditor from 'uiSrc/components/inline-item-editor/InlineItemEditor'
import { IColumnSearchState, ITableColumn } from 'uiSrc/components/virtual-table/interfaces'
import { StopPropagation } from 'uiSrc/components/virtual-table'
import { columnWidth } from 'uiSrc/components/virtual-grid'
import { getColumnWidth } from 'uiSrc/components/virtual-grid'
import { AddMembersToZSetDto, SearchZSetMembersResponse, ZSetMemberDto } from 'apiSrc/modules/browser/dto'
import PopoverDelete from '../popover-delete/PopoverDelete'

Expand Down Expand Up @@ -389,7 +389,7 @@ const ZSetDetails = (props: Props) => {
onChangeWidth={setWidth}
columns={columns.map((column, i, arr) => ({
...column,
width: columnWidth(i, width, arr)
width: getColumnWidth(i, width, arr)
}))}
footerHeight={0}
loadMoreItems={loadMoreItems}
Expand Down
5 changes: 3 additions & 2 deletions redisinsight/ui/src/slices/cli/cli-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CreateCliClientResponse, DeleteClientResponse } from 'apiSrc/modules/cl
import { apiService, sessionStorageService } from 'uiSrc/services'
import { ApiEndpoints, BrowserStorageItem } from 'uiSrc/constants'
import { getApiErrorMessage, getUrl, isStatusSuccessful } from 'uiSrc/utils'
import { concatToOutput, setCliDbIndex } from 'uiSrc/slices/cli/cli-output'
import { outputSelector, concatToOutput, setCliDbIndex } from 'uiSrc/slices/cli/cli-output'
import { cliTexts, ConnectionSuccessOutputText, InitOutputText } from 'uiSrc/constants/cliOutput'
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'

Expand Down Expand Up @@ -182,8 +182,9 @@ export function createCliClientAction(
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
const state = stateInit()
const { host, port, db } = connectedInstanceSelector(state)
const { data = [] } = outputSelector?.(state) ?? {}
dispatch(processCliClient())
dispatch(concatToOutput(InitOutputText(host, port, db, onWorkbenchClick)))
dispatch(concatToOutput(InitOutputText(host, port, db, !data.length, onWorkbenchClick)))

try {
const { data, status } = await apiService.post<CreateCliClientResponse>(
Expand Down