import { Direction , Query } from '@elastic/eui' ; export type SortField = 'snapshot' | 'repository' | 'indices' | 'startTimeInMillis' | 'durationInMillis' | 'shards.total' | 'shards.failed' ; export type SortDirection = Direction ; interface SnapshotTableParams { sortField : SortField ; sortDirection : SortDirection ; pageIndex : number ; pageSize : number ; } interface SnapshotSearchParams { searchField ? : string ; searchValue ? : string ; searchMatch ? : string ; searchOperator ? : string ; } export type SnapshotListParams = SnapshotTableParams & SnapshotSearchParams ; export const DEFAULT_SNAPSHOT_LIST_PARAMS = { sortField : 'startTimeInMillis' , sortDirection : 'desc' , pageIndex : 0 , pageSize : 20 , } ; const resetSearchOptions = ( listParams ) : SnapshotListParams => ( { ... listParams , searchField : undefined , searchValue : undefined , searchMatch : undefined , searchOperator : undefined , } ) ; export const getQueryFromListParams = ( listParams ) : Query => { const { searchField , searchValue } = listParams ; if ( ! searchField || ! searchValue ) { return Query . MATCH_ALL ; } return Query . parse ( `${ searchField }=${ searchValue }` ) ; } ; export const getListParams = ( listParams , query ) : SnapshotListParams => { if ( ! query ) { return resetSearchOptions ( listParams ) ; } const clause = query . ast . clauses [ 0 ] ; if ( ! clause ) { return resetSearchOptions ( listParams ) ; } if ( clause . type === 'term' ) { return { ... listParams , searchField : 'snapshot' , searchValue : String ( clause . value ) , searchMatch : clause . match , searchOperator : 'eq' , } ; } if ( clause . type === 'field' ) { return { ... listParams , searchField : clause . field , searchValue : String ( clause . value ) , searchMatch : clause . match , searchOperator : clause . operator , } ; } return resetSearchOptions ( listParams ) ; } ;