11import { selectModelsDownloaded , setModelsDownloaded } from "@/src/reduxStore/states/pages/models-downloaded" ;
2- import { ModelsDownloaded , ModelsDownloadedStatus } from "@/src/types/components/models-downloaded/models-downloaded" ;
32import { Tooltip } from "@nextui-org/react" ;
43import { IconAlertTriangleFilled , IconArrowLeft , IconCircleCheckFilled , IconExternalLink , IconLoader , IconPlus , IconTrash } from "@tabler/icons-react" ;
54import { useRouter } from "next/router" ;
6- import { useCallback , useEffect } from "react" ;
5+ import { useCallback , useEffect , useState } from "react" ;
76import { useDispatch , useSelector } from "react-redux" ;
8- import LoadingIcon from "../shared/loading /LoadingIcon" ;
7+ import LoadingIcon from "../../../submodules/react-components/components /LoadingIcon" ;
98import { openModal , setModalStates } from "@/src/reduxStore/states/modal" ;
109import { ModalEnum } from "@/src/types/shared/modal" ;
1110import { selectIsAdmin , selectOrganizationId } from "@/src/reduxStore/states/general" ;
@@ -16,17 +15,30 @@ import DeleteModelDownloadModal from "./DeleteModelDownloadModal";
1615import { useWebsocket } from "@/submodules/react-components/hooks/web-socket/useWebsocket" ;
1716import { getModelProviderInfo } from "@/src/services/base/project" ;
1817import { Application , CurrentPage } from "@/submodules/react-components/hooks/web-socket/constants" ;
18+ import { MODELS_DOWNLOAD_TABLE_COLUMNS , prepareTableBodyModelsDownload } from "@/src/util/table-preparations/models-download" ;
19+ import KernTable from "@/submodules/react-components/components/kern-table/KernTable" ;
1920
2021export default function ModelsDownload ( ) {
2122 const router = useRouter ( ) ;
2223 const dispatch = useDispatch ( ) ;
2324 const isAdmin = useSelector ( selectIsAdmin ) ;
2425 const modelsDownloaded = useSelector ( selectModelsDownloaded ) ;
2526
27+ const [ preparedValues , setPreparedValues ] = useState ( [ ] ) ;
28+
2629 useEffect ( ( ) => {
2730 refetchModels ( ) ;
2831 } , [ ] ) ;
2932
33+ useEffect ( ( ) => {
34+ if ( ! modelsDownloaded ) return ;
35+ setPreparedValues ( prepareTableBodyModelsDownload ( modelsDownloaded , openDeleteModal , isAdmin ) ) ;
36+ } , [ modelsDownloaded ] ) ;
37+
38+ function openDeleteModal ( model ) {
39+ dispatch ( setModalStates ( ModalEnum . DELETE_MODEL_DOWNLOAD , { modelName : model . name , open : true } ) ) ;
40+ }
41+
3042 function refetchModels ( ) {
3143 getModelProviderInfo ( ( res ) => {
3244 dispatch ( setModelsDownloaded ( res ) ) ;
@@ -58,79 +70,10 @@ export default function ModelsDownload() {
5870 < div className = "mt-1" >
5971 < div className = "inline-block min-w-full align-middle" >
6072 < div className = "overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg" >
61- < table className = "min-w-full divide-y divide-gray-300" >
62- < thead className = "bg-gray-50" >
63- < tr >
64- < th scope = "col"
65- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
66- Name</ th >
67- < th scope = "col"
68- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
69- Revision</ th >
70- < th scope = "col"
71- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
72- Link</ th >
73- < th scope = "col"
74- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
75- Download date</ th >
76- < th scope = "col"
77- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
78- Size</ th >
79- < th scope = "col"
80- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
81- Status</ th >
82- < th scope = "col"
83- className = "px-3 py-2 text-center text-xs font-medium uppercase tracking-wide text-gray-500" >
84- </ th >
85- </ tr >
86- </ thead >
87- < tbody className = "divide-y divide-gray-200" >
88- { modelsDownloaded && modelsDownloaded . map ( ( model : ModelsDownloaded , index : number ) => (
89- < tr key = { model . name } className = { `${ index % 2 != 0 ? 'bg-gray-50' : 'bg-white' } ` } >
90- < td className = "text-center px-3 py-2 text-sm text-gray-500" >
91- < span className = "inline-block mr-2" > { model . name } </ span >
92- </ td >
93- < td className = "text-center px-3 py-2 text-sm text-gray-500" >
94- { model . revision ? model . revision : '-' }
95- </ td >
96- < td className = "text-center px-3 py-2 text-sm text-gray-500" >
97- < div className = "flex justify-center" >
98- { model . link && < a href = { model . link } target = "_blank" >
99- < IconExternalLink className = "h-5 w-5" />
100- </ a > }
101- </ div >
102- </ td >
103- < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" >
104- { model . date != '0' && ( model . status === ModelsDownloadedStatus . FINISHED || model . status === ModelsDownloadedStatus . DOWNLOADING ) ? model . parseDate : '-' }
105- { model . status === ModelsDownloadedStatus . INITIALIZING && < > { model . date } </ > }
106- </ td >
107- < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" >
108- { model . status === ModelsDownloadedStatus . FINISHED ? model . sizeFormatted : '-' }
109- </ td >
110- < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" >
111- < div className = "flex justify-center" >
112- { model . status === ModelsDownloadedStatus . FINISHED && < Tooltip content = { TOOLTIPS_DICT . GENERAL . SUCCESSFULLY_CREATED } color = "invert" placement = "top" className = "cursor-auto" >
113- < IconCircleCheckFilled className = "h-6 w-6 text-green-500" />
114- </ Tooltip > }
115- { model . status === ModelsDownloadedStatus . FAILED && < Tooltip content = { TOOLTIPS_DICT . GENERAL . ERROR } color = "invert" placement = "top" className = "cursor-auto" >
116- < IconAlertTriangleFilled className = "h-6 w-6 text-red-500" />
117- </ Tooltip > }
118- { model . status === ModelsDownloadedStatus . DOWNLOADING && < Tooltip content = { TOOLTIPS_DICT . GENERAL . DOWNLOADING } color = "invert" placement = "top" className = "cursor-auto" >
119- < LoadingIcon />
120- </ Tooltip > }
121- { model . status === ModelsDownloadedStatus . INITIALIZING && < Tooltip content = { TOOLTIPS_DICT . GENERAL . INITIALIZING } color = "invert" placement = "top" className = "cursor-auto" >
122- < IconLoader className = "h-6 w-6 text-gray-500" />
123- </ Tooltip > }
124- </ div >
125- </ td >
126- < td className = "whitespace-nowrap text-center px-3 py-2 text-sm text-gray-500" >
127- { isAdmin && < IconTrash onClick = { ( ) => dispatch ( setModalStates ( ModalEnum . DELETE_MODEL_DOWNLOAD , { modelName : model . name , open : true } ) ) }
128- className = "h-6 w-6 text-red-700 cursor-pointer" /> }
129- </ td >
130- </ tr >
131- ) ) }
132- </ tbody >
133- </ table >
73+ < KernTable
74+ headers = { MODELS_DOWNLOAD_TABLE_COLUMNS }
75+ values = { preparedValues }
76+ />
13477 </ div >
13578 </ div >
13679 </ div >
0 commit comments