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

@@ -8,10 +8,11 @@ import { RunType, RunsMessages } from '@/types/run';
import RunDialog from './RunDialog';
import DeleteConfirmDialog from '@/components/DeleteConfirmDialog';
import { TokenContext } from '@/utils/TokenProvider';
import { LocaleCodeType } from '@/types/locale';
type Props = {
projectId: string;
locale: string;
locale: LocaleCodeType;
messages: RunsMessages;
};

View File

@@ -1,4 +1,4 @@
import { useState, useEffect, useMemo } from 'react';
import { useState, useEffect, useMemo, ReactNode } from 'react';
import {
Table,
TableHeader,
@@ -17,6 +17,7 @@ import { Link, NextUiLinkClasses } from '@/src/navigation';
import { MoreVertical } from 'lucide-react';
import { RunsMessages, RunType } from '@/types/run';
import dayjs from 'dayjs';
import { LocaleCodeType } from '@/types/locale';
type Props = {
projectId: string;
@@ -24,7 +25,7 @@ type Props = {
runs: RunType[];
onDeleteRun: (runId: number) => void;
messages: RunsMessages;
locale: string;
locale: LocaleCodeType;
};
export default function RunsTable({ projectId, isDisabled, runs, onDeleteRun, messages, locale }: Props) {
@@ -63,19 +64,19 @@ export default function RunsTable({ projectId, isDisabled, runs, onDeleteRun, me
return text.length > maxLength ? text.slice(0, maxLength) + '...' : text;
};
const renderCell = (run: RunType, columnKey: Key) => {
const renderCell = (run: RunType, columnKey: string) => {
const cellValue = run[columnKey as keyof RunType];
switch (columnKey) {
case 'id':
return <span>{cellValue}</span>;
return <span>{cellValue as number}</span>;
case 'name':
const maxLength = 30;
const truncatedDescription = truncateText(run.description, maxLength);
return (
<div>
<Link href={`/projects/${projectId}/runs/${run.id}`} locale={locale} className={NextUiLinkClasses}>
{cellValue}
{cellValue as string}
</Link>
<div className="text-xs text-default-500">
<div>{truncatedDescription}</div>
@@ -83,7 +84,7 @@ export default function RunsTable({ projectId, isDisabled, runs, onDeleteRun, me
</div>
);
case 'updatedAt':
return <span>{dayjs(cellValue).format('YYYY/MM/DD HH:mm')}</span>;
return <span>{dayjs(cellValue as string).format('YYYY/MM/DD HH:mm')}</span>;
case 'actions':
return (
<Dropdown>
@@ -145,7 +146,9 @@ export default function RunsTable({ projectId, isDisabled, runs, onDeleteRun, me
</TableHeader>
<TableBody emptyContent={messages.noRunsFound} items={sortedItems}>
{(item) => (
<TableRow key={item.id}>{(columnKey) => <TableCell>{renderCell(item, columnKey)}</TableCell>}</TableRow>
<TableRow key={item.id}>
{(columnKey) => <TableCell>{renderCell(item, columnKey as string) as ReactNode}</TableCell>}
</TableRow>
)}
</TableBody>
</Table>

View File

@@ -77,7 +77,7 @@ export default function RunEditor({
const { theme, setTheme } = useTheme();
const [testRun, setTestRun] = useState<RunType>(defaultTestRun);
const [folders, setFolders] = useState<FolderType[]>([]);
const [runStatusCounts, setRunStatusCounts] = useState<RunStatusCountType[]>();
const [runStatusCounts, setRunStatusCounts] = useState<RunStatusCountType[]>([]);
const [selectedKeys, setSelectedKeys] = useState<Selection>(new Set([]));
const [selectedFolder, setSelectedFolder] = useState<FolderType | null>(null);
const [testCases, setTestCases] = useState<CaseType[]>([]);
@@ -256,10 +256,12 @@ export default function RunEditor({
size="sm"
variant="bordered"
selectedKeys={[testRunStatus[testRun.state].uid]}
onSelectionChange={(e) => {
const selectedUid = e.anchorKey;
const index = testRunStatus.findIndex((template) => template.uid === selectedUid);
setTestRun({ ...testRun, state: index });
onSelectionChange={(newSelection) => {
if (newSelection !== 'all' && newSelection.size !== 0) {
const selectedUid = Array.from(newSelection)[0];
const index = testRunStatus.findIndex((template) => template.uid === selectedUid);
setTestRun({ ...testRun, state: index });
}
}}
label={messages.status}
className="mt-3 max-w-xs"
@@ -278,7 +280,7 @@ export default function RunEditor({
<div className="flex items-center justify-between">
<h6 className="h-8 font-bold">{messages.selectTestCase}</h6>
<div>
{(selectedKeys.size > 0 || selectedKeys === 'all') && (
{(selectedKeys === 'all' || selectedKeys.size > 0) && (
<Dropdown>
<DropdownTrigger>
<Button

View File

@@ -4,6 +4,7 @@ import dynamic from 'next/dynamic';
import { testRunCaseStatus } from '@/config/selection';
import { RunStatusCountType } from '@/types/run';
import { TestRunCaseStatusMessages } from '@/types/status';
import { ChartDataType } from '@/types/chart';
const Chart = dynamic(() => import('react-apexcharts'), { ssr: false });
type Props = {
@@ -13,7 +14,7 @@ type Props = {
};
export default function RunProgressDounut({ statusCounts, testRunCaseStatusMessages, theme }: Props) {
const [chartData, setChartData] = useState({
const [chartData, setChartData] = useState<ChartDataType>({
series: [],
options: {
labels: [],

View File

@@ -1,3 +1,4 @@
import { LocaleCodeType } from '@/types/locale';
import RunsPage from './RunsPage';
import { useTranslations } from 'next-intl';
@@ -27,7 +28,7 @@ export default function Page({ params }: { params: { projectId: string; locale:
return (
<>
<RunsPage projectId={params.projectId} locale={params.locale} messages={messages} />
<RunsPage projectId={params.projectId} locale={params.locale as LocaleCodeType} messages={messages} />
</>
);
}

View File

@@ -246,6 +246,8 @@ async function updateRunCases(jwt: string, runId: number, testCases: CaseType[])
runId: runId,
status: itr.RunCases[0].status,
editState: itr.RunCases[0].editState,
createdAt: '0',
updatedAt: '0',
});
}
});