1- import React , { useEffect , useState } from 'react' ;
2- import { useTranslation } from 'react-i18next' ;
3- import {
4- Button ,
5- Dropdown ,
6- Form ,
7- Input ,
8- Label ,
9- Message ,
10- Pagination ,
11- Popup ,
12- Table ,
13- } from 'semantic-ui-react' ;
14- import { Link } from 'react-router-dom' ;
1+ import React , { useEffect , useState } from 'react' ;
2+ import { useTranslation } from 'react-i18next' ;
3+ import { Button , Dropdown , Form , Input , Label , Message , Pagination , Popup , Table , } from 'semantic-ui-react' ;
4+ import { Link } from 'react-router-dom' ;
155import {
166 API ,
177 loadChannelModels ,
@@ -23,8 +13,8 @@ import {
2313 timestamp2string ,
2414} from '../helpers' ;
2515
26- import { CHANNEL_OPTIONS , ITEMS_PER_PAGE } from '../constants' ;
27- import { renderGroup , renderNumber } from '../helpers/render' ;
16+ import { CHANNEL_OPTIONS , ITEMS_PER_PAGE } from '../constants' ;
17+ import { renderGroup , renderNumber } from '../helpers/render' ;
2818
2919function renderTimestamp ( timestamp ) {
3020 return < > { timestamp2string ( timestamp ) } </ > ;
@@ -93,30 +83,32 @@ const ChannelsTable = () => {
9383 const [ showPrompt , setShowPrompt ] = useState ( shouldShowPrompt ( promptID ) ) ;
9484 const [ showDetail , setShowDetail ] = useState ( isShowDetail ( ) ) ;
9585
86+ const processChannelData = ( channel ) => {
87+ if ( channel . models === '' ) {
88+ channel . models = [ ] ;
89+ channel . test_model = '' ;
90+ } else {
91+ channel . models = channel . models . split ( ',' ) ;
92+ if ( channel . models . length > 0 ) {
93+ channel . test_model = channel . models [ 0 ] ;
94+ }
95+ channel . model_options = channel . models . map ( ( model ) => {
96+ return {
97+ key : model ,
98+ text : model ,
99+ value : model ,
100+ } ;
101+ } ) ;
102+ console . log ( 'channel' , channel ) ;
103+ }
104+ return channel ;
105+ } ;
106+
96107 const loadChannels = async ( startIdx ) => {
97108 const res = await API . get ( `/api/channel/?p=${ startIdx } ` ) ;
98- const { success, message, data } = res . data ;
109+ const { success, message, data} = res . data ;
99110 if ( success ) {
100- let localChannels = data . map ( ( channel ) => {
101- if ( channel . models === '' ) {
102- channel . models = [ ] ;
103- channel . test_model = '' ;
104- } else {
105- channel . models = channel . models . split ( ',' ) ;
106- if ( channel . models . length > 0 ) {
107- channel . test_model = channel . models [ 0 ] ;
108- }
109- channel . model_options = channel . models . map ( ( model ) => {
110- return {
111- key : model ,
112- text : model ,
113- value : model ,
114- } ;
115- } ) ;
116- console . log ( 'channel' , channel ) ;
117- }
118- return channel ;
119- } ) ;
111+ let localChannels = data . map ( processChannelData ) ;
120112 if ( startIdx === 0 ) {
121113 setChannels ( localChannels ) ;
122114 } else {
@@ -301,7 +293,8 @@ const ChannelsTable = () => {
301293 const res = await API . get ( `/api/channel/search?keyword=${ searchKeyword } ` ) ;
302294 const { success, message, data } = res . data ;
303295 if ( success ) {
304- setChannels ( data ) ;
296+ let localChannels = data . map ( processChannelData ) ;
297+ setChannels ( localChannels ) ;
305298 setActivePage ( 1 ) ;
306299 } else {
307300 showError ( message ) ;
0 commit comments