Skip to content

Commit 0015ce4

Browse files
Merge pull request #4197 from RedisInsight/feature/RI-6323-wb-big-responses
show original placeholder without applying visualization for big resp…
2 parents 17be0f6 + 9ab51df commit 0015ce4

File tree

6 files changed

+117
-45
lines changed

6 files changed

+117
-45
lines changed

redisinsight/api/src/__mocks__/workbench.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const mockCommandExecutionSuccessResult = Object.assign(new CommandExecut
2828
export const mockCommendExecutionHugeResultPlaceholder = Object.assign(new CommandExecutionResult(), {
2929
status: CommandExecutionStatus.Success,
3030
response: 'Results have been deleted since they exceed 1 MB. Re-run the command to see new results.',
31+
sizeLimitExceeded: true,
3132
});
3233

3334
export const mockCommendExecutionHugeResultPlaceholderEncrypted = 'huge_result_placeholder_encrypted';

redisinsight/api/src/modules/workbench/models/command-execution-result.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ export class CommandExecutionResult {
1717
})
1818
@Expose()
1919
response: any;
20+
21+
@ApiProperty({
22+
type: Boolean,
23+
description: 'Flag showing if response was replaced with message notification about response size limit threshold',
24+
})
25+
@Expose()
26+
sizeLimitExceeded?: boolean;
2027
}

redisinsight/api/src/modules/workbench/repositories/local-command-execution.repository.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class LocalCommandExecutionRepository extends CommandExecutionRepository
5151
{
5252
status: CommandExecutionStatus.Success,
5353
response: ERROR_MESSAGES.WORKBENCH_RESPONSE_TOO_BIG(),
54+
sizeLimitExceeded: true,
5455
},
5556
]);
5657
// Hack, do not store isNotStored. Send once to show warning
@@ -61,7 +62,10 @@ export class LocalCommandExecutionRepository extends CommandExecutionRepository
6162
...(await this.commandExecutionRepository.save(await this.modelEncryptor.encryptEntity(entity))),
6263
command: commandExecutions[idx].command, // avoid decryption
6364
mode: commandExecutions[idx].mode,
64-
result: commandExecutions[idx].result, // avoid decryption + show original response when it was huge
65+
// avoid decryption + show original response when it was huge
66+
// also will return original response even if it wasn't stored
67+
// so flag sizeLimitExceeded will be undefined
68+
result: commandExecutions[idx].result,
6569
summary: commandExecutions[idx].summary,
6670
executionTime: commandExecutions[idx].executionTime,
6771
isNotStored,

redisinsight/api/test/api/workbench/POST-databases-id-workbench-command_executions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ describe('POST /databases/:instanceId/workbench/command-executions', () => {
160160
expect(localDb.encryptData(JSON.stringify([{
161161
status: 'success',
162162
response: 'Results have been deleted since they exceed 1 MB. Re-run the command to see new results.',
163+
sizeLimitExceeded: true,
163164
}]))).to.eql(entity.result);
164165
}
165166
},

redisinsight/ui/src/components/query/query-card/QueryCard.spec.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { instance, mock } from 'ts-mockito'
44
import { toggleOpenWBResult } from 'uiSrc/slices/workbench/wb-results'
55
import { ResultsMode } from 'uiSrc/slices/interfaces/workbench'
66
import { cleanup, clearStoreActions, fireEvent, mockedStore, render } from 'uiSrc/utils/test-utils'
7+
import { CommandExecutionStatus } from 'uiSrc/slices/interfaces/cli'
78
import QueryCard, { Props, getSummaryText } from './QueryCard'
89

910
const mockedProps = mock<Props>()
@@ -137,4 +138,41 @@ describe('QueryCard', () => {
137138
expect(queryCommonResultEl).toBeInTheDocument()
138139
expect(queryCliResultEl).not.toBeInTheDocument()
139140
})
141+
142+
it('should render QueryCardCliResult when result reached response size threshold', () => {
143+
const { queryByTestId } = render(
144+
<QueryCard
145+
{...instance(mockedProps)}
146+
resultsMode={ResultsMode.GroupMode}
147+
result={[{
148+
status: CommandExecutionStatus.Success,
149+
response: 'Any message about size limit threshold exceeded',
150+
sizeLimitExceeded: true
151+
}]}
152+
isOpen
153+
command={null}
154+
/>
155+
)
156+
const queryCliResultEl = queryByTestId('query-cli-result')
157+
158+
expect(queryCliResultEl).toBeInTheDocument()
159+
})
160+
161+
it('should render QueryCardCliResult when result reached response size threshold even w/o flag', () => {
162+
const { queryByTestId } = render(
163+
<QueryCard
164+
{...instance(mockedProps)}
165+
resultsMode={ResultsMode.GroupMode}
166+
result={[{
167+
status: CommandExecutionStatus.Success,
168+
response: 'Results have been deleted since they exceed 1 MB. Re-run the command to see new results.',
169+
}]}
170+
isOpen
171+
command={null}
172+
/>
173+
)
174+
const queryCliResultEl = queryByTestId('query-cli-result')
175+
176+
expect(queryCliResultEl).toBeInTheDocument()
177+
})
140178
})

redisinsight/ui/src/components/query/query-card/QueryCard.tsx

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ const QueryCard = (props: Props) => {
152152

153153
const commonError = CommonErrorResponse(id, command, result)
154154

155+
const isSizeLimitExceededResponse = (result: Maybe<CommandExecutionResult[]>) => {
156+
const resultObj = result?.[0]
157+
// response.includes - to be backward compatible with responses which don't include sizeLimitExceeded flag
158+
return resultObj?.sizeLimitExceeded === true || resultObj?.response?.includes('Results have been deleted')
159+
}
160+
155161
return (
156162
<div
157163
className={cx(styles.containerWrapper, {
@@ -196,50 +202,65 @@ const QueryCard = (props: Props) => {
196202
? <QueryCardCommonResult loading={loading} result={commonError} />
197203
: (
198204
<>
199-
{isGroupResults(resultsMode) && (
200-
<QueryCardCliResultWrapper
201-
loading={loading}
202-
query={command}
203-
db={db}
204-
resultsMode={resultsMode}
205-
result={result}
206-
isNotStored={isNotStored}
207-
isFullScreen={isFullScreen}
208-
data-testid="group-mode-card"
209-
/>
210-
)}
211-
{(resultsMode === ResultsMode.Default || !resultsMode) && (
212-
<>
213-
{viewTypeSelected === WBQueryType.Plugin && (
214-
<>
215-
{!loading && result !== undefined ? (
216-
<QueryCardCliPlugin
217-
id={selectedViewValue}
218-
result={result}
219-
query={command}
220-
mode={mode}
221-
setMessage={setMessage}
222-
commandId={id}
223-
/>
224-
) : (
225-
<div className={styles.loading}>
226-
<EuiLoadingContent lines={5} data-testid="loading-content" />
227-
</div>
228-
)}
229-
</>
230-
)}
231-
{(viewTypeSelected === WBQueryType.Text) && (
232-
<QueryCardCliResultWrapper
233-
loading={loading}
234-
query={command}
235-
resultsMode={resultsMode}
236-
result={result}
237-
isNotStored={isNotStored}
238-
isFullScreen={isFullScreen}
239-
/>
240-
)}
241-
</>
242-
)}
205+
{isSizeLimitExceededResponse(result)
206+
? (
207+
<QueryCardCliResultWrapper
208+
loading={loading}
209+
query={command}
210+
resultsMode={resultsMode}
211+
result={result}
212+
isNotStored={isNotStored}
213+
isFullScreen={isFullScreen}
214+
/>
215+
)
216+
: (
217+
<>
218+
{isGroupResults(resultsMode) && (
219+
<QueryCardCliResultWrapper
220+
loading={loading}
221+
query={command}
222+
db={db}
223+
resultsMode={resultsMode}
224+
result={result}
225+
isNotStored={isNotStored}
226+
isFullScreen={isFullScreen}
227+
data-testid="group-mode-card"
228+
/>
229+
)}
230+
{(resultsMode === ResultsMode.Default || !resultsMode) && (
231+
<>
232+
{viewTypeSelected === WBQueryType.Plugin && (
233+
<>
234+
{!loading && result !== undefined ? (
235+
<QueryCardCliPlugin
236+
id={selectedViewValue}
237+
result={result}
238+
query={command}
239+
mode={mode}
240+
setMessage={setMessage}
241+
commandId={id}
242+
/>
243+
) : (
244+
<div className={styles.loading}>
245+
<EuiLoadingContent lines={5} data-testid="loading-content" />
246+
</div>
247+
)}
248+
</>
249+
)}
250+
{(viewTypeSelected === WBQueryType.Text) && (
251+
<QueryCardCliResultWrapper
252+
loading={loading}
253+
query={command}
254+
resultsMode={resultsMode}
255+
result={result}
256+
isNotStored={isNotStored}
257+
isFullScreen={isFullScreen}
258+
/>
259+
)}
260+
</>
261+
)}
262+
</>
263+
)}
243264
</>
244265
)}
245266
</>

0 commit comments

Comments
 (0)