-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve sort, default sort and short dot
Signed-off-by: Anan Z <[email protected]>
- Loading branch information
Showing
12 changed files
with
239 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/plugins/discover/public/application/components/default_discover_table/helper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { IndexPattern } from '../../../opensearch_dashboards_services'; | ||
import { shortenDottedString } from '../../helpers'; | ||
|
||
export type SortOrder = [string, string]; | ||
export interface LegacyDisplayedColumn { | ||
name: string; | ||
displayName: string; | ||
isSortable: boolean; | ||
isRemoveable: boolean; | ||
colLeftIdx: number; | ||
colRightIdx: number; | ||
} | ||
|
||
export interface ColumnProps { | ||
name: string; | ||
displayName: string; | ||
isSortable: boolean; | ||
isRemoveable: boolean; | ||
colLeftIdx: number; | ||
colRightIdx: number; | ||
} | ||
|
||
/** | ||
* Returns properties necessary to display the time column | ||
* If it's an IndexPattern with timefield, the time column is | ||
* prepended, not moveable and removeable | ||
* @param timeFieldName | ||
*/ | ||
export function getTimeColumn(timeFieldName: string): ColumnProps { | ||
return { | ||
name: timeFieldName, | ||
displayName: 'Time', | ||
isSortable: true, | ||
isRemoveable: false, | ||
colLeftIdx: -1, | ||
colRightIdx: -1, | ||
}; | ||
} | ||
/** | ||
* A given array of column names returns an array of properties | ||
* necessary to display the columns. If the given indexPattern | ||
* has a timefield, a time column is prepended | ||
* @param columns | ||
* @param indexPattern | ||
* @param hideTimeField | ||
* @param isShortDots | ||
*/ | ||
export function getLegacyDisplayedColumns( | ||
columns: string[], | ||
indexPattern: IndexPattern, | ||
hideTimeField: boolean, | ||
isShortDots: boolean | ||
): LegacyDisplayedColumn[] { | ||
if (!Array.isArray(columns) || typeof indexPattern !== 'object' || !indexPattern.getFieldByName) { | ||
return []; | ||
} | ||
const columnProps = columns.map((column, idx) => { | ||
const field = indexPattern.getFieldByName(column); | ||
return { | ||
name: column, | ||
displayName: isShortDots ? shortenDottedString(column) : column, | ||
isSortable: field && field.sortable ? true : false, | ||
isRemoveable: column !== '_source' || columns.length > 1, | ||
colLeftIdx: idx - 1 < 0 ? -1 : idx - 1, | ||
colRightIdx: idx + 1 >= columns.length ? -1 : idx + 1, | ||
}; | ||
}); | ||
return !hideTimeField && indexPattern.timeFieldName | ||
? [getTimeColumn(indexPattern.timeFieldName), ...columnProps] | ||
: columnProps; | ||
} |
Oops, something went wrong.