Skip to content

Commit

Permalink
feat(salariesByLocation): show latest year in preview subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 9, 2024
1 parent d7965b4 commit 9473e23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions studio/lib/payloads/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export interface Benefit {
richText: PortableTextBlock[];
}

export interface SalariesPage {
_type: string;
_key: string;
year: number;
salaries: string;
}

export interface CompensationsPage {
_createdAt: string;
_id: string;
Expand Down
15 changes: 13 additions & 2 deletions studio/schemas/objects/compensations/salariesByLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "./utils/validation";
import { companyLocationNameID } from "../../documents/companyLocation";
import { SalariesInput } from "../../../components/salariesInput/SalariesInput";
import { SalariesPage } from "../../../lib/payloads/compensations";

export const salariesByLocation = defineField({
name: "salaries",
Expand Down Expand Up @@ -69,11 +70,21 @@ export const salariesByLocation = defineField({
preview: {
select: {
location: `${locationID}.${companyLocationNameID}`,
yearlySalaries: `yearlySalaries`,
},
prepare({ location }) {
prepare({ location, yearlySalaries }) {
const latestYear =
yearlySalaries && yearlySalaries.length > 0
? yearlySalaries.reduce((acc: number, salaries: SalariesPage) => {
if (salaries.year > acc) {
return salaries.year;
}
return acc;
}, yearlySalaries[0].year)
: undefined;
return {
title: location || "No location selected",
subtitle: "Location Salaries",
subtitle: latestYear ? `Latest year: ${latestYear}` : "N/A",
};
},
},
Expand Down

0 comments on commit 9473e23

Please sign in to comment.