Skip to content

Commit c8acb97

Browse files
committed
Merge branch 'dle-4-0-bug-fixing' into 'dle-4-0'
fix(ui): DBLab Engine 4 UI fixes See merge request postgres-ai/database-lab!987
2 parents 4e14476 + 7d9be82 commit c8acb97

File tree

10 files changed

+54
-72
lines changed

10 files changed

+54
-72
lines changed

ui/packages/ce/src/App/Instance/Branches/CreateBranch/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getBranches } from 'api/branches/getBranches'
22
import { createBranch } from 'api/branches/createBranch'
3-
import { getBranchSnapshots } from 'api/snapshots/getBranchSnapshots'
3+
import { getSnapshots } from 'api/snapshots/getSnapshots'
44

55
import { CreateBranchPage } from '@postgres.ai/shared/pages/CreateBranch'
66

@@ -12,7 +12,7 @@ export const CreateBranch = () => {
1212
const api = {
1313
getBranches,
1414
createBranch,
15-
getBranchSnapshots,
15+
getSnapshots,
1616
}
1717

1818
const elements = {
@@ -29,7 +29,7 @@ export const CreateBranch = () => {
2929

3030
return (
3131
<PageContainer>
32-
<CreateBranchPage api={api} elements={elements} />
32+
<CreateBranchPage instanceId={''} api={api} elements={elements} />
3333
</PageContainer>
3434
)
3535
}

ui/packages/ce/src/App/Instance/Clones/CreateClone/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getInstanceRetrieval } from 'api/instances/getInstanceRetrieval'
88
import { createClone } from 'api/clones/createClone'
99
import { getClone } from 'api/clones/getClone'
1010
import { getBranches } from 'api/branches/getBranches'
11-
import { getBranchSnapshots } from 'api/snapshots/getBranchSnapshots'
11+
import { getSnapshots } from 'api/snapshots/getSnapshots'
1212

1313
export const CreateClone = () => {
1414
const routes = {
@@ -22,7 +22,7 @@ export const CreateClone = () => {
2222
createClone,
2323
getClone,
2424
getBranches,
25-
getBranchSnapshots,
25+
getSnapshots,
2626
}
2727

2828
const elements = {

ui/packages/ce/src/api/snapshots/getBranchSnapshots.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

ui/packages/shared/pages/CreateBranch/index.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { getCliBranchListCommand, getCliCreateBranchCommand } from './utils'
2828
import { Snapshot } from 'types/api/entities/snapshot'
2929

3030
interface CreateBranchProps {
31+
instanceId: string
3132
api: MainStoreApi
3233
elements: {
3334
breadcrumbs: React.ReactNode
@@ -91,7 +92,7 @@ const useStyles = makeStyles(
9192
)
9293

9394
export const CreateBranchPage = observer(
94-
({ api, elements }: CreateBranchProps) => {
95+
({ instanceId, api, elements }: CreateBranchProps) => {
9596
const stores = useCreatedStores(api)
9697
const classes = useStyles()
9798
const history = useHistory()
@@ -105,8 +106,8 @@ export const CreateBranchPage = observer(
105106
createBranchError,
106107
isBranchesLoading,
107108
isCreatingBranch,
108-
getBranchSnapshots,
109-
branchSnapshotsError,
109+
getSnapshots,
110+
snapshotsError,
110111
} = stores.main
111112

112113
const handleSubmit = async (values: CreateBranchFormValues) => {
@@ -117,23 +118,28 @@ export const CreateBranchPage = observer(
117118
})
118119
}
119120

120-
const handleParentBranchChange = async (
121-
e: React.ChangeEvent<HTMLInputElement>,
122-
) => {
123-
const branchName = e.target.value
124-
formik.setFieldValue('baseBranch', branchName)
125-
await getBranchSnapshots(branchName).then((response) => {
121+
const fetchSnapshots = async (branchName: string) => {
122+
await getSnapshots(instanceId, branchName).then((response) => {
126123
if (response) {
127124
setBranchSnapshots(response)
128125
formik.setFieldValue('snapshotID', response[0]?.id)
129126
}
130127
})
131128
}
132129

130+
const handleParentBranchChange = async (
131+
e: React.ChangeEvent<HTMLInputElement>,
132+
) => {
133+
const branchName = e.target.value
134+
formik.setFieldValue('baseBranch', branchName)
135+
await fetchSnapshots(branchName)
136+
}
137+
133138
const [{ formik }] = useForm(handleSubmit)
134139

135140
useEffect(() => {
136141
load()
142+
fetchSnapshots(formik.values.baseBranch)
137143
}, [formik.values.baseBranch])
138144

139145
if (isBranchesLoading) {
@@ -146,12 +152,10 @@ export const CreateBranchPage = observer(
146152
<div className={classes.wrapper}>
147153
<div className={classes.container}>
148154
<SectionTitle tag="h1" level={1} text="Create branch" />
149-
{(branchSnapshotsError || getBranchesError) && (
155+
{(snapshotsError || getBranchesError) && (
150156
<div className={classes.marginTop}>
151157
<ErrorStub
152-
message={
153-
branchSnapshotsError?.message || getBranchesError?.message
154-
}
158+
message={snapshotsError?.message || getBranchesError?.message}
155159
/>
156160
</div>
157161
)}

ui/packages/shared/pages/CreateBranch/stores/Main.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
CreateBranchFormValues,
1414
} from '@postgres.ai/shared/types/api/endpoints/createBranch'
1515
import { Branch } from '@postgres.ai/shared/types/api/endpoints/getBranches'
16-
import { GetBranchSnapshots } from 'types/api/endpoints/getBranchSnapshots'
16+
import { GetSnapshots } from 'types/api/endpoints/getSnapshots'
1717

1818
type Error = {
1919
title?: string
@@ -23,11 +23,11 @@ type Error = {
2323
export type MainStoreApi = {
2424
getBranches: GetBranches
2525
createBranch: CreateBranch
26-
getBranchSnapshots: GetBranchSnapshots
26+
getSnapshots: GetSnapshots
2727
}
2828

2929
export class MainStore {
30-
branchSnapshotsError: Error | null = null
30+
snapshotsError: Error | null = null
3131
getBranchesError: Error | null = null
3232
createBranchError: Error | null = null
3333

@@ -78,13 +78,16 @@ export class MainStore {
7878
return response
7979
}
8080

81-
getBranchSnapshots = async (branchName: string) => {
82-
if (!this.api.getBranchSnapshots) return
81+
getSnapshots = async (instanceId: string, branchName?: string) => {
82+
if (!this.api.getSnapshots) return
8383

84-
const { response, error } = await this.api.getBranchSnapshots(branchName)
84+
const { response, error } = await this.api.getSnapshots({
85+
instanceId,
86+
branchName,
87+
})
8588

8689
if (error) {
87-
this.branchSnapshotsError = await error.json().then((err) => err)
90+
this.snapshotsError = await error.json().then((err) => err)
8891
}
8992

9093
return response

ui/packages/shared/pages/CreateClone/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const CreateClone = observer((props: Props) => {
7575

7676
const fetchBranchSnapshotsData = async (branchName: string) => {
7777
const snapshotsRes =
78-
(await stores.main.getBranchSnapshots(branchName)) ?? []
78+
(await stores.main.getSnapshots(props.instanceId, branchName)) ?? []
7979
setSnapshots(snapshotsRes)
8080
formik.setFieldValue('snapshotId', snapshotsRes[0]?.id)
8181
}
@@ -86,7 +86,7 @@ export const CreateClone = observer((props: Props) => {
8686
const selectedBranch = e.target.value
8787
formik.setFieldValue('branch', selectedBranch)
8888

89-
if (props.api.getBranchSnapshots) {
89+
if (props.api.getSnapshots) {
9090
await fetchBranchSnapshotsData(selectedBranch)
9191
}
9292
}
@@ -103,7 +103,7 @@ export const CreateClone = observer((props: Props) => {
103103
setBranchesList(branches.map((branch) => branch.name))
104104
formik.setFieldValue('branch', initiallySelectedBranch)
105105

106-
if (props.api.getBranchSnapshots) {
106+
if (props.api.getSnapshots) {
107107
await fetchBranchSnapshotsData(initiallySelectedBranch)
108108
} else {
109109
const allSnapshots = stores.main?.snapshots?.data ?? []
@@ -154,7 +154,7 @@ export const CreateClone = observer((props: Props) => {
154154
if (
155155
stores.main.instanceError ||
156156
stores.main.getBranchesError ||
157-
stores.main.getBranchSnapshotsError ||
157+
stores.main.getSnapshotsError ||
158158
stores.main?.snapshots?.error
159159
)
160160
return (
@@ -165,7 +165,7 @@ export const CreateClone = observer((props: Props) => {
165165
message={
166166
stores.main.instanceError ||
167167
stores.main.getBranchesError?.message ||
168-
stores.main.getBranchSnapshotsError?.message ||
168+
stores.main.getSnapshotsError?.message ||
169169
(stores.main?.snapshots?.error as string)
170170
}
171171
/>

ui/packages/shared/pages/CreateClone/stores/Main.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GetInstance } from '@postgres.ai/shared/types/api/endpoints/getInstance
66
import { CreateClone } from '@postgres.ai/shared/types/api/endpoints/createClone'
77
import { GetClone } from '@postgres.ai/shared/types/api/endpoints/getClone'
88
import { GetBranches } from '@postgres.ai/shared/types/api/endpoints/getBranches'
9-
import { GetBranchSnapshots } from '@postgres.ai/shared/types/api/endpoints/getBranchSnapshots'
9+
import { GetSnapshots } from '@postgres.ai/shared/types/api/endpoints/getSnapshots'
1010
import {
1111
SnapshotsStore,
1212
SnapshotsApi,
@@ -23,14 +23,14 @@ export type MainStoreApi = SnapshotsApi & {
2323
createClone: CreateClone
2424
getClone: GetClone
2525
getBranches?: GetBranches
26-
getBranchSnapshots?: GetBranchSnapshots
26+
getSnapshots?: GetSnapshots
2727
}
2828

2929
export class MainStore {
3030
instance: Instance | null = null
3131
instanceError: string | null = null
3232
getBranchesError: Error | null = null
33-
getBranchSnapshotsError: Error | null = null
33+
getSnapshotsError: Error | null = null
3434

3535
clone: Clone | null = null
3636
cloneError: string | null = null
@@ -45,7 +45,7 @@ export class MainStore {
4545
makeAutoObservable(this)
4646

4747
this.api = api
48-
if (!api.getBranchSnapshots) {
48+
if (!api.getSnapshots) {
4949
this.snapshots = new SnapshotsStore(api)
5050
}
5151
}
@@ -100,12 +100,14 @@ export class MainStore {
100100
return response
101101
}
102102

103-
getBranchSnapshots = async (branchId: string) => {
104-
if (!this.api.getBranchSnapshots) return
105-
const { response, error } = await this.api.getBranchSnapshots(branchId)
103+
getSnapshots = async (instanceId: string, branchName?: string) => {
104+
if (!this.api.getSnapshots) return
105+
const { response, error } = await this.api.getSnapshots({
106+
instanceId,
107+
branchName,
108+
})
106109

107-
if (error)
108-
this.getBranchSnapshotsError = await error.json().then((err) => err)
110+
if (error) this.getSnapshotsError = await error.json().then((err) => err)
109111

110112
return response
111113
}

ui/packages/shared/pages/Instance/Snapshots/components/SnapshotsList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const SnapshotListItem = ({
134134
<div className={classes.commitItem}>
135135
<div className={classes.gridContainer}>
136136
<div className={classes.infoBlock}>
137-
<div className={classes.header}>{snapshot.message}</div>
137+
<div className={classes.header}>{snapshot.message || '-'}</div>
138138
<div className={classes.infoContent} title={snapshot.dataStateAt}>
139139
{timeAgo} ago
140140
</div>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ export const Snapshots = observer(() => {
5858
const filteredSnapshots = useMemo(() => {
5959
if (!snapshots.data) return []
6060

61+
if (!messageFilter.trim()) {
62+
return snapshots.data
63+
}
64+
6165
return snapshots.data.filter((snapshot) =>
62-
snapshot.message.toLowerCase().includes(messageFilter.toLowerCase()),
66+
snapshot?.message?.toLowerCase()?.includes(messageFilter.toLowerCase()),
6367
)
6468
}, [snapshots.data, messageFilter])
6569

ui/packages/shared/types/api/endpoints/getBranchSnapshots.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)