Skip to content

Commit

Permalink
Merge pull request #5 from ElemarJR/fix_yearn_lint_bugs
Browse files Browse the repository at this point in the history
Refactor type handling in various components
  • Loading branch information
ElemarJR authored Oct 21, 2024
2 parents a794a7a + 212383f commit 0fefd5b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 33 deletions.
24 changes: 12 additions & 12 deletions frontend/src/app/about-us/cases/CaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const CaseCard: React.FC<CaseCardProps> = ({ caseItem, caseData }) => {
}
};

const getStatusColor = (status: string) => {
const statusColor: { [key: string]: string } = {
"Critical": "rose",
"Requires attention": "amber",
"All right": "lime"
};
return statusColor[status] || "zinc";
const getStatusColor = (status: string): "zinc" | "rose" | "amber" | "lime" => {
switch (status) {
case "Critical": return "rose";
case "Requires attention": return "amber";
case "All right": return "lime";
default: return "zinc";
}
};

const formatDate = (dateString: string) => {
Expand Down Expand Up @@ -121,12 +121,12 @@ export const CaseCard: React.FC<CaseCardProps> = ({ caseItem, caseData }) => {
date.setDate(date.getDate() - date.getDay() - 7 * (6 - i));
return date.toLocaleDateString('pt-BR', { day: '2-digit', month: '2-digit' });
}), 'AVG'].map((date, index) => {
const weekData = index < 6 ? caseData.byWeek.find(week => week.week.startsWith(date)) : null;
const weekData = index < 6 ? caseData.byWeek.find((week: { week: string; }) => week.week.startsWith(date)) : null;
const averageData = index === 6 ? {
totalConsultingHours: caseData.byWeek.reduce((sum, week) => sum + week.totalConsultingHours, 0) / 6,
totalHandsOnHours: caseData.byWeek.reduce((sum, week) => sum + week.totalHandsOnHours, 0) / 6,
totalSquadHours: caseData.byWeek.reduce((sum, week) => sum + week.totalSquadHours, 0) / 6,
totalInternalHours: caseData.byWeek.reduce((sum, week) => sum + week.totalInternalHours, 0) / 6
totalConsultingHours: caseData.byWeek.reduce((sum: any, week: { totalConsultingHours: any; }) => sum + week.totalConsultingHours, 0) / 6,
totalHandsOnHours: caseData.byWeek.reduce((sum: any, week: { totalHandsOnHours: any; }) => sum + week.totalHandsOnHours, 0) / 6,
totalSquadHours: caseData.byWeek.reduce((sum: any, week: { totalSquadHours: any; }) => sum + week.totalSquadHours, 0) / 6,
totalInternalHours: caseData.byWeek.reduce((sum: any, week: { totalInternalHours: any; }) => sum + week.totalInternalHours, 0) / 6
} : null;
const data = index < 6 ? weekData : averageData;
return (
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/app/about-us/products-or-services/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { Heading } from "@/components/catalyst/heading";
import { gql, useQuery } from "@apollo/client";
import { gql, HttpLink, useQuery } from "@apollo/client";
import Image from "next/image";
import Link from "next/link";
import { useState } from "react";
Expand Down Expand Up @@ -55,9 +55,8 @@ export default function ProductsOrServices() {

if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;

const queryString = print(GET_OFFERS_AND_TIMESHEET);
const GRAPHQL_ENDPOINT = (client.link.options as any).uri;
const GRAPHQL_ENDPOINT = client.link instanceof HttpLink ? client.link.options.uri : undefined;

const handleStatClick = (statName: string) => {
setSelectedStat(statName);
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/app/analytics/datasets/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ export default function Datasets() {
const updateQueryString = (newSelectedValues: SelectValue[]) => {
const params = new URLSearchParams();
const uniqueFilters: Record<string, Set<string>> = {};

newSelectedValues.forEach(value => {
if (typeof value.value === 'string') {
if (value && 'value' in value && typeof value.value === 'string') {
const [field, fieldValue] = value.value.split(':');
if (!uniqueFilters[field]) {
uniqueFilters[field] = new Set();
if (field && fieldValue) {
if (!uniqueFilters[field]) {
uniqueFilters[field] = new Set();
}
uniqueFilters[field].add(fieldValue);
}
uniqueFilters[field].add(fieldValue);
}
});

Expand Down Expand Up @@ -140,19 +142,19 @@ export default function Datasets() {
<div className="mb-6">
<form className="pl-2 pr-2">
<Select
value={selectedValues}
value={selectedValues as SelectValue}
options={filterableFields.map((f: any) => ({
label: String(f.field ?? 'Unknown Field'),
options: Array.from(new Set((f.options || [])
.filter((o: any) => o != null)
.map((o: any) => String(o))))
.map((o: string) => ({
.filter((o: unknown) => o != null)
.map((o: unknown) => String(o))))
.map((o: unknown) => ({
value: `${f.field}:${o}`,
label: o,
label: String(o),
}))
}))}
placeholder="Filters..."
onChange={(value): void => {
onChange={(value: unknown | unknown[]): void => {
const newSelectedValues = Array.isArray(value) ? value : [];
setSelectedValues(newSelectedValues);
updateQueryString(newSelectedValues);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/analytics/week-review/FilterFieldsSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import SelectComponent from "react-tailwindcss-select";
import { SelectValue as TailwindSelectValue } from "react-tailwindcss-select/dist/components/type";
import { Option } from "react-tailwindcss-select/dist/components/type";

interface FilterFieldsSelectProps {
data: any;
selectedFilters: TailwindSelectValue[];
handleFilterChange: (value: TailwindSelectValue | TailwindSelectValue[]) => void;
selectedFilters: Option[];
handleFilterChange: (value: Option | Option[] | null) => void;
}

export const FilterFieldsSelect: React.FC<FilterFieldsSelectProps> = ({ data, selectedFilters, handleFilterChange }) => {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/app/analytics/week-review/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Heading } from "@/components/catalyst/heading";
import { format } from "date-fns";
import { useQuery } from "@apollo/client";
import { motion } from "framer-motion";
import { Option } from "react-tailwindcss-select/dist/components/type";

import { WEEK_REVIEW_QUERY } from "./weekReviewQuery";
import { DatePicker } from "@/components/DatePicker";
Expand All @@ -16,7 +17,7 @@ import AllocationAnalysisTables from './AllocationAnalysisTables';

export default function WeekReview() {
const [date, setDate] = useState<Date>(new Date());
const [selectedFilters, setSelectedFilters] = useState<TailwindSelectValue[]>(
const [selectedFilters, setSelectedFilters] = useState<Option[]>(
[]
);
const [formattedSelectedValues, setFormattedSelectedValues] = useState<
Expand All @@ -41,9 +42,9 @@ export default function WeekReview() {
};

const handleFilterChange = (
value: TailwindSelectValue | TailwindSelectValue[]
value: Option | Option[] | null
): void => {
const newSelectedValues = Array.isArray(value) ? value : [];
const newSelectedValues = Array.isArray(value) ? value : value ? [value] : [];
setSelectedFilters(newSelectedValues);

const formattedValues =
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import { NextAuthOptions } from "next-auth";

export const authOptions: NextAuthOptions = {
const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
Expand Down

0 comments on commit 0fefd5b

Please sign in to comment.