@@ -12,7 +12,11 @@ import { observer } from "mobx-react";
1212import { CfIpStatistics , TestStatistics } from "@/store/TestStatistics" ;
1313import { SortType } from "@/typings" ;
1414import { sortByIp , sortByNumber } from "@/utils/sorter" ;
15-
15+ import { useState } from "react" ;
16+ import { Button } from "react-native-paper" ;
17+ import { getStoredJson , storeJson } from "@/store/storage" ;
18+ const STORAGE_KEY_TEST_STATISTICS_USER_CONFIG =
19+ "STORAGE_KEY_TEST_STATISTICS_USER_CONFIG" ;
1620export const StatisticsData = observer (
1721 ( { testStatisticsStore } : { testStatisticsStore : TestStatistics } ) => (
1822 < StatisticsDataInternal rows = { testStatisticsStore . computedRecordList } />
@@ -63,6 +67,19 @@ function sortTableData(
6367 }
6468 return sortByIp ( dataList , sortType , ( obj ) => obj . ip ) ;
6569}
70+ function getFilteredTableHeaders (
71+ originalTableHeaders : MyTableHeaderColumn [ ] ,
72+ isShowAllHeader : boolean
73+ ) {
74+ if ( isShowAllHeader ) {
75+ return originalTableHeaders ;
76+ }
77+ return originalTableHeaders . filter (
78+ ( column ) =>
79+ column . id !== TestStatisticsTableHeaderCol . TotalRespondCount &&
80+ column . id !== TestStatisticsTableHeaderCol . TotalDownloadCount
81+ ) ;
82+ }
6683function StatisticsDataInternal ( props : { rows : CfIpStatistics [ ] } ) {
6784 const { tableHeaders, changeTableHeadersSortType, getCurrentSortConf } =
6885 useTableHeader < MyTableHeaderColumn > ( initialTestStatisticsTableHeaderCols ) ;
@@ -81,17 +98,50 @@ function StatisticsDataInternal(props: { rows: CfIpStatistics[] }) {
8198 columnId as `${TestStatisticsTableHeaderCol } `,
8299 sortType
83100 ) ;
101+ const [ isShowAllHeader , setIsShowAllHeader ] = useState < boolean > ( false ) ;
84102
103+ let filteredTableHeaders = getFilteredTableHeaders (
104+ tableHeaders ,
105+ isShowAllHeader
106+ ) ;
107+
108+ getStoredJson < Record < string , any > > (
109+ STORAGE_KEY_TEST_STATISTICS_USER_CONFIG ,
110+ { }
111+ ) . then ( ( { isShowAllHeader } ) => {
112+ setIsShowAllHeader ( ( ) => ! ! isShowAllHeader ) ;
113+ } ) ;
114+
115+ function onIsShowAllHeaderChange ( isShowAllHeader : boolean ) {
116+ setIsShowAllHeader ( ( isShowAllHeader ) => ! isShowAllHeader ) ;
117+ storeJson ( STORAGE_KEY_TEST_STATISTICS_USER_CONFIG , { isShowAllHeader } ) ;
118+ }
85119 return (
86120 < View style = { styles . getStartedContainer } >
121+ < View
122+ style = { {
123+ flexDirection : "row" ,
124+ alignItems : "flex-end" ,
125+ marginBottom : 10 ,
126+ } }
127+ >
128+ < Button
129+ mode = "contained"
130+ contentStyle = { { marginHorizontal : - 5 , marginVertical : - 2 } }
131+ onPress = { ( ) => onIsShowAllHeaderChange ( ! isShowAllHeader ) }
132+ >
133+ { isShowAllHeader ? "HIDE SOME COLUMNS" : "SHOW ALL COLUMNS" }
134+ </ Button >
135+ </ View >
136+
87137 < TableHeader
88138 style = { { cellTextStyle : styles . tableCell } }
89139 onSort = { onSort }
90- cols = { tableHeaders }
140+ cols = { filteredTableHeaders }
91141 />
92142 < TableRows
93143 rows = { sortedRows }
94- columns = { tableHeaders }
144+ columns = { filteredTableHeaders }
95145 rowKeyName = { "ip" }
96146 style = { { cellTextStyle : styles . tableCell } }
97147 />
0 commit comments