-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from nattvara/show-failures
Show failures
- Loading branch information
Showing
7 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
.flag { | ||
width: 100% !important; | ||
height: 50px; | ||
border-radius: 3px; | ||
} | ||
|
||
.logo { | ||
border-radius: 3px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { Table, Image, Typography } from 'antd'; | ||
import { notification } from 'antd'; | ||
import { useEffect, useState } from 'react'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import apiClient, { ServerErrorResponse, ServerResponse } from '@/http'; | ||
import { Lecture } from '@/components/lecture'; | ||
import styles from './denied-table.less'; | ||
import { ColumnsType } from 'antd/es/table'; | ||
import svFlag from '@/assets/flag-sv.svg'; | ||
import enFlag from '@/assets/flag-en.svg'; | ||
import kthLogo from '@/assets/kth.svg'; | ||
import youtubeLogo from '@/assets/youtube.svg'; | ||
|
||
const { Link } = Typography; | ||
|
||
const UPDATE_INTERVAL = 5000; | ||
|
||
const columns: ColumnsType<Lecture> = [ | ||
{ | ||
title: 'Source', | ||
dataIndex: 'source', | ||
render: (source: string) => { | ||
let icon = ''; | ||
if (source === 'youtube') { | ||
icon = youtubeLogo; | ||
} else if (source === 'kth') { | ||
icon = kthLogo; | ||
} | ||
return ( | ||
<Image src={icon} height={30} className={styles.logo} preview={false} /> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Title', | ||
dataIndex: 'title', | ||
}, | ||
{ | ||
title: 'Analysis', | ||
dataIndex: 'combined_public_id_and_lang', | ||
render: (combined_public_id_and_lang: string) => ( | ||
<> | ||
<Link | ||
href={`/analyse/lectures/${combined_public_id_and_lang}`} | ||
type="dashed" | ||
> | ||
View Progress | ||
</Link> | ||
</> | ||
), | ||
}, | ||
{ | ||
title: 'Content Link', | ||
dataIndex: 'content_link', | ||
render: (content_link: string) => ( | ||
<> | ||
<Link href={content_link} target="_blank"> | ||
{content_link} | ||
</Link> | ||
</> | ||
), | ||
}, | ||
{ | ||
title: 'Language', | ||
dataIndex: 'language', | ||
render: (val: string) => { | ||
let flagIcon = ''; | ||
if (val === 'sv') { | ||
flagIcon = svFlag; | ||
} else if (val === 'en') { | ||
flagIcon = enFlag; | ||
} | ||
return ( | ||
<Image | ||
src={flagIcon} | ||
height={30} | ||
className={styles.flag} | ||
preview={false} | ||
/> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Added At', | ||
dataIndex: 'created_at', | ||
render: (val: string) => { | ||
const d = new Date(val); | ||
const date = d.toDateString(); | ||
const time = d.toLocaleTimeString('sv'); | ||
return ( | ||
<> | ||
{date}, {time} | ||
</> | ||
); | ||
}, | ||
}, | ||
{ | ||
title: 'Progress', | ||
dataIndex: 'overall_progress', | ||
render: (val: string) => <>{val}%</>, | ||
}, | ||
]; | ||
|
||
interface LectureResponse extends ServerResponse { | ||
data: Lecture[]; | ||
} | ||
|
||
export default function FailuresTable() { | ||
const [lectures, setLectures] = useState<Lecture[]>([]); | ||
const [notificationApi, contextHolder] = notification.useNotification(); | ||
|
||
const { mutate: fetchLectures } = useMutation( | ||
async () => { | ||
return await apiClient.get(`/lectures?summary=true&only_failed=true`); | ||
}, | ||
{ | ||
onSuccess: (res: LectureResponse) => { | ||
const result = { | ||
status: res.status + '-' + res.statusText, | ||
headers: res.headers, | ||
data: res.data, | ||
}; | ||
for (let i = 0; i < res.data.length; i++) { | ||
const lecture = res.data[i]; | ||
lecture.combined_public_id_and_lang = `${lecture.public_id}/${lecture.language}`; | ||
lecture['key'] = lecture.combined_public_id_and_lang; | ||
} | ||
setLectures(result.data as Lecture[]); | ||
}, | ||
onError: (err: ServerErrorResponse) => { | ||
notificationApi['error']({ | ||
message: 'Failed to get lectures', | ||
description: err.response.data.detail, | ||
}); | ||
}, | ||
} | ||
); | ||
|
||
useEffect(() => { | ||
fetchLectures(); | ||
}, [fetchLectures]); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
fetchLectures(); | ||
}, UPDATE_INTERVAL); | ||
|
||
return () => clearInterval(interval); | ||
}, [fetchLectures]); | ||
|
||
return ( | ||
<> | ||
{contextHolder} | ||
<Table columns={columns} dataSource={lectures} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Frame from '@/components/main/frame'; | ||
import DeniedTable from '@/components/tables/failures-table'; | ||
import { registerPageLoad } from '@/matomo'; | ||
import { useEffect } from 'react'; | ||
import { Typography } from 'antd'; | ||
|
||
const { Title } = Typography; | ||
|
||
export default function FailuresPage() { | ||
useEffect(() => { | ||
registerPageLoad(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Frame> | ||
<> | ||
<Title level={3}>Lectures that has failed</Title> | ||
<DeniedTable /> | ||
</> | ||
</Frame> | ||
</> | ||
); | ||
} |