Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] [Sourcerer] useFetchIndex unified data source access #154968

Open
dhurley14 opened this issue Apr 13, 2023 · 1 comment
Open
Labels
Feature:Sourcerer Security Solution Sourcerer feature Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.

Comments

@dhurley14
Copy link
Contributor

dhurley14 commented Apr 13, 2023

Once this PR has merged, #149360 the security solution should no longer need to rely on component-level state and effects to determine whether it is safe to access certain properties on the specific data source, as all data sources are now typed to be data views, whether you pass in an array of index name strings or a data view id. My ask will be to update all components where we are separately fetching a data view (if a component receives a data view id) and setting associated state within that component and remove those useEffect hooks and associated state and rely on the data view provided by useFetchIndex.

For example, this:

const [isIndexPatternLoading, { browserFields, indexPatterns: initIndexPattern }] = useFetchIndex(
index,
false
);
const [indexPattern, setIndexPattern] = useState<DataViewBase>(initIndexPattern);
const { data } = useKibana().services;
// Why do we need this? to ensure the query bar auto-suggest gets the latest updates
// when the index pattern changes
// when we select new dataView
// when we choose some other dataSourceType
useEffect(() => {
if (dataSourceType === DataSourceType.IndexPatterns) {
if (!isIndexPatternLoading) {
setIndexPattern(initIndexPattern);
}
}
if (dataSourceType === DataSourceType.DataView) {
const fetchDataView = async () => {
if (dataViewId != null) {
const dv = await data.dataViews.get(dataViewId);
setDataViewTitle(dv.title);
setIndexPattern(dv);
}
};
fetchDataView();
}
}, [dataSourceType, isIndexPatternLoading, data, dataViewId, initIndexPattern]);

Can now just become:

const [isIndexPatternLoading, { browserFields, indexPatterns: dataView }] = useFetchIndex( 
   dataViewId ?? index,
   false 
 );
@dhurley14 dhurley14 added Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Sourcerer Security Solution Sourcerer feature labels Apr 13, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Sourcerer Security Solution Sourcerer feature Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.
Projects
None yet
Development

No branches or pull requests

2 participants