@@ -7,8 +7,7 @@ import { IGetTagsResponse, ITag, TagsAPI } from "../api/v1/TagsAPI";
77import { TagFormModal } from "../forms/TagFormModal" ;
88import { dashboardStore } from "../stores/DashboardStore" ;
99import { PermissionUtils } from "../utilities/PermissionUtils" ;
10- import { DEFAULT_PAGE_SIZE , PAGE_SIZE_OPTIONS } from "./Config" ;
11- import { DeleteLink } from "./DeleteLink" ;
10+ import { PAGE_SIZE_OPTIONS } from "./Config" ;
1211
1312type DATA_INDEX = "name" | "controls" ;
1413
@@ -23,32 +22,22 @@ type IRow = {
2322 [ k in DATA_INDEX ] : React . ReactNode ;
2423} ;
2524
26- interface IReloadOptions {
27- search ?: string ;
28- page ?: number ;
29- perPage ?: number ;
30- }
31-
3225export function TagsTable ( props : { project : IProject ; tableReloader ?: number ; style ?: React . CSSProperties } ) {
3326 const params = useParams < { projectId : string } > ( ) ;
3427
35- const [ page , setPage ] = React . useState < number > ( 1 ) ;
36- const [ perPage , setPerPage ] = React . useState < number > ( DEFAULT_PAGE_SIZE ) ;
37- const [ search , setSearch ] = React . useState < string > ( null ) ;
38- const [ tagsResponse , setTagsResponse ] = React . useState < IGetTagsResponse > ( null ) ;
28+ const [ search , setSearch ] = React . useState < string | null > ( null ) ;
29+ const [ tagsResponse , setTagsResponse ] = React . useState < IGetTagsResponse | null > ( null ) ;
3930 const [ loading , setLoading ] = React . useState < boolean > ( false ) ;
4031 const [ tagDialogVisible , setTagDialogVisible ] = React . useState < boolean > ( false ) ;
41- const [ tagToEdit , setTagToEdit ] = React . useState < ITag > ( null ) ;
32+ const [ tagToEdit , setTagToEdit ] = React . useState < ITag | null > ( null ) ;
4233
43- async function reload ( options ?: IReloadOptions ) {
34+ async function reload ( options ?: { search ?: string } ) {
4435 setLoading ( true ) ;
4536
4637 try {
4738 const response = await TagsAPI . getTags ( {
4839 projectId : params . projectId ,
49- search : options ?. search || search ,
50- page : options ?. page || page ,
51- perPage : options ?. perPage || perPage
40+ search : options ?. search || search
5241 } ) ;
5342 setTagsResponse ( response ) ;
5443 } catch ( error ) {
@@ -61,7 +50,7 @@ export function TagsTable(props: { project: IProject; tableReloader?: number; st
6150
6251 const debouncedSearch = React . useCallback (
6352 _ . debounce ( ( value : string ) => {
64- reload ( { search : value , page : 1 } ) ;
53+ reload ( { search : value } ) ;
6554 } , 500 ) ,
6655 [ ]
6756 ) ;
@@ -117,8 +106,7 @@ export function TagsTable(props: { project: IProject; tableReloader?: number; st
117106 }
118107
119108 setLoading ( false ) ;
120- setPage ( 1 ) ;
121- await reload ( { page : 1 } ) ;
109+ await reload ( ) ;
122110 }
123111 } ) ;
124112 } }
@@ -190,21 +178,7 @@ export function TagsTable(props: { project: IProject; tableReloader?: number; st
190178 pagination = { {
191179 pageSizeOptions : PAGE_SIZE_OPTIONS ,
192180 showSizeChanger : true ,
193- current : page ,
194- pageSize : perPage ,
195- total : tagsResponse ?. meta ?. total || 0 ,
196- onChange : async ( newPage , newPerPage ) => {
197- const isPageSizeChange = perPage !== newPerPage ;
198-
199- if ( isPageSizeChange ) {
200- setPage ( 1 ) ;
201- setPerPage ( newPerPage ) ;
202- reload ( { page : 1 , perPage : newPerPage } ) ;
203- } else {
204- setPage ( newPage ) ;
205- reload ( { page : newPage } ) ;
206- }
207- }
181+ total : tagsResponse ?. meta ?. total || 0
208182 } }
209183 locale = { {
210184 emptyText : < Empty description = "No tags found" image = { Empty . PRESENTED_IMAGE_SIMPLE } />
@@ -219,7 +193,7 @@ export function TagsTable(props: { project: IProject; tableReloader?: number; st
219193 } }
220194 formProps = { {
221195 projectId : params . projectId ,
222- tag : tagToEdit ,
196+ tag : tagToEdit ?? undefined ,
223197 onSaved : async ( ) => {
224198 setTagDialogVisible ( false ) ;
225199 setTagToEdit ( null ) ;
0 commit comments