-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad1edeb
commit 4fec016
Showing
16 changed files
with
389 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/lib/components/custom/stats/countPerDepartment.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<script lang="ts"> | ||
import Separator from '$lib/components/ui/separator/separator.svelte'; | ||
import type { PersonType } from '$lib/types/person'; | ||
let { | ||
personsCount | ||
}: { | ||
personsCount: { | ||
type: PersonType; | ||
department: string; | ||
count: number; | ||
}[]; | ||
} = $props(); | ||
const allTypes = $derived( | ||
personsCount | ||
.filter((item, index, self) => self.findIndex((other) => other.type === item.type) === index) | ||
.map((d) => ({ | ||
type: d.type, | ||
count: 0 | ||
})) | ||
.sort((t1, t2) => t1.type.localeCompare(t2.type)) | ||
); | ||
const departments = $derived.by(() => { | ||
const dataMap = personsCount.reduce( | ||
(acc, { department, type, count }) => { | ||
if (!acc[department]) acc[department] = {} as Record<PersonType, number>; | ||
if (type !== null) acc[department][type] = count; | ||
return acc; | ||
}, | ||
{} as Record<string, Record<PersonType, number>> | ||
); | ||
return Object.entries(dataMap) | ||
.map(([department, types]) => ({ | ||
department, | ||
types: [ | ||
...Object.entries(types).map(([type, count]) => ({ | ||
type: type as PersonType, | ||
count | ||
})), | ||
...allTypes | ||
] | ||
.filter( | ||
(item, index, self) => self.findIndex((other) => other.type === item.type) === index | ||
) | ||
.sort((t1, t2) => t1.type.localeCompare(t2.type)) | ||
})) | ||
.sort((d1, d2) => d1.department.localeCompare(d2.department)); | ||
}); | ||
const totalCountPerType = $derived( | ||
departments | ||
.flatMap((d) => d.types) | ||
.reduce( | ||
(acc, curr) => { | ||
const existingType = acc.find((item) => item.type === curr.type); | ||
if (!existingType) { | ||
return [...acc, curr]; | ||
} | ||
existingType.count += curr.count; | ||
return acc; | ||
}, | ||
[] as { | ||
type: PersonType; | ||
count: number; | ||
}[] | ||
) | ||
.sort((t1, t2) => t1.type.localeCompare(t2.type)) | ||
); | ||
</script> | ||
|
||
<table class="w-full"> | ||
<thead> | ||
<tr> | ||
<th class="w-1/3">Department</th> | ||
{#each allTypes as { type }} | ||
<th class="w-1/3">{type}</th> | ||
{/each} | ||
</tr> | ||
</thead> | ||
<tbody class="text-center"> | ||
{#each departments as { department, types }} | ||
<tr> | ||
<td>{department}</td> | ||
{#each types as { count }} | ||
<td>{count}</td> | ||
{/each} | ||
</tr> | ||
{/each} | ||
</tbody> | ||
</table> | ||
|
||
<Separator class="my-3" /> | ||
|
||
<table class="w-full"> | ||
<thead> | ||
<tr> | ||
<th class="w-1/3">Type</th> | ||
<th class="w-1/3">Total</th> | ||
</tr> | ||
</thead> | ||
<tbody class="text-center"> | ||
{#each totalCountPerType as { type, count }} | ||
<tr> | ||
<td>{type}</td> | ||
<td>{count}</td> | ||
</tr> | ||
{/each} | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Tabs as TabsPrimitive } from 'bits-ui'; | ||
import Content from './tabs-content.svelte'; | ||
import List from './tabs-list.svelte'; | ||
import Trigger from './tabs-trigger.svelte'; | ||
|
||
const Root = TabsPrimitive.Root; | ||
|
||
export { | ||
Root, | ||
Content, | ||
List, | ||
Trigger, | ||
// | ||
Root as Tabs, | ||
Content as TabsContent, | ||
List as TabsList, | ||
Trigger as TabsTrigger | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script lang="ts"> | ||
import { Tabs as TabsPrimitive } from 'bits-ui'; | ||
import { cn } from '$lib/utils.js'; | ||
let { | ||
ref = $bindable(null), | ||
class: className, | ||
...restProps | ||
}: TabsPrimitive.ContentProps = $props(); | ||
</script> | ||
|
||
<TabsPrimitive.Content | ||
bind:ref | ||
class={cn( | ||
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2', | ||
className | ||
)} | ||
{...restProps} | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script lang="ts"> | ||
import { Tabs as TabsPrimitive } from 'bits-ui'; | ||
import { cn } from '$lib/utils.js'; | ||
let { ref = $bindable(null), class: className, ...restProps }: TabsPrimitive.ListProps = $props(); | ||
</script> | ||
|
||
<TabsPrimitive.List | ||
bind:ref | ||
class={cn( | ||
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground', | ||
className | ||
)} | ||
{...restProps} | ||
/> |
Oops, something went wrong.