Skip to content

Commit c85f926

Browse files
committed
Merge branch '589-white-screen-when-opening-the-clone-creation-page' into 'dle-4-0'
fix(ui): "white screen” when opening the clone creation page See merge request postgres-ai/database-lab!966
2 parents 4571bc2 + 0cc2968 commit c85f926

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
*/
77

88
import { request } from 'helpers/request'
9+
import {
10+
SnapshotDto,
11+
formatSnapshotDto,
12+
} from '@postgres.ai/shared/types/api/entities/snapshot'
13+
import { GetBranchSnapshots } from '@postgres.ai/shared/types/api/endpoints/getBranchSnapshots'
914

10-
export const getBranchSnapshots = async (branch: string) => {
15+
export const getBranchSnapshots: GetBranchSnapshots = async (
16+
branch: string,
17+
) => {
1118
const response = await request(`/branch/snapshots/${branch}`)
1219

1320
return {
14-
response: response.ok ? await response.json() : null,
21+
response: response.ok
22+
? ((await response.json()) as SnapshotDto[]).map(formatSnapshotDto)
23+
: null,
1524
error: response.ok ? null : response,
1625
}
1726
}

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const CreateClone = observer((props: Props) => {
4949
const timer = useTimer()
5050
const [branchesList, setBranchesList] = useState<string[]>([])
5151
const [snapshots, setSnapshots] = useState([] as Snapshot[])
52+
const [isLoadingSnapshots, setIsLoadingSnapshots] = useState(false)
5253

5354
// Form.
5455
const onSubmit = async (values: FormValues) => {
@@ -94,6 +95,7 @@ export const CreateClone = observer((props: Props) => {
9495

9596
const fetchData = async () => {
9697
try {
98+
setIsLoadingSnapshots(true)
9799
await stores.main.load(props.instanceId)
98100

99101
const branches = (await stores.main.getBranches()) ?? []
@@ -105,12 +107,15 @@ export const CreateClone = observer((props: Props) => {
105107
await fetchBranchSnapshotsData(initiallySelectedBranch)
106108
} else {
107109
const allSnapshots = stores.main?.snapshots?.data ?? []
108-
setSnapshots(allSnapshots)
110+
const sortedSnapshots = allSnapshots.slice().sort(compareSnapshotsDesc)
111+
setSnapshots(sortedSnapshots)
109112
const [firstSnapshot] = allSnapshots ?? []
110113
formik.setFieldValue('snapshotId', firstSnapshot?.id)
111114
}
112115
} catch (error) {
113116
console.error('Error fetching data:', error)
117+
} finally {
118+
setIsLoadingSnapshots(false)
114119
}
115120
}
116121

@@ -136,7 +141,7 @@ export const CreateClone = observer((props: Props) => {
136141
)
137142

138143
// Initial loading spinner.
139-
if (!stores.main.instance)
144+
if (!stores.main.instance || isLoadingSnapshots)
140145
return (
141146
<>
142147
{headRendered}
@@ -217,23 +222,20 @@ export const CreateClone = observer((props: Props) => {
217222
}
218223
error={Boolean(formik.errors.snapshotId)}
219224
items={
220-
snapshots
221-
.slice()
222-
.sort(compareSnapshotsDesc)
223-
.map((snapshot, i) => {
224-
const isLatest = i === 0
225-
return {
226-
value: snapshot.id,
227-
children: (
228-
<>
229-
{snapshot.dataStateAt}
230-
{isLatest && (
231-
<span className={styles.snapshotTag}>Latest</span>
232-
)}
233-
</>
234-
),
235-
}
236-
}) ?? []
225+
snapshots.map((snapshot, i) => {
226+
const isLatest = i === 0
227+
return {
228+
value: snapshot.id,
229+
children: (
230+
<>
231+
{snapshot.dataStateAt}
232+
{isLatest && (
233+
<span className={styles.snapshotTag}>Latest</span>
234+
)}
235+
</>
236+
),
237+
}
238+
}) ?? []
237239
}
238240
/>
239241

ui/packages/shared/utils/snapshot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const compareSnapshotsDesc = (
22
a: { dataStateAtDate: Date },
33
b: { dataStateAtDate: Date },
44
): number => {
5-
const { dataStateAtDate: dateA } = a
6-
const { dataStateAtDate: dateB } = b
7-
return dateB.getTime() - dateA.getTime()
5+
const dataStateAtDateA = a.dataStateAtDate?.getTime() ?? 0
6+
const dataStateAtDateB = b.dataStateAtDate?.getTime() ?? 0
7+
return dataStateAtDateB - dataStateAtDateA
88
}

0 commit comments

Comments
 (0)