-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use index pattern id instead of title (#6746)
* Use index pattern id instead title * Update CHANGELOG * Fix index pattern in cluster statistics
- Loading branch information
1 parent
1c73ab3
commit 30ff6ee
Showing
14 changed files
with
330 additions
and
316 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
222 changes: 115 additions & 107 deletions
222
plugins/main/public/components/common/data-source/pattern/pattern-data-source.ts
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 |
---|---|---|
@@ -1,125 +1,133 @@ | ||
import { tDataSource, tSearchParams, tFilter, tParsedIndexPattern } from "../index"; | ||
import { | ||
tDataSource, | ||
tSearchParams, | ||
tFilter, | ||
tParsedIndexPattern, | ||
} from '../index'; | ||
import { getDataPlugin } from '../../../../kibana-services'; | ||
import { IndexPatternsContract, IndexPattern } from "../../../../../../../src/plugins/data/public"; | ||
import { | ||
IndexPatternsContract, | ||
IndexPattern, | ||
} from '../../../../../../../src/plugins/data/public'; | ||
import { search } from '../../search-bar/search-bar-service'; | ||
import { PatternDataSourceFilterManager } from '../index'; | ||
|
||
export class PatternDataSource implements tDataSource { | ||
id: string; | ||
title: string; | ||
fields: any[]; | ||
patternService: IndexPatternsContract; | ||
indexPattern: IndexPattern; | ||
export class PatternDataSource implements tDataSource { | ||
id: string; | ||
title: string; | ||
fields: any[]; | ||
patternService: IndexPatternsContract; | ||
indexPattern: IndexPattern; | ||
|
||
constructor(id: string, title: string) { | ||
this.id = id; | ||
this.title = title; | ||
} | ||
/** | ||
* Initialize the data source | ||
*/ | ||
async init(){ | ||
this.patternService = await getDataPlugin().indexPatterns; | ||
this.indexPattern = await this.patternService.get(this.id); | ||
} | ||
constructor(id: string, title: string) { | ||
this.id = id; | ||
this.title = title; | ||
} | ||
/** | ||
* Initialize the data source | ||
*/ | ||
async init() { | ||
this.patternService = await getDataPlugin().indexPatterns; | ||
this.indexPattern = await this.patternService.get(this.id); | ||
} | ||
|
||
getFields(){ | ||
return this.fields; | ||
} | ||
getFields() { | ||
return this.fields; | ||
} | ||
|
||
getFixedFilters(): tFilter[]{ | ||
// return all filters | ||
return [ | ||
...this.getPinnedAgentFilter(), | ||
]; | ||
} | ||
getFixedFilters(): tFilter[] { | ||
// return all filters | ||
return [...this.getPinnedAgentFilter()]; | ||
} | ||
|
||
getFetchFilters(): tFilter[]{ | ||
return [ | ||
...this.getAllowAgentsFilter(), | ||
...this.getExcludeManagerFilter() | ||
]; | ||
} | ||
getFetchFilters(): tFilter[] { | ||
return [...this.getAllowAgentsFilter(), ...this.getExcludeManagerFilter()]; | ||
} | ||
|
||
async select(){ | ||
try { | ||
const pattern = await this.patternService.get(this.id); | ||
if(pattern){ | ||
const fields = await this.patternService.getFieldsForIndexPattern( | ||
pattern, | ||
); | ||
const scripted = pattern.getScriptedFields().map(field => field.spec); | ||
pattern.fields.replaceAll([...fields, ...scripted]); | ||
await this.patternService.updateSavedObject(pattern); | ||
}else{ | ||
throw new Error('Error selecting index pattern: pattern not found'); | ||
} | ||
}catch(error){ | ||
throw new Error(`Error selecting index pattern: ${error}`); | ||
} | ||
async select() { | ||
try { | ||
const pattern = await this.patternService.get(this.id); | ||
if (pattern) { | ||
const fields = await this.patternService.getFieldsForIndexPattern( | ||
pattern, | ||
); | ||
const scripted = pattern.getScriptedFields().map(field => field.spec); | ||
pattern.fields.replaceAll([...fields, ...scripted]); | ||
await this.patternService.updateSavedObject(pattern); | ||
} else { | ||
throw new Error('Error selecting index pattern: pattern not found'); | ||
} | ||
} catch (error) { | ||
throw new Error(`Error selecting index pattern: ${error}`); | ||
} | ||
} | ||
|
||
async fetch(params: tSearchParams){ | ||
const indexPattern = await this.patternService.get(this.id); | ||
const { filters: defaultFilters = [], query, pagination, sorting, fields, dateRange, aggs } = params; | ||
if(!indexPattern){ | ||
return; | ||
} | ||
|
||
try { | ||
const results = await search({ | ||
indexPattern, | ||
filters: defaultFilters, | ||
query, | ||
pagination, | ||
sorting, | ||
fields: fields, | ||
dateRange, | ||
aggs | ||
} | ||
); | ||
|
||
return results; | ||
}catch(error){ | ||
throw new Error(`Error fetching data: ${error}`); | ||
} | ||
|
||
async fetch(params: tSearchParams) { | ||
const indexPattern = await this.patternService.get(this.id); | ||
const { | ||
filters: defaultFilters = [], | ||
query, | ||
pagination, | ||
sorting, | ||
fields, | ||
dateRange, | ||
aggs, | ||
} = params; | ||
if (!indexPattern) { | ||
return; | ||
} | ||
|
||
toJSON(): tParsedIndexPattern { | ||
return { | ||
attributes: { | ||
fields: JSON.stringify(this.fields), | ||
title: this.title | ||
}, | ||
title: this.title, | ||
id: this.id, | ||
migrationVersion: { | ||
'index-pattern': '7.10.0' | ||
}, | ||
namespace: [], | ||
references: [], | ||
score: 0, | ||
type: 'index-pattern', | ||
updated_at: new Date().toISOString(), | ||
version: 'WzPatternDataSource', | ||
_fields: this.fields | ||
} | ||
} | ||
try { | ||
const results = await search({ | ||
indexPattern, | ||
filters: defaultFilters, | ||
query, | ||
pagination, | ||
sorting, | ||
fields: fields, | ||
dateRange, | ||
aggs, | ||
}); | ||
|
||
/** | ||
* Returns the filter when the an agent is pinned (saved in the session storage or redux store) | ||
*/ | ||
getPinnedAgentFilter(): tFilter[] { | ||
return PatternDataSourceFilterManager.getPinnedAgentFilter(this.title); | ||
return results; | ||
} catch (error) { | ||
throw new Error(`Error fetching data: ${error}`); | ||
} | ||
} | ||
|
||
getAllowAgentsFilter(): tFilter[] { | ||
return PatternDataSourceFilterManager.getAllowAgentsFilter(this.title); | ||
} | ||
toJSON(): tParsedIndexPattern { | ||
return { | ||
attributes: { | ||
fields: JSON.stringify(this.fields), | ||
title: this.title, | ||
}, | ||
title: this.title, | ||
id: this.id, | ||
migrationVersion: { | ||
'index-pattern': '7.10.0', | ||
}, | ||
namespace: [], | ||
references: [], | ||
score: 0, | ||
type: 'index-pattern', | ||
updated_at: new Date().toISOString(), | ||
version: 'WzPatternDataSource', | ||
_fields: this.fields, | ||
}; | ||
} | ||
|
||
getExcludeManagerFilter(): tFilter[] { | ||
return PatternDataSourceFilterManager.getExcludeManagerFilter(this.title); | ||
} | ||
/** | ||
* Returns the filter when the an agent is pinned (saved in the session storage or redux store) | ||
*/ | ||
getPinnedAgentFilter(): tFilter[] { | ||
return PatternDataSourceFilterManager.getPinnedAgentFilter(this.id); | ||
} | ||
|
||
getAllowAgentsFilter(): tFilter[] { | ||
return PatternDataSourceFilterManager.getAllowAgentsFilter(this.id); | ||
} | ||
|
||
} | ||
getExcludeManagerFilter(): tFilter[] { | ||
return PatternDataSourceFilterManager.getExcludeManagerFilter(this.id); | ||
} | ||
} |
Oops, something went wrong.