Skip to content

Commit

Permalink
Refactor overage table calculation to use $effect and untrack for imp…
Browse files Browse the repository at this point in the history
…roved reactivity in utilization page

Co-authored-by: frodesundby <frode.sundby@nav.no>
  • Loading branch information
rbjornstad and frodesundby committed Dec 12, 2024
1 parent d8f2482 commit a0c6d47
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/routes/utilization/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts">
import { run } from 'svelte/legacy';
import { goto } from '$app/navigation';
import { UtilizationResourceType, type TenantUtilization$result } from '$houdini';
import Card from '$lib/Card.svelte';
Expand Down Expand Up @@ -31,6 +29,7 @@
import bytes from 'bytes-iec';
import type { EChartsOption } from 'echarts';
import prettyBytes from 'pretty-bytes';
import { untrack } from 'svelte';
import type { PageData } from './$houdini';
interface Props {
Expand Down Expand Up @@ -212,12 +211,14 @@
let { TenantUtilization } = $derived(data);
let resourceUtilization = $derived(mergeAll($TenantUtilization.data));
let overageTable: TeamsOverageData[] = $state([]);
run(() => {
overageTable = mergeCalculateAndSortOverageDataAllTeams(
resourceUtilization,
sortState.orderBy,
sortState.direction
);
$effect(() => {
untrack(() => {
overageTable = mergeCalculateAndSortOverageDataAllTeams(
resourceUtilization,
sortState.orderBy,
sortState.direction
);
});
});
</script>

Expand Down Expand Up @@ -404,19 +405,21 @@
{overage.team}
</a>
</Td>
<Td
>{overage.unusedCpu.toLocaleString('en-GB', {
<Td>
{overage.unusedCpu.toLocaleString('en-GB', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
})}</Td
>
})}
</Td>
<Td>{prettyBytes(overage.unusedMem)}</Td>
<Td>
<Cost cost={overage.estimatedAnnualOverageCost} />
</Td>
</Tr>
{:else}
<p>No overage data for tenant.</p>
<Tr>
<Td colspan={999}>No overage data for tenant.</Td>
</Tr>
{/each}
</Tbody>
</Table>
Expand Down

0 comments on commit a0c6d47

Please sign in to comment.