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 cec5d15

Browse files
AdrinlolNikolayS
authored andcommitted
fix(ui): add instance status refresh
1 parent a34ddc9 commit cec5d15

File tree

8 files changed

+63
-16
lines changed

8 files changed

+63
-16
lines changed

‎ui/packages/platform/src/actions/actions.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const Actions = Reflux.createActions([{
6464
editDbLabInstance: ASYNC_ACTION,
6565
destroyDbLabInstance: ASYNC_ACTION,
6666
resetNewDbLabInstance: {},
67-
reloadDblabInstance: ASYNC_ACTION,
67+
getDbLabInstanceStatus: ASYNC_ACTION,
6868
checkDbLabInstanceUrl: ASYNC_ACTION,
6969
downloadReportJsonFiles: ASYNC_ACTION,
7070
addOrgDomain: ASYNC_ACTION,
@@ -846,7 +846,7 @@ Actions.destroyDbLabInstance.listen(function (token, instanceId) {
846846
});
847847
});
848848

849-
Actions.reloadDblabInstance.listen(function (token, instanceId) {
849+
Actions.getDbLabInstanceStatus.listen(function (token, instanceId) {
850850
let action = this;
851851

852852
if (!api) {
@@ -857,12 +857,12 @@ Actions.reloadDblabInstance.listen(function (token, instanceId) {
857857

858858
action.progressed({ instanceId: instanceId });
859859

860-
timeoutPromise(REQUEST_TIMEOUT, api.getInstance(token, instanceId))
860+
timeoutPromise(REQUEST_TIMEOUT, api.getDbLabInstanceStatus(token, instanceId))
861861
.then(result => {
862862
result.json()
863863
.then(json => {
864864
if (json) {
865-
action.completed({ data: json[0], instanceId: instanceId });
865+
action.completed({ data: json, instanceId: instanceId });
866866
} else {
867867
action.failed({ instanceId: instanceId }, new Error(
868868
'wrong_reply'));

‎ui/packages/platform/src/api/api.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function encodeData(data) {
1616

1717
class Api {
1818
constructor(setting) {
19-
this.server = setting.server;
19+
this.server = setting.server
2020
this.apiServer = setting.apiServer
2121
}
2222

@@ -544,16 +544,16 @@ class Api {
544544
});
545545
}
546546

547-
getInstance(token, orgId) {
547+
getDbLabInstanceStatus(token, instanceId) {
548548
let headers = {
549549
Authorization: 'Bearer ' + token
550550
};
551551

552-
return this.get(`${this.apiServer}/dblab_instances`,{
553-
id: `eq.${orgId}`
552+
return this.post(`${this.apiServer}/rpc/dblab_instance_status_refresh`,{
553+
instance_id: instanceId
554554
}, {
555-
headers: headers,
556-
})
555+
headers: headers
556+
});
557557
}
558558

559559
checkDbLabInstanceUrl(token, url, verifyToken, useTunnel) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*--------------------------------------------------------------------------
2+
* Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
3+
* All Rights Reserved. Proprietary and confidential.
4+
* Unauthorized copying of this file, via any medium is strictly prohibited
5+
*--------------------------------------------------------------------------
6+
*/
7+
8+
import { RefreshInstance } from '@postgres.ai/shared/types/api/endpoints/refreshInstance'
9+
10+
import { request } from 'helpers/request'
11+
12+
export const refreshInstance: RefreshInstance = async (req) => {
13+
const response = await request('/rpc/dblab_instance_status_refresh', {
14+
method: 'post',
15+
body: JSON.stringify({
16+
instance_id: req.instanceId,
17+
}),
18+
})
19+
20+
return {
21+
response: response.ok ? true : null,
22+
error: response.ok ? null : response,
23+
}
24+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class DbLabInstances extends Component<
250250
break
251251

252252
case 'refresh':
253-
Actions.reloadDblabInstance(auth?.token, instanceId)
253+
Actions.getDbLabInstanceStatus(auth?.token, instanceId)
254254

255255
break
256256

‎ui/packages/platform/src/pages/Instance/index.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Instance as InstancePage } from '@postgres.ai/shared/pages/Instance'
55
import { ConsoleBreadcrumbsWrapper } from 'components/ConsoleBreadcrumbs/ConsoleBreadcrumbsWrapper'
66
import { ROUTES } from 'config/routes'
77
import { getInstance } from 'api/instances/getInstance'
8+
import { refreshInstance } from 'api/instances/refreshInstance'
89
import { getSnapshots } from 'api/snapshots/getSnapshots'
910
import { destroyClone } from 'api/clones/destroyClone'
1011
import { resetClone } from 'api/clones/resetClone'
@@ -54,6 +55,7 @@ export const Instance = () => {
5455
getInstance,
5556
getSnapshots,
5657
destroyClone,
58+
refreshInstance,
5759
resetClone,
5860
getWSToken,
5961
getConfig,

‎ui/packages/platform/src/stores/store.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ const Store = Reflux.createStore({
13141314
};
13151315
},
13161316

1317-
onReloadDblabInstanceFailed: function (data, error) {
1317+
onGetDbLabInstanceStatusFailed: function (data, error) {
13181318
this.data.dbLabInstanceStatus.isProcessing = false;
13191319
this.data.dbLabInstanceStatus.isProcessed = true;
13201320
this.data.dbLabInstanceStatus.error = true;
@@ -1336,7 +1336,7 @@ const Store = Reflux.createStore({
13361336
this.trigger(this.data);
13371337
},
13381338

1339-
onReloadDblabInstanceProgressed: function (data) {
1339+
onGetDbLabInstanceStatusProgressed: function (data) {
13401340
this.data.dbLabInstanceStatus.isProcessing = true;
13411341
this.data.dbLabInstanceStatus.isProcessed = false;
13421342
this.data.dbLabInstanceStatus.error = false;
@@ -1358,7 +1358,7 @@ const Store = Reflux.createStore({
13581358
this.trigger(this.data);
13591359
},
13601360

1361-
onReloadDblabInstanceCompleted: function (data) {
1361+
onGetDbLabInstanceStatusCompleted: function (data) {
13621362
this.data.dbLabInstanceStatus.isProcessing = false;
13631363
this.data.dbLabInstanceStatus.errorMessage = this.getError(data.data);
13641364
this.data.dbLabInstanceStatus.error = !!this.data.dbLabInstanceStatus

‎ui/packages/shared/pages/Instance/index.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const Instance = observer((props: Props) => {
7373
instanceRetrieval,
7474
isLoadingInstance,
7575
load,
76+
reload,
7677
} = stores.main
7778

7879
const switchTab = (_: React.ChangeEvent<{}> | null, tabID: number) => {
@@ -120,7 +121,7 @@ export const Instance = observer((props: Props) => {
120121
className={classes.title}
121122
rightContent={
122123
<Button
123-
onClick={() => load(props.instanceId)}
124+
onClick={() => reload(props.instanceId)}
124125
isDisabled={!instance && !instanceError}
125126
className={classes.reloadButton}
126127
>

‎ui/packages/shared/pages/Instance/stores/Main.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Config } from '@postgres.ai/shared/types/api/entities/config'
1212
import { GetConfig } from '@postgres.ai/shared/types/api/endpoints/getConfig'
1313
import { UpdateConfig } from '@postgres.ai/shared/types/api/endpoints/updateConfig'
1414
import { TestDbSource } from '@postgres.ai/shared/types/api/endpoints/testDbSource'
15+
import { RefreshInstance } from '@postgres.ai/shared/types/api/endpoints/refreshInstance'
1516
import { DestroyClone } from '@postgres.ai/shared/types/api/endpoints/destroyClone'
1617
import { ResetClone } from '@postgres.ai/shared/types/api/endpoints/resetClone'
1718
import { GetWSToken } from '@postgres.ai/shared/types/api/endpoints/getWSToken'
@@ -30,6 +31,7 @@ const UNSTABLE_CLONE_STATUS_CODES = ['CREATING', 'RESETTING', 'DELETING']
3031
export type Api = {
3132
getInstance: GetInstance
3233
getSnapshots: GetSnapshots
34+
refreshInstance?: RefreshInstance
3335
destroyClone: DestroyClone
3436
resetClone: ResetClone
3537
getWSToken: GetWSToken
@@ -82,6 +84,18 @@ export class MainStore {
8284
}
8385

8486
load = (instanceId: string) => {
87+
this.instance = null
88+
this.isReloadingInstance = true
89+
this.loadInstance(instanceId, false)
90+
this.loadInstanceRetrieval(instanceId).then(() => {
91+
if (this.instanceRetrieval) {
92+
this.getConfig()
93+
}
94+
})
95+
this.snapshots.load(instanceId)
96+
}
97+
98+
reload = (instanceId: string) => {
8599
this.instance = null
86100
this.isReloadingInstance = true
87101
this.loadInstance(instanceId)
@@ -120,10 +134,16 @@ export class MainStore {
120134
return !!response
121135
}
122136

123-
private loadInstance = async (instanceId: string) => {
137+
private loadInstance = async (
138+
instanceId: string,
139+
refresh: boolean = true,
140+
) => {
124141
this.instanceError = null
125142
this.isLoadingInstance = true
126143

144+
if (this.api.refreshInstance && refresh)
145+
await this.api.refreshInstance({ instanceId: instanceId })
146+
127147
const { response, error } = await this.api.getInstance({
128148
instanceId: instanceId,
129149
})

0 commit comments

Comments
(0)

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