fix: Typescript check (#21)

* fix: typescript check error

* fix: typescript check error

* fix: typescript check error

* fix: typescript check error

* fix: typescript check error
This commit is contained in:
Takeshi Kimata
2024-07-28 00:20:24 +09:00
committed by GitHub
parent 44b7c7b9c3
commit c60491db09
60 changed files with 496 additions and 311 deletions

View File

@@ -3,7 +3,6 @@ import { useState, useEffect, useContext } from 'react';
import { title, subtitle } from '@/components/primitives';
import { Card, CardBody, Chip, Divider } from '@nextui-org/react';
import { Folder, Clipboard, FlaskConical } from 'lucide-react';
import { CaseTypeCountType, CasePriorityCountType } from '@/types/case';
import { ProgressSeriesType } from '@/types/run';
import { HomeMessages } from './page';
import { TokenContext } from '@/utils/TokenProvider';
@@ -16,6 +15,8 @@ import TestProgressBarChart from './TestProgressColumnChart';
import { TestRunCaseStatusMessages } from '@/types/status';
import { TestTypeMessages } from '@/types/testType';
import { PriorityMessages } from '@/types/priority';
import { ProjectType } from '@/types/project';
import { CasePriorityCountType, CaseTypeCountType } from '@/types/chart';
const apiServer = Config.apiServer;
@@ -59,19 +60,24 @@ export function ProjectHome({
}: Props) {
const context = useContext(TokenContext);
const { theme, setTheme } = useTheme();
const [project, setProject] = useState({
const [project, setProject] = useState<ProjectType>({
id: 0,
name: '',
detail: '',
Folders: [{ Cases: [] }],
Runs: [{ RunCases: [] }],
isPublic: false,
userId: 0,
createdAt: '',
updatedAt: '',
Folders: [],
Runs: [],
});
const [folderNum, setFolderNum] = useState(0);
const [caseNum, setCaseNum] = useState(0);
const [runNum, setRunNum] = useState(0);
const [typesCounts, setTypesCounts] = useState<CaseTypeCountType[]>();
const [priorityCounts, setPriorityCounts] = useState<CasePriorityCountType[]>();
const [progressCategories, setProgressCategories] = useState<string[]>();
const [progressSeries, setProgressSeries] = useState<ProgressSeriesType[]>();
const [typesCounts, setTypesCounts] = useState<CaseTypeCountType[]>([]);
const [priorityCounts, setPriorityCounts] = useState<CasePriorityCountType[]>([]);
const [progressCategories, setProgressCategories] = useState<string[]>([]);
const [progressSeries, setProgressSeries] = useState<ProgressSeriesType[]>([]);
useEffect(() => {
async function fetchDataEffect() {
@@ -92,6 +98,9 @@ export function ProjectHome({
useEffect(() => {
async function aggregate() {
if (!project) {
return;
}
const { folderNum, runNum, caseNum } = aggregateBasicInfo(project);
setFolderNum(folderNum);
setRunNum(runNum);

View File

@@ -2,18 +2,19 @@ import React from 'react';
import { useState, useEffect } from 'react';
import dynamic from 'next/dynamic';
import { priorities } from '@/config/selection';
import { CasePriorityCountType } from '@/types/case';
import { CasePriorityCountType } from '@/types/chart';
import { PriorityMessages } from '@/types/priority';
import { ChartDataType } from '@/types/chart';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
type Props = {
priorityCounts: CasePriorityCountType[];
priorityMessages: PriorityMessages;
theme: string;
theme: string | undefined;
};
export default function TestPriorityDonutChart({ priorityCounts, priorityMessages, theme }: Props) {
const [chartData, setChartData] = useState({
const [chartData, setChartData] = useState<ChartDataType>({
series: [],
options: {
labels: [],

View File

@@ -3,16 +3,17 @@ import { useState, useEffect } from 'react';
import dynamic from 'next/dynamic';
import { ProgressSeriesType } from '@/types/run';
import { testRunCaseStatus } from '@/config/selection';
import { ChartDataType } from '@/types/chart';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
type Props = {
progressSeries: ProgressSeriesType[];
progressCategories: string[];
theme: string;
theme: string | undefined;
};
export default function TestProgressBarChart({ progressSeries, progressCategories, theme }: Props) {
const [chartData, setChartData] = useState({
const [chartData, setChartData] = useState<ChartDataType>({
series: [],
options: {
labels: [],

View File

@@ -2,18 +2,18 @@ import React from 'react';
import { useState, useEffect } from 'react';
import dynamic from 'next/dynamic';
import { testTypes } from '@/config/selection';
import { CaseTypeCountType } from '@/types/case';
import { TestTypeMessages } from '@/types/testType';
import { CaseTypeCountType, ChartDataType } from '@/types/chart';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
type Props = {
typesCounts: CaseTypeCountType[];
testTypeMessages: TestTypeMessages;
theme: string;
theme: string | undefined;
};
export default function TestTypesDonutChart({ typesCounts, testTypeMessages, theme }: Props) {
const [chartData, setChartData] = useState({
const [chartData, setChartData] = useState<ChartDataType>({
series: [],
options: {
labels: [],

View File

@@ -1,6 +1,7 @@
import { ProjectType } from '@/types/project';
import { testTypes, priorities, testRunCaseStatus } from '@/config/selection';
import { TestRunCaseStatusMessages } from '@/types/status';
import { CasePriorityCountType, CaseTypeCountType } from '@/types/chart';
// aggregate folder, case, run mum
function aggregateBasicInfo(project: ProjectType) {
@@ -15,48 +16,58 @@ function aggregateBasicInfo(project: ProjectType) {
return { folderNum, runNum, caseNum };
}
// aggregate test types of each case
function aggregateTestType(project: ProjectType) {
const typesCounts = {};
function aggregateTestType(project: ProjectType): CaseTypeCountType[] {
// count how many test cases are for each type
const typesCounts: number[] = testTypes.map((entry) => {
return 0;
});
project.Folders.forEach((folder) => {
folder.Cases.forEach((testcase) => {
const type = testcase.type;
typesCounts[type] = (typesCounts[type] || 0) + 1;
typesCounts[type]++;
});
});
const result = [];
const result: CaseTypeCountType[] = [];
for (let type = 0; type <= testTypes.length; type++) {
result.push({ type: type, count: typesCounts[type] || 0 });
result.push({ type: type, count: typesCounts[type] });
}
return result;
}
function aggregateTestPriority(project: ProjectType) {
const priorityCounts = {};
// count how many test cases are for each priority
const priorityCounts: number[] = priorities.map((entry) => {
return 0;
});
project.Folders.forEach((folder) => {
folder.Cases.forEach((testcase) => {
const priority = testcase.priority;
priorityCounts[priority] = (priorityCounts[priority] || 0) + 1;
priorityCounts[priority]++;
});
});
const result = [];
const result: CasePriorityCountType[] = [];
for (let priority = 0; priority <= priorities.length; priority++) {
result.push({ priority: priority, count: priorityCounts[priority] || 0 });
result.push({ priority: priority, count: priorityCounts[priority] });
}
return result;
}
function aggregateProgress(project: ProjectType, testRunCaseStatusMessages: TestRunCaseStatusMessages) {
let series = testRunCaseStatus.map((status) => {
type ChartSeries = { name: string; data: number[] };
let series: ChartSeries[] = testRunCaseStatus.map((status) => {
return { name: testRunCaseStatusMessages[status.uid], data: [] };
});
let categories = [];
let categories: string[] = [];
project.Runs.forEach((run) => {
if (!run.RunCases) {
return;
}
run.RunCases.forEach((runCase) => {
const createdAtDate = new Date(runCase.createdAt);
const dateString = createdAtDate.toISOString().slice(0, 10);
@@ -72,6 +83,10 @@ function aggregateProgress(project: ProjectType, testRunCaseStatusMessages: Test
});
project.Runs.forEach((run) => {
if (!run.RunCases) {
return;
}
run.RunCases.forEach((runCase) => {
const createdAtDate = new Date(runCase.createdAt);
const dateString = createdAtDate.toISOString().slice(0, 10);