Skip to content

Commit 7004e19

Browse files
authored
Merge branch 'main' into mg/OPS-2983
2 parents d042294 + fbe5a81 commit 7004e19

4 files changed

Lines changed: 33 additions & 44 deletions

File tree

packages/react-ui/src/app/features/ai/lib/assistant-ui-chat-hook.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ export const useAssistantChat = ({
232232
toast(errorToast);
233233
},
234234
onFinish: async () => {
235+
if (chatMode !== ChatMode.Agent) {
236+
return;
237+
}
238+
235239
if (!chatId || hasAttemptedNameGenerationRef.current[chatId]) {
236240
return;
237241
}

packages/react-ui/src/app/routes/openops-tables/index.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,16 @@ import { t } from 'i18next';
22
import { useLocation } from 'react-router-dom';
33

44
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
5-
import { platformHooks } from '@/app/common/hooks/platform-hooks';
6-
import { projectHooks } from '@/app/common/hooks/project-hooks';
75
import { useDefaultSidebarState } from '@/app/common/hooks/use-default-sidebar-state';
86
import { useCandu } from '@/app/features/extensions/candu/use-candu';
97
import { FlagId } from '@openops/shared';
108

119
const OpenOpsTablesPage = () => {
1210
useDefaultSidebarState('minimized');
1311
const { isCanduEnabled, canduClientToken, canduUserId } = useCandu();
14-
const { project } = projectHooks.useCurrentProject();
15-
const { platform: organization } = platformHooks.useCurrentPlatform();
16-
17-
// TODO: Remove type assertion and remove organization?.tablesWorkspaceId fallback once Phase 1 is complete
18-
const workspaceId =
19-
(project as any)?.tablesWorkspaceId ?? organization?.tablesWorkspaceId;
20-
21-
const parentDataObj = {
22-
userId: canduUserId ?? undefined,
23-
canduClientToken: canduClientToken ?? undefined,
24-
...(isCanduEnabled && { isCanduEnabled: true }),
25-
...(workspaceId !== undefined && { workspaceId }),
26-
};
27-
28-
const parentData = encodeURIComponent(JSON.stringify(parentDataObj));
12+
const parentData = encodeURIComponent(
13+
JSON.stringify({ isCanduEnabled, userId: canduUserId, canduClientToken }),
14+
);
2915

3016
const location = useLocation();
3117
const params = new URLSearchParams(location.search);
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { createAxiosHeaders, makeOpenOpsTablesPost } from '@openops/common';
22

3+
const TOKEN_NAME_PREFIX = 'Project_';
4+
35
export type DatabaseToken = {
46
id: number;
57
name: string;
@@ -13,26 +15,20 @@ export type DatabaseToken = {
1315
};
1416
};
1517

16-
export type CreateDatabaseTokenParams = {
17-
name: string;
18-
workspaceId: number;
19-
systemToken: string;
20-
};
21-
2218
export async function createDatabaseToken(
23-
params: CreateDatabaseTokenParams,
19+
workspaceId: number,
20+
token: string,
2421
): Promise<DatabaseToken> {
2522
const payload = {
26-
name: params.name,
27-
workspace: params.workspaceId,
23+
name: 'OpenOps Token',
24+
workspace: workspaceId,
2825
};
2926

30-
const headers = createAxiosHeaders(params.systemToken);
31-
const response = await makeOpenOpsTablesPost<DatabaseToken>(
27+
const headers = createAxiosHeaders(token);
28+
29+
return makeOpenOpsTablesPost<DatabaseToken>(
3230
'api/database/tokens/',
3331
payload,
3432
headers,
3533
);
36-
37-
return response;
3834
}
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
const openopsCommonMock = {
22
...jest.requireActual('@openops/common'),
33
makeOpenOpsTablesPost: jest.fn(),
4+
createAxiosHeaders: jest.fn(),
45
};
56
jest.mock('@openops/common', () => openopsCommonMock);
67

78
import { AxiosHeaders } from 'axios';
89
import { createDatabaseToken } from '../../../src/app/openops-tables/create-database-token';
910

10-
describe('createDatabaseToken', () => {
11+
describe('createProjectDatabaseToken', () => {
1112
beforeEach(() => {
1213
jest.clearAllMocks();
1314
});
1415

1516
it('should return the created token on successful creation', async () => {
16-
const params = {
17-
name: 'Test Token',
18-
workspaceId: 1,
19-
systemToken: 'test_system_token',
20-
};
17+
const token = 'test_system_token';
18+
const workspaceId = 1;
19+
20+
const mockHeaders = new AxiosHeaders({
21+
'Content-Type': 'application/json',
22+
Authorization: `JWT ${token}`,
23+
});
2124
const mockTokenResponse = {
2225
id: 1,
23-
name: 'Test Token',
26+
name: 'Project_test-project-123',
2427
workspace: 1,
2528
key: 'test_database_token_key',
2629
permissions: {
@@ -31,23 +34,23 @@ describe('createDatabaseToken', () => {
3134
},
3235
};
3336

37+
openopsCommonMock.createAxiosHeaders.mockReturnValue(mockHeaders);
3438
openopsCommonMock.makeOpenOpsTablesPost.mockResolvedValue(
3539
mockTokenResponse,
3640
);
3741

38-
const result = await createDatabaseToken(params);
42+
const result = await createDatabaseToken(workspaceId, token);
3943

4044
expect(result).toEqual(mockTokenResponse);
45+
expect(openopsCommonMock.createAxiosHeaders).toHaveBeenCalledTimes(1);
46+
expect(openopsCommonMock.createAxiosHeaders).toHaveBeenCalledWith(token);
4147
expect(openopsCommonMock.makeOpenOpsTablesPost).toHaveBeenCalledWith(
4248
'api/database/tokens/',
4349
{
44-
name: params.name,
45-
workspace: params.workspaceId,
50+
name: 'OpenOps Token',
51+
workspace: workspaceId,
4652
},
47-
new AxiosHeaders({
48-
'Content-Type': 'application/json',
49-
Authorization: `JWT ${params.systemToken}`,
50-
}),
53+
mockHeaders,
5154
);
5255
});
5356
});

0 commit comments

Comments
 (0)