Skip to content

Comments

[Security Solution] Loading fallback poc for data views#225111

Closed
lgestc wants to merge 7 commits intoelastic:mainfrom
lgestc:use_data_view_safe_poc
Closed

[Security Solution] Loading fallback poc for data views#225111
lgestc wants to merge 7 commits intoelastic:mainfrom
lgestc:use_data_view_safe_poc

Conversation

@lgestc
Copy link
Contributor

@lgestc lgestc commented Jun 24, 2025

Summary

This is a POC to test an approach to loading data view information in components.

Adding isSync flag to useDataView hook, allowing us to remove all the checks for loading state / undefined values in components that consume data views.

@elasticmachine
Copy link
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!

const { dataView } = useDataView(DataViewManagerScopeName.default);
// NOTE: there should be a Suspense / some kind of loader here as this value is not settled immediately
const experimentalIndicesExist = !!dataView?.matchedIndices?.length;
const dataView = useDataView(DataViewManagerScopeName.default, true);
Copy link
Contributor Author

@lgestc lgestc Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true triggers the "synchronous" behaviour

fallback = fallbackElement,
}) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const results = scopes.map((scope) => useDataView(scope, false));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In sync mode, data views will be fetched on top level (restored from data view service cache), and then reused in useDataView when it is called with isSync = true


return (
<DataViewContext.Provider value={value}>
{allReady ? children : fallback}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Render a fallback until data views are loaded

scope: DataViewManagerScopeName;
}

type ConditionalReturn<IsSync extends boolean> = IsSync extends true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depending on the flag value, we are getting different return types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants