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

[Discover] Adding Recent Datasets #8133

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sejli
Copy link
Member

@sejli sejli commented Sep 11, 2024

Description

Adds recent datasets to dataset selector. Also fixes an issue where we were able to select an index without specifying a time field option.

image image

Issues Resolved

Screenshot

Testing the changes

Changelog

  • feat: Adds recently selected data to data selector

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 60.98%. Comparing base (d1caa92) to head (18d458d).

Files with missing lines Patch % Lines
...ry/query_string/dataset_service/dataset_service.ts 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8133      +/-   ##
==========================================
- Coverage   60.98%   60.98%   -0.01%     
==========================================
  Files        3743     3743              
  Lines       88857    88863       +6     
  Branches    13859    13861       +2     
==========================================
+ Hits        54188    54190       +2     
- Misses      31314    31315       +1     
- Partials     3355     3358       +3     
Flag Coverage Δ
Linux_1 28.85% <0.00%> (-0.01%) ⬇️
Linux_2 56.34% <ø> (ø)
Linux_3 ?
Linux_4 29.93% <0.00%> (-0.01%) ⬇️
Windows_1 28.86% <0.00%> (-0.01%) ⬇️
Windows_2 56.29% <ø> (ø)
Windows_3 37.79% <66.66%> (+<0.01%) ⬆️
Windows_4 29.93% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

Nice! Can we add some tests for this feature so that we can be sure that these dont break as we fix more things?

@ashwin-pc
Copy link
Member

How are you limiting the recents?

@@ -34,6 +35,7 @@ const ConnectedDatasetSelector = ({ onSubmit }: ConnectedDatasetSelectorProps) =
const query = queryString.getInitialQueryByDataset(dataset);
queryString.setQuery(query);
onSubmit!(queryString.getQuery());
services.data.query.queryString.getDatasetService().addRecentDataset(dataset);
Copy link
Member

Choose a reason for hiding this comment

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

queryString.getDatasetService().addRecentDataset(initialDataset);

Copy link
Member

Choose a reason for hiding this comment

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

@ashwin-pc do you think we should be just handling this is the query string manager? like updating the recents based on the query?

Copy link
Member

Choose a reason for hiding this comment

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

Yes that would make it less prone to issues like when datasets are selected using ways that arent the dataset selector. Wouldnt block on that being a requirement, but that is a cleaner approach

Copy link
Member

Choose a reason for hiding this comment

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

@sejli maybe could be an open issue

@@ -31,6 +33,9 @@ export class DatasetService {
if (this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)) {
this.registerDefaultTypes();
}
this.recentDatasets = new LRUCache({
max: this.uiSettings.get(UI_SETTINGS.SEARCH_MAX_RECENT_DATASETS) ?? 4,
Copy link
Member

Choose a reason for hiding this comment

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

nit: could this actually be undefined?

Copy link
Member Author

Choose a reason for hiding this comment

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

While running tests, uiSettings has everything set to be jest.fn(), which is the only place where it would be undefined. Could override the original uiSettings mock such that uiSettings.get() returns 4, would that be better practice?

Copy link
Member

Choose a reason for hiding this comment

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

yes, dont change the UI implementation to meet a test infrastructure gap if possible.

@ashwin-pc ashwin-pc added 2.17.1 and removed v2.18.0 labels Sep 17, 2024
return Array.from(this.recentDatasets.values());
}

public addRecentDataset(dataset: Dataset | undefined): void {
Copy link
Member

Choose a reason for hiding this comment

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

do you think instead of relying on the UI component for setting the dataset the recent dataset is the one that is used? so like nobody could add recent dataset they can only access the recent data sets?

opensearch-changeset-bot bot added a commit to sejli/OpenSearch-Dashboards that referenced this pull request Sep 21, 2024
kavilla
kavilla previously approved these changes Sep 23, 2024
@@ -165,6 +165,7 @@ export const Configurator = ({
onConfirm(dataset);
}}
fill
disabled={timeFields && timeFields.length > 0 && timeFieldName === undefined}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: but couldn't you combine the first two expressions down to timeFields?.length > 0.
do you think that the way you did it would be better style?

setSelectedDataset(
allDatasets.filter((ds) => ds.recent)[0].dataset ??
allDatasets.filter((ds) => !ds.recent)[0].dataset
);
Copy link
Member

Choose a reason for hiding this comment

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

is the second filter needed? since if there's no recent datasets, then every dataset should satisfy !ds.recent

also recent datasets are added at first anyways, this is just allDatasets[0].dataset?

@@ -23,6 +24,7 @@ export class DatasetService {
private indexPatterns?: IndexPatternsContract;
private defaultDataset?: Dataset;
private typesRegistry: Map<string, DatasetTypeConfig> = new Map();
private recentDatasets: LRUCache<string, Dataset>;
Copy link
Member

Choose a reason for hiding this comment

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

is this just in memory or stored in some storage?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, we'll just store it in memory.

(dataset) => !recentDatasets.some((ds) => ds.id === dataset.id)
);
const allDatasets = [
...recentDatasets.map((ds) => ({ dataset: ds, recent: true })),
Copy link
Member

Choose a reason for hiding this comment

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

would there be invalid/outdated datasets? should we check and make sure every recent dataset appears in the fetchedDatasets?

Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Sean Li <lnse@amazon.com>
Signed-off-by: Sean Li <lnse@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants