mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
correct percentage for import migrationbox
This commit is contained in:
1 parent
9c8b88e70f
commit
c82d36321b
2 files changed
+37
-28
No files matched your search
@@ -5,6 +5,7 @@
|
||||
import { realtime } from '$lib/stores/sdk';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
import { onMount } from 'svelte';
|
||||
import { calculatePercentage, type Counter } from '$lib/helpers/migration';
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const showMigrationBox = writable(false);
|
||||
@@ -12,19 +13,6 @@
|
||||
|
||||
<script lang="ts">
|
||||
let migration: Models.Migration;
|
||||
type Counter = {
|
||||
pending: number;
|
||||
error: number;
|
||||
success: number;
|
||||
processing: number;
|
||||
skip: number;
|
||||
warning: number;
|
||||
};
|
||||
|
||||
type TotalCounter = {
|
||||
done: number;
|
||||
processing: number;
|
||||
};
|
||||
|
||||
$: percentage = (function getPercentage() {
|
||||
if (!migration) return 0;
|
||||
@@ -32,21 +20,7 @@
|
||||
if (migration.status === 'completed') return 100;
|
||||
|
||||
const statusCounters = parseIfString(migration.statusCounters) as Record<string, Counter>;
|
||||
const totalCounter: TotalCounter = Object.values(statusCounters).reduce(
|
||||
(curr, acc) => {
|
||||
return {
|
||||
done: curr.done + acc.success + acc.error + acc.skip + acc.warning,
|
||||
processing: curr.processing + acc.processing + acc.pending
|
||||
};
|
||||
},
|
||||
{ done: 0, processing: 0 } as TotalCounter
|
||||
);
|
||||
|
||||
const res = Math.round(
|
||||
(totalCounter.done / (totalCounter.done + totalCounter.processing)) * 100
|
||||
);
|
||||
|
||||
return Number.isNaN(res) ? 0 : res;
|
||||
return calculatePercentage(statusCounters);
|
||||
})();
|
||||
|
||||
onMount(() => {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
export type Counter = {
|
||||
pending: number;
|
||||
error: number;
|
||||
success: number;
|
||||
processing: number;
|
||||
skip: number;
|
||||
warning: number;
|
||||
};
|
||||
|
||||
type TotalCounter = {
|
||||
done: number;
|
||||
processing: number;
|
||||
};
|
||||
|
||||
export function calculatePercentage(statusCounters: Record<string, Counter>): number {
|
||||
const totalCounter: TotalCounter = Object.values(statusCounters).reduce(
|
||||
(curr, acc) => {
|
||||
return {
|
||||
done: curr.done + acc.success + acc.error + acc.skip + acc.warning,
|
||||
processing: curr.processing + Math.max(0, acc.processing) + Math.max(0, acc.pending)
|
||||
};
|
||||
},
|
||||
{ done: 0, processing: 0 } as TotalCounter
|
||||
);
|
||||
|
||||
const res = Math.round(
|
||||
(totalCounter.done / (totalCounter.done + totalCounter.processing)) * 100
|
||||
);
|
||||
|
||||
if (Number.isNaN(res)) return 0;
|
||||
if (res > 100) return 100;
|
||||
if (res < 0) return 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in new issue
Block a user