Skip to content

Commit f10ddb2

Browse files
committed
#RI-3749 - fix last field deletion context for list, zset, set data types
1 parent ea0a70b commit f10ddb2

File tree

7 files changed

+27
-17
lines changed

7 files changed

+27
-17
lines changed

redisinsight/ui/src/pages/browser/components/key-details-remove-items/remove-list-elements/RemoveListElements.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import {
4040
import styles from '../styles.module.scss'
4141

4242
export interface Props {
43-
onCancel: () => void;
43+
onCancel: () => void
44+
onRemoveKey: () => void
4445
}
4546

4647
const optionsDestinations: EuiSuperSelectOption<string>[] = [
@@ -55,7 +56,7 @@ const optionsDestinations: EuiSuperSelectOption<string>[] = [
5556
]
5657

5758
const RemoveListElements = (props: Props) => {
58-
const { onCancel } = props
59+
const { onCancel, onRemoveKey } = props
5960

6061
const [count, setCount] = useState<string>('')
6162
const [destination, setDestination] = useState<ListElementDestination>(TAIL_DESTINATION)
@@ -119,7 +120,8 @@ const RemoveListElements = (props: Props) => {
119120
setIsPopoverOpen(false)
120121
}
121122

122-
const onSuccessRemoved = () => {
123+
const onSuccessRemoved = (newTotal: number) => {
124+
if (newTotal <= 0) onRemoveKey()
123125
onCancel()
124126
sendEventTelemetry({
125127
event: getBasedOnViewTypeEvent(

redisinsight/ui/src/pages/browser/components/key-details/KeyDetails/KeyDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ const KeyDetails = ({ ...props }: Props) => {
123123
}
124124

125125
const TypeDetails: any = {
126-
[KeyTypes.ZSet]: <ZSetDetails isFooterOpen={isAddItemPanelOpen} />,
127-
[KeyTypes.Set]: <SetDetails isFooterOpen={isAddItemPanelOpen} />,
126+
[KeyTypes.ZSet]: <ZSetDetails isFooterOpen={isAddItemPanelOpen} onRemoveKey={onRemoveKey} />,
127+
[KeyTypes.Set]: <SetDetails isFooterOpen={isAddItemPanelOpen} onRemoveKey={onRemoveKey} />,
128128
[KeyTypes.String]: (
129129
<StringDetails
130130
isEditItem={editItem}
@@ -224,7 +224,7 @@ const KeyDetails = ({ ...props }: Props) => {
224224
{isRemoveItemPanelOpen && (
225225
<div className={cx('formFooterBar', styles.contentActive)}>
226226
{selectedKeyType === KeyTypes.List && (
227-
<RemoveListElements onCancel={closeRemoveItemPanel} />
227+
<RemoveListElements onCancel={closeRemoveItemPanel} onRemoveKey={onRemoveKey} />
228228
)}
229229
</div>
230230
)}

redisinsight/ui/src/pages/browser/components/set-details/SetDetails.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ const cellCache = new CellMeasurerCache({
5151

5252
export interface Props {
5353
isFooterOpen: boolean
54+
onRemoveKey: () => void
5455
}
5556

5657
const SetDetails = (props: Props) => {
57-
const { isFooterOpen } = props
58+
const { isFooterOpen, onRemoveKey } = props
5859

5960
const { loading } = useSelector(setSelector)
6061
const { members: loadedMembers, total, nextCursor } = useSelector(setDataSelector)
@@ -100,7 +101,8 @@ const SetDetails = (props: Props) => {
100101
setDeleting(`${member + suffix}`)
101102
}
102103

103-
const onSuccessRemoved = () => {
104+
const onSuccessRemoved = (newTotal: number) => {
105+
newTotal === 0 && onRemoveKey()
104106
sendEventTelemetry({
105107
event: getBasedOnViewTypeEvent(
106108
viewType,

redisinsight/ui/src/pages/browser/components/zset-details/ZSetDetails.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ interface IZsetMember extends ZsetMember {
6161

6262
export interface Props {
6363
isFooterOpen: boolean
64+
onRemoveKey: () => void
6465
}
6566

6667
const ZSetDetails = (props: Props) => {
67-
const { isFooterOpen } = props
68+
const { isFooterOpen, onRemoveKey } = props
6869

6970
const { loading, searching } = useSelector(zsetSelector)
7071
const { loading: updateLoading } = useSelector(updateZsetScoreStateSelector)
@@ -119,7 +120,8 @@ const ZSetDetails = (props: Props) => {
119120
setDeleting(`${member + suffix}`)
120121
}, [])
121122

122-
const onSuccessRemoved = () => {
123+
const onSuccessRemoved = (newTotal: number) => {
124+
newTotal === 0 && onRemoveKey()
123125
sendEventTelemetry({
124126
event: getBasedOnViewTypeEvent(
125127
viewType,

redisinsight/ui/src/slices/browser/list.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export function insertListElementsAction(
429429
// Asynchronous thunk action
430430
export function deleteListElementsAction(
431431
data: DeleteListElementsDto,
432-
onSuccessAction?: () => void,
432+
onSuccessAction?: (newTotal: number) => void,
433433
onFailAction?: () => void
434434
) {
435435
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
@@ -445,9 +445,11 @@ export function deleteListElementsAction(
445445
{ data, params: { encoding } },
446446
)
447447
if (isStatusSuccessful(status)) {
448-
onSuccessAction?.()
448+
const newTotal = state.browser.list.data?.total - data.count
449+
450+
onSuccessAction?.(newTotal)
449451
dispatch(deleteListElementsSuccess())
450-
if (state.browser.list.data?.total - data.count > 0) {
452+
if (newTotal > 0) {
451453
dispatch<any>(fetchKeyInfo(data.keyName))
452454
dispatch(addMessageNotification(
453455
successMessages.REMOVED_LIST_ELEMENTS(

redisinsight/ui/src/slices/browser/set.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export function addSetMembersAction(
310310
export function deleteSetMembers(
311311
key: RedisResponseBuffer,
312312
members: RedisResponseBuffer[],
313-
onSuccessAction?: () => void,
313+
onSuccessAction?: (newTotal: number) => void,
314314
) {
315315
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
316316
dispatch(removeSetMembers())
@@ -333,8 +333,9 @@ export function deleteSetMembers(
333333
)
334334

335335
if (isStatusSuccessful(status)) {
336-
onSuccessAction?.()
337336
const newTotalValue = state.browser.set.data.total - data.affected
337+
338+
onSuccessAction?.(newTotalValue)
338339
dispatch(removeSetMembersSuccess())
339340
dispatch(removeMembersFromList(members))
340341
if (newTotalValue > 0) {

redisinsight/ui/src/slices/browser/zset.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export function fetchAddZSetMembers(
351351
export function deleteZSetMembers(
352352
key: RedisResponseBuffer,
353353
members: RedisResponseBuffer[],
354-
onSuccessAction?: () => void,
354+
onSuccessAction?: (newTotal: number) => void,
355355
) {
356356
return async (dispatch: AppDispatch, stateInit: () => RootState) => {
357357
dispatch(removeZsetMembers())
@@ -372,8 +372,9 @@ export function deleteZSetMembers(
372372
}
373373
)
374374
if (isStatusSuccessful(status)) {
375-
onSuccessAction?.()
376375
const newTotalValue = state.browser.zset.data.total - data.affected
376+
377+
onSuccessAction?.(newTotalValue)
377378
dispatch(removeZsetMembersSuccess())
378379
dispatch(removeMembersFromList(members))
379380
if (newTotalValue > 0) {

0 commit comments

Comments
 (0)