Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9aa0ec9

Browse files
Merge branch 'bot_ui_convert_thread_hotfix' into 'master'
Bot UI: Fixes multiple thread creation See merge request postgres-ai/database-lab!893
2 parents aea38ec + 07a2d1b commit 9aa0ec9

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed
Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
import {request} from "../../helpers/request";
22

3-
export const convertThread = async(thread_id: string): Promise<{ response: { final_thread_id: string, msg: string } | null; error: Response | null }> => {
3+
export const convertThread = (thread_id: string): Promise<{ response: { final_thread_id: string, msg: string } | null; error: Response | null }> => {
44
const apiServer = process.env.REACT_APP_BOT_API_URL || '';
55

6-
try {
7-
const response = await request(
8-
`/convert_thread`,
9-
{
10-
method: 'POST',
11-
body: JSON.stringify({
12-
thread_id
13-
})
14-
},
15-
apiServer
16-
);
17-
18-
if (!response.ok) {
19-
return { response: null, error: response };
20-
}
21-
22-
const responseData = await response.json();
23-
24-
return { response: responseData, error: null };
25-
26-
} catch (error) {
27-
return { response: null, error: error as Response };
28-
}
29-
}
6+
return request(
7+
`/convert_thread`,
8+
{
9+
method: 'POST',
10+
body: JSON.stringify({ thread_id }),
11+
},
12+
apiServer
13+
)
14+
.then(async (response) => {
15+
if (!response.ok) {
16+
return { response: null, error: response };
17+
}
18+
const responseData = await response.json();
19+
return { response: responseData, error: null };
20+
})
21+
.catch((error: Response) => {
22+
return { response: null, error };
23+
});
24+
};

‎ui/packages/platform/src/components/Dashboard/Dashboard.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ interface DashboardState {
101101
}
102102

103103
class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
104+
isThreadConverted = false;
104105
unsubscribe: Function
105106
componentDidMount() {
106107
const that = this
107108
const orgId = this.props.orgId
108109
const onlyProjects = this.props.onlyProjects
109110

110-
this.unsubscribe = (Store.listen as RefluxTypes['listen'])(asyncfunction () {
111+
this.unsubscribe = (Store.listen as RefluxTypes['listen'])(function () {
111112
that.setState({ data: this.data })
112113

113114
const auth: DashboardState['data']['auth'] =
@@ -118,20 +119,25 @@ class Dashboard extends Component<DashboardWithStylesProps, DashboardState> {
118119
const cookieName = "pgai_tmp_thread_id=";
119120
const cookies = document.cookie.split(';').map(cookie => cookie.trim());
120121
const pgaiTmpThreadId = cookies.find(cookie => cookie.startsWith(cookieName))?.substring(cookieName.length) || null;
121-
if (pgaiTmpThreadId) {
122+
if (pgaiTmpThreadId && !that.isThreadConverted) {
123+
that.isThreadConverted = true;
122124
try {
123-
const data = await convertThread(pgaiTmpThreadId);
124-
if (data?.response?.final_thread_id) {
125-
document.cookie = `${cookieName}=; expires=1970年1月01日 00:00:00 GMT; path=/; domain=.${window.location.hostname.split('.').slice(-2).join('.')}`;
126-
if (userProfile && userProfile.data && userProfile.data.orgs) {
127-
if (userProfile.data.orgs.hasOwnProperty('demo')) {
128-
that.props.history.push(`demo/bot/${data.response.final_thread_id}`);
125+
convertThread(pgaiTmpThreadId)
126+
.then(({response, error}) => {
127+
if (response?.final_thread_id) {
128+
document.cookie = `${cookieName}=; expires=1970年1月01日 00:00:00 GMT; path=/; domain=.${window.location.hostname.split('.').slice(-2).join('.')}`;
129+
if (userProfile && userProfile.data && userProfile.data.orgs) {
130+
if (userProfile.data.orgs.hasOwnProperty('demo')) {
131+
that.props.history.push(`demo/bot/${response.final_thread_id}`);
132+
}
133+
}
129134
}
130-
}
131-
}
135+
})
132136
} catch (error) {
133137
console.error('Error converting thread:', error);
134138
}
139+
} else {
140+
document.cookie = `${cookieName}=; expires=1970年1月01日 00:00:00 GMT; path=/; domain=.${window.location.hostname.split('.').slice(-2).join('.')}`;
135141
}
136142

137143
if (onlyProjects) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /