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

Add new columns to perfile table #305 #332

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions app/kysely.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export interface Profiles {
firstName: string;
githubUser: string | null;
id: string;
isBillable: Generated<boolean>;
jobLevelTier: string | null;
jobLevelTitle: string | null;
jobTitleId: string | null;
Expand Down
2 changes: 2 additions & 0 deletions app/lake.server.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

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

have you tested these changes? You need to run

npm run migrate-profiles-lake

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function findProfileData(email: string) {
const query = `SELECT contact__wizeos_profile_id, contact__employee_number, contact__email,
contact__first_name, contact__preferred_name, contact__last_name,
contact__photo__url,
contact__is_billable,
contact__location, contact__country,
contact__status, contact__department, contact__business_unit,
contact__employee_status,
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function getActiveProfiles() {
const query = `SELECT contact__wizeos_profile_id, contact__employee_number, contact__email,
contact__first_name, contact__preferred_name, contact__last_name,
contact__photo__url,
contact__is_billable,
contact__location, contact__country,
contact__status, contact__department, contact__business_unit,
contact__employee_status,
Expand Down
41 changes: 40 additions & 1 deletion app/models/profile.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PrismaClient,
} from "@prisma/client";
import { Prisma } from "@prisma/client";
import { sql } from "kysely";
Copy link
Collaborator

Choose a reason for hiding this comment

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

none of these changes from lines 11 to 13 seem necessary. ESLint says we are importing but not using those names.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you revert line 11. It still shows this warning from ESLint

image

import { OrderByNode, sql } from "kysely";

Check failure on line 11 in app/models/profile.server.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

'OrderByNode' is defined but never used

interface UserProfile extends Profiles {
role: string;
Expand Down Expand Up @@ -95,6 +95,7 @@
jobLevelTitle: data.jobLevelTitle,
department: data.department,
businessUnit: data.businessUnit,
isBillable: data.isBillable,
location: data.location,
country: data.country,
employeeStatus: data.employeeStatus,
Expand Down Expand Up @@ -277,6 +278,7 @@
benchStatus?: string[];
employeeStatus?: string[];
skill?: string[];
isBillable?: boolean;
itemsPerPage: number;
}

Expand All @@ -294,6 +296,7 @@
benchStatus = [],
employeeStatus = [],
skill = [],
isBillable,
itemsPerPage = 50,
}: SearchProfilesFullInput) {
if (page < 1) page = 1;
Expand All @@ -304,6 +307,7 @@
};

if (department.length > 0) {
console.log("Hello world! "+department);
where = {
...where,
department: { in: department },
Expand Down Expand Up @@ -348,6 +352,14 @@
};
}

if (isBillable != undefined) {
where = {
...where,
isBillable: isBillable,

};
}

// Get ids
const profileIds = await prisma.profiles.findMany({
select: {
Expand All @@ -356,6 +368,8 @@
where,
});



const ids = profileIds.map((id) => id.id);
const count = ids.length;

Expand All @@ -377,6 +391,7 @@
preferredName: true,
benchStatus: true,
businessUnit: true,
isBillable: true,
employeeStatus: true,
githubUser: true,
projectMembers: {
Expand Down Expand Up @@ -502,6 +517,20 @@
}
});

const isBillables = await prisma.profiles.groupBy({
by : ["isBillable"],
where:{
id: {
in: ids,
},
},
orderBy: {
isBillable: "asc",
},
_count: {
isBillable: true
},
});
return {
profiles,
count,
Expand All @@ -510,6 +539,7 @@
employeeStatuses: convertCountResult(employeeStatuses, "employeeStatus"),
benchStatuses: convertCountResult(benchStatuses, "benchStatus"),
skills,
isBillables: convertBooleanToString(isBillables),
};
}

Expand All @@ -522,6 +552,15 @@
});
};

const convertBooleanToString = (countResult : any[]) => {
return countResult.map(item => ({
name: item.isBillable.toString(),
count: item._count.isBillable
}));
};



export async function searchProfiles(
searchTerm: string,
project: string | null = null,
Expand Down
3 changes: 2 additions & 1 deletion app/profileMigration.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function getMappedProfiles(): Promise<Prisma.ProfilesCreateInput[]> {
email: lakeProfile.contact__email,
firstName: lakeProfile.contact__first_name,
preferredName:
lakeProfile.contact__preferred_name || lakeProfile.contact__first_name,
lakeProfile.contact__preferred_name || lakeProfile.contact__first_name,
lastName: lakeProfile.contact__last_name,
department: lakeProfile.contact__department,
jobLevelTier: lakeProfile.contact__wizeos__level,
Expand All @@ -21,6 +21,7 @@ async function getMappedProfiles(): Promise<Prisma.ProfilesCreateInput[]> {
employeeStatus: lakeProfile.contact__employee_status,
benchStatus: lakeProfile.contact__status,
businessUnit: lakeProfile.contact__business_unit,
isBillable: lakeProfile.contact__is_billable,
};
});
return mappedProfiles;
Expand Down
18 changes: 17 additions & 1 deletion app/routes/profiles._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const FILTERS = [
"businessUnit",
"benchStatus",
"skill",
"isBillable",
];

interface LoaderData {
Expand All @@ -109,7 +110,10 @@ export const loader: LoaderFunction = async ({ request }) => {
const benchStatus = url.searchParams.getAll("benchStatus");
const employeeStatus = url.searchParams.getAll("employeeStatus");
const skill = url.searchParams.getAll("skill");


const isBillable = url.searchParams.get("isBillable") === null ?
undefined :
url.searchParams.get("isBillable") === "true";
const data = await searchProfilesFull({
searchTerm,
page,
Expand All @@ -118,6 +122,7 @@ export const loader: LoaderFunction = async ({ request }) => {
benchStatus,
employeeStatus,
skill,
isBillable,
itemsPerPage: ITEMS_PER_PAGE,
});

Expand Down Expand Up @@ -147,6 +152,7 @@ const Profiles = () => {
benchStatuses,
employeeStatuses,
skills,
isBillables,
},
} = useLoaderData() as unknown as LoaderData;
const theme = useTheme();
Expand Down Expand Up @@ -267,6 +273,13 @@ const Profiles = () => {
items={benchStatuses}
/>
) : null}
{isBillables.length > 0 ?(
<FilterAccordion
title="Is Billable"
filter="isBillable"
items={isBillables}
/>
) : null}
<FilterAccordion title="Skill" filter="skill" items={skills} />
</Paper>
</Grid>
Expand Down Expand Up @@ -365,6 +378,9 @@ const Profiles = () => {
<Typography sx={{ fontWeight: "bold" }}>
{item.employeeStatus}
</Typography>
<Typography sx={{ fontWeight: "bold" }}>
{item.isBillable}
</Typography>
{item.projectMembers.length > 0 ? (
<>
{item.projectMembers.map((projectMember, index) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Profiles" ADD COLUMN "isBillable" BOOLEAN NOT NULL DEFAULT true;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ model Profiles {
jobLevelTitle String?
department String?
businessUnit String?
isBillable Boolean @default(true)
// - null
// - Horizontal
// - Innovation
Expand Down
12 changes: 12 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ async function seed() {
department: "Engineering",
},
});
await db.profiles.upsert({
where: { email: "ramiro.cardona@in.wizeline.com" },
update: {},
create: {
email: "ramiro.cardona@in.wizeline.com",
firstName: "Ramiro",
preferredName: "Ramiro",
lastName: "Cardona",
department: "Engineering",
isBillable: false,
},
});
await db.profiles.upsert({
where: { email: "fernanda.vargas@wizeline.com" },
update: {},
Expand Down
Loading