Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 - feat: add employee list filters #884

Merged
merged 11 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"read_more": "Read more"
},
"employee_card": {
"show": "Show",
"of": "of",
"show": "Showing",
"of": "out of",
"consultants": "consultants"
}
}
2 changes: 1 addition & 1 deletion messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"read_more": "Les mer"
},
"employee_card": {
"show": "Vis",
"show": "Viser",
"of": "av",
"consultants": "konsulenter"
}
Expand Down
4 changes: 2 additions & 2 deletions messages/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"read_more": "Läs mer"
},
"employee_card": {
"show": "Visa",
"show": "Visar",
"of": "av",
"consultants": "konsulentar"
"consultants": "konsulter"
}
}
194 changes: 194 additions & 0 deletions src/components/sections/employees/EmployeeList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
"use client";

import { useTranslations } from "next-intl";
import { useState } from "react";

import Button from "src/components/buttons/Button";
import EmployeeCard from "src/components/employeeCard/EmployeeCard";
import Text from "src/components/text/Text";
import { ChewbaccaEmployee, Competence } from "src/types/employees";

import styles from "./employees.module.css";

const competences: Competence[] = [
"Utvikling",
"Administasjon",
"Design",
"Project Management",
];

function countCompetences(employees: ChewbaccaEmployee[]) {
const competenceCounts: Record<Competence, number> = {
Utvikling: 0,
Administasjon: 0,
Design: 0,
"Project Management": 0,
};

employees
.flatMap((e) => e.competences)
.forEach((c) => (competenceCounts[c] += 1));

return competenceCounts;
}

function countLocations(employees: ChewbaccaEmployee[]) {
const locationCounts: Record<string, number> = {};

employees
.flatMap((e) => e.officeName)
.filter((o) => !!o)
.forEach((o) =>
!locationCounts[o!]
? (locationCounts[o!] = 1)
: (locationCounts[o!] += 1),
);

return locationCounts;
}

export interface EmployeesProps {
employees: ChewbaccaEmployee[];
language: string;
employeesPageSlug: string;
}

interface EmployeeFilters {
competenceFilter: Competence | null;
locationFilter: string | null;
}

export default function EmployeeList({
employees,
language,
employeesPageSlug,
}: EmployeesProps) {
const competenceCounts = countCompetences(employees);
const locationCounts = countLocations(employees);
const locations = Object.keys(locationCounts);

const t = useTranslations("employee_card");

const [filteredEmployees, setFilteredEmployees] =
useState<ChewbaccaEmployee[]>(employees);

const [employeeFilters, setEmployeeFilters] = useState<EmployeeFilters>({
competenceFilter: null,
locationFilter: null,
});

function filterEmployees(newFilters: Partial<EmployeeFilters>) {
const combinedFilters = { ...employeeFilters, ...newFilters };
setEmployeeFilters(combinedFilters);

const newFilteredEmployees = employees.filter((e) => {
if (
combinedFilters.competenceFilter !== null &&
!e.competences.includes(combinedFilters.competenceFilter)
) {
return false;
}

if (
combinedFilters.locationFilter !== null &&
e.officeName !== combinedFilters.locationFilter
) {
return false;
}

return true;
});

setFilteredEmployees(newFilteredEmployees);
}

return (
<>
<div className={styles.employeeFiltersWrapper}>
<div className={styles.employeeFilterWrapper}>
<Text type="labelSemibold" className={styles.employeeFilterLabel}>
Fag
</Text>
<Button
size="small"
type={
employeeFilters.competenceFilter == null
? "secondaryFilled"
: "secondary"
}
onClick={() => filterEmployees({ competenceFilter: null })}
>
Alle
trulshj marked this conversation as resolved.
Show resolved Hide resolved
</Button>
{competences.map((competence) => {
const active = employeeFilters.competenceFilter == competence;
return (
<Button
size="small"
key={competence}
type={active ? "secondaryFilled" : "secondary"}
onClick={() =>
filterEmployees({ competenceFilter: competence })
}
>
{competence} ({competenceCounts[competence]})
</Button>
);
})}
</div>
<div className={styles.employeeFilterWrapper}>
<Text type="labelSemibold" className={styles.employeeFilterLabel}>
Lokasjon
trulshj marked this conversation as resolved.
Show resolved Hide resolved
</Text>
<Button
size="small"
type={
employeeFilters.locationFilter == null
? "secondaryFilled"
: "secondary"
}
onClick={() => filterEmployees({ locationFilter: null })}
>
Alle
</Button>
{locations.map((location) => {
const active = employeeFilters.locationFilter == location;
return (
<Button
size="small"
key={location}
type={active ? "secondaryFilled" : "secondary"}
onClick={() => filterEmployees({ locationFilter: location })}
>
{location} ({locationCounts[location]})
</Button>
);
})}
</div>
</div>

<div className={styles.employeeCountWrapper}>
<div style={{ display: "flex" }}></div>

<p className={styles.employeeCount}>
{t("show")}{" "}
<span className={styles.employeeCountValue}>{employees.length}</span>{" "}
{t("of")}{" "}
<span className={styles.employeeCountValue}>{employees.length}</span>{" "}
{t("consultants")}
</p>
</div>

<div className={styles.peopleContainer}>
{filteredEmployees.map((employee) => (
<EmployeeCard
employee={employee}
employeePageSlug={employeesPageSlug}
language={language}
key={employee.name}
/>
))}
</div>
</>
);
}
29 changes: 6 additions & 23 deletions src/components/sections/employees/Employees.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { headers } from "next/headers";
import { getTranslations } from "next-intl/server";

import EmployeeCard from "src/components/employeeCard/EmployeeCard";
import {
domainFromEmail,
fetchAllChewbaccaEmployees,
Expand All @@ -11,14 +9,14 @@ import { EmployeesSection } from "studio/lib/interfaces/pages";
import { EMPLOYEE_PAGE_SLUG_QUERY } from "studio/lib/queries/siteSettings";
import { loadStudioQuery } from "studio/lib/store";

import EmployeeList from "./EmployeeList";
import styles from "./employees.module.css";
export interface EmployeesProps {
language: string;
section: EmployeesSection;
}

export default async function Employees({ language, section }: EmployeesProps) {
const t = await getTranslations("employee_card");
const employeesPageRes = await loadStudioQuery<{ slug: string }>(
EMPLOYEE_PAGE_SLUG_QUERY,
{
Expand All @@ -39,31 +37,16 @@ export default async function Employees({ language, section }: EmployeesProps) {
(employee) =>
employee.email != null && domainFromEmail(employee.email) === domain,
);
const total = employees.length;

return (
<div className={styles.wrapper}>
<div className={styles.employees}>
<h1 className={styles.header}>{section.basicTitle}</h1>
<div className={styles.employeeCountWrapper}>
<p className={styles.employeeCount}>
{t("show")}
<span className={styles.employeeCountValue}>{total}</span>
{t("of")}
<span className={styles.employeeCountValue}>{total}</span>{" "}
{t("consultants")}
</p>
</div>
<div className={styles.peopleContainer}>
{employees.map((employee) => (
<EmployeeCard
employee={employee}
employeePageSlug={employeesPageSlug}
language={language}
key={employee.name}
/>
))}
</div>
<EmployeeList
employees={employees}
employeesPageSlug={employeesPageSlug}
language={language}
/>
</div>
</div>
);
Expand Down
21 changes: 21 additions & 0 deletions src/components/sections/employees/employees.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
align-self: flex-start;
}

.employeeFiltersWrapper {
padding: 1.5rem 0;
align-self: flex-start;
display: flex;
flex-direction: column;
gap: 0.75rem;
}

.employeeFilterWrapper {
flex-wrap: wrap;
display: flex;
align-items: center;
gap: 0.75rem;
}

.employeeFilterLabel {
flex-shrink: 0;
min-width: 4.5rem;
width: 4.5rem;
}

.employeeCountWrapper {
width: 100%;
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const elementMap: { [key in TextType]: keyof JSX.IntrinsicElements } = {
h6: "h6",
desktopLink: "p",
desktopLinkBig: "p",
labelSmall: "p",
labelLight: "p",
labelRegular: "p",
labelSemibold: "p",
labelBold: "p",
labelSmall: "span",
labelLight: "span",
labelRegular: "span",
labelSemibold: "span",
labelBold: "span",
quoteItalic: "p",
quoteNormal: "p",
bodyExtraSmall: "p",
Expand Down
7 changes: 7 additions & 0 deletions src/components/text/text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@
line-height: 120%;
}

.labelBold {
font-size: 1rem;
font-style: normal;
font-weight: 800;
line-height: 120%;
}

.quoteNormal {
font-size: 1.5rem;
font-style: normal;
Expand Down
8 changes: 7 additions & 1 deletion src/types/employees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export function isChewbaccaEmployeesResponse(
);
}

export type Competence =
| "Project Management"
| "Design"
| "Utvikling"
| "Administasjon";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should utvikling and administrasjon be replaced with english terms?

Copy link
Contributor

@anemne anemne Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The language should ideally match the selected lang: Norwegian for "no," English for "en," and Swedish for "se"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disse er det som kommer fra Chewbacca, kan brukes som nøkler i oversetting


export interface ChewbaccaEmployee {
email?: string | null;
name?: string | null;
Expand All @@ -24,7 +30,7 @@ export interface ChewbaccaEmployee {
imageThumbUrl?: string | null;
officeName?: string | null;
startDate?: string | null;
competences: string[];
competences: Competence[];
}

export function isChewbaccaEmployee(
Expand Down