Skip to content

Commit 5ba2a43

Browse files
Merge pull request #2397 from RedisInsight/feature/RI-4669-clear-wb-history
Feature/ri 4669 clear wb history
2 parents b5ff815 + 253376c commit 5ba2a43

File tree

24 files changed

+500
-58
lines changed

24 files changed

+500
-58
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export abstract class CommandExecutionRepository {
66
abstract getList(databaseId: string): Promise<ShortCommandExecution[]>;
77
abstract getOne(databaseId: string, id: string): Promise<CommandExecution>;
88
abstract delete(databaseId: string, id: string): Promise<void>;
9+
abstract deleteAll(databaseId: string): Promise<void>;
910
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ describe('LocalCommandExecutionRepository', () => {
253253
);
254254
});
255255
});
256+
describe('deleteAll', () => {
257+
it('Should not return anything on delete', async () => {
258+
repository.delete.mockResolvedValueOnce(1);
259+
expect(await service.deleteAll(mockDatabase.id)).toEqual(
260+
undefined,
261+
);
262+
});
263+
});
256264
describe('cleanupDatabaseHistory', () => {
257265
it('Should should not return anything on cleanup', async () => {
258266
mockQueryBuilderGetManyRaw.mockReturnValueOnce([

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@ export class LocalCommandExecutionRepository extends CommandExecutionRepository
163163
this.logger.log('Command execution deleted');
164164
}
165165

166+
/**
167+
* Delete all items
168+
*
169+
* @param databaseId
170+
*/
171+
async deleteAll(databaseId: string): Promise<void> {
172+
this.logger.log('Delete all command executions');
173+
174+
await this.commandExecutionRepository.delete({ databaseId });
175+
176+
this.logger.log('Command executions deleted');
177+
}
178+
166179
/**
167180
* Clean history for particular database to fit 30 items limitation
168181
* @param databaseId

redisinsight/api/src/modules/workbench/workbench.controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ export class WorkbenchController {
9898
): Promise<void> {
9999
return this.service.deleteCommandExecution(databaseId, id);
100100
}
101+
102+
@ApiEndpoint({
103+
description: 'Delete command executions',
104+
statusCode: 200,
105+
})
106+
@Delete('/command-executions')
107+
@ApiRedisParams()
108+
async deleteCommandExecutions(
109+
@Param('dbInstance') databaseId: string,
110+
): Promise<void> {
111+
return this.service.deleteCommandExecutions(databaseId);
112+
}
101113
}

redisinsight/api/src/modules/workbench/workbench.service.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const mockCommandExecutionRepository = () => ({
134134
getList: jest.fn(),
135135
getOne: jest.fn(),
136136
delete: jest.fn(),
137+
deleteAll: jest.fn(),
137138
});
138139

139140
describe('WorkbenchService', () => {
@@ -389,6 +390,17 @@ describe('WorkbenchService', () => {
389390
mockCommandExecution.id,
390391
);
391392

393+
expect(result).toEqual(undefined);
394+
});
395+
});
396+
describe('deleteCommandExecutions', () => {
397+
it('should not return anything on delete', async () => {
398+
commandExecutionProvider.deleteAll.mockResolvedValueOnce('some response');
399+
400+
const result = await service.deleteCommandExecutions(
401+
mockWorkbenchClientMetadata.databaseId,
402+
);
403+
392404
expect(result).toEqual(undefined);
393405
});
394406
});

redisinsight/api/src/modules/workbench/workbench.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ export class WorkbenchService {
187187
this.analyticsService.sendCommandDeletedEvent(databaseId);
188188
}
189189

190+
/**
191+
* Delete command executions by databaseId
192+
*
193+
* @param databaseId
194+
*/
195+
async deleteCommandExecutions(databaseId: string): Promise<void> {
196+
await this.commandExecutionRepository.deleteAll(databaseId);
197+
}
198+
190199
/**
191200
* Check if workbench allows such command
192201
* @param commandLine
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {
2+
expect,
3+
describe,
4+
it,
5+
deps,
6+
validateApiCall,
7+
} from '../deps';
8+
const { server, request, constants, rte, localDb } = deps;
9+
10+
// endpoint to test
11+
const endpoint = (
12+
instanceId = constants.TEST_INSTANCE_ID,
13+
) =>
14+
request(server).delete(`/${constants.API.DATABASES}/${instanceId}/workbench/command-executions`);
15+
16+
const mainCheckFn = async (testCase) => {
17+
it(testCase.name, async () => {
18+
// additional checks before test run
19+
if (testCase.before) {
20+
await testCase.before();
21+
}
22+
23+
await validateApiCall({
24+
endpoint,
25+
...testCase,
26+
});
27+
28+
// additional checks after test pass
29+
if (testCase.after) {
30+
await testCase.after();
31+
}
32+
});
33+
};
34+
35+
describe('DELETE /databases/:instanceId/workbench/command-executions', () => {
36+
describe('Common', () => {
37+
[
38+
{
39+
name: 'Should return 404 not found when incorrect instance',
40+
endpoint: () => endpoint(
41+
constants.TEST_NOT_EXISTED_INSTANCE_ID,
42+
),
43+
statusCode: 404,
44+
responseBody: {
45+
statusCode: 404,
46+
message: 'Invalid database instance id.',
47+
error: 'Not Found'
48+
},
49+
},
50+
{
51+
name: 'Should return 0 array when no history items yet',
52+
before: async () => {
53+
await localDb.generateNCommandExecutions({
54+
databaseId: constants.TEST_INSTANCE_ID,
55+
id: constants.TEST_COMMAND_EXECUTION_ID_1,
56+
}, 2);
57+
},
58+
after: async () => {
59+
expect(await (await localDb.getRepository(localDb.repositories.COMMAND_EXECUTION)).count({})).to.eq(0)
60+
},
61+
},
62+
].map(mainCheckFn);
63+
});
64+
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface Props {
3939
summary?: ResultsSummary
4040
createdAt?: Date
4141
loading?: boolean
42+
clearing?: boolean
4243
isNotStored?: boolean
4344
executionTime?: number
4445
db?: number
@@ -80,6 +81,7 @@ const QueryCard = (props: Props) => {
8081
onQueryProfile,
8182
onQueryReRun,
8283
loading,
84+
clearing,
8385
emptyCommand,
8486
isNotStored,
8587
executionTime,
@@ -173,6 +175,7 @@ const QueryCard = (props: Props) => {
173175
isFullScreen={isFullScreen}
174176
query={command}
175177
loading={loading}
178+
clearing={clearing}
176179
createdAt={createdAt}
177180
message={message}
178181
queryType={queryType}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export interface Props {
6262
queryType: WBQueryType
6363
selectedValue: string
6464
loading?: boolean
65+
clearing?: boolean
6566
executionTime?: number
6667
emptyCommand?: boolean
6768
db?: number
@@ -96,6 +97,7 @@ const QueryCardHeader = (props: Props) => {
9697
toggleFullScreen,
9798
query = '',
9899
loading,
100+
clearing,
99101
message,
100102
createdAt,
101103
mode,
@@ -169,6 +171,7 @@ const QueryCardHeader = (props: Props) => {
169171
const handleQueryDelete = (event: React.MouseEvent) => {
170172
eventStop(event)
171173
onQueryDelete()
174+
sendEvent(TelemetryEvent.WORKBENCH_CLEAR_RESULT_CLICKED, query)
172175
}
173176

174177
const handleQueryReRun = (event: React.MouseEvent) => {
@@ -404,7 +407,7 @@ const QueryCardHeader = (props: Props) => {
404407
</EuiFlexItem>
405408
<EuiFlexItem grow={false} className={styles.buttonIcon}>
406409
<EuiButtonIcon
407-
disabled={loading}
410+
disabled={loading || clearing}
408411
iconType="trash"
409412
aria-label="Delete command"
410413
data-testid="delete-command"

redisinsight/ui/src/constants/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ enum ApiEndpoints {
7777
SETTINGS_AGREEMENTS_SPEC = 'settings/agreements/spec',
7878

7979
WORKBENCH_COMMAND_EXECUTIONS = 'workbench/command-executions',
80-
WORKBENCH_COMMANDS_EXECUTION = 'workbench/commands-execution',
8180

8281
PROFILER = 'profiler',
8382
PROFILER_LOGS = 'profiler/logs',

0 commit comments

Comments
 (0)