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] Display Cache Time and Clear Cache Button #8214

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8214.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add last updated time and cache refresh button to Discover Advanced Dataset Selector ([#8214](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8214))
4 changes: 4 additions & 0 deletions src/plugins/data/common/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
if (ourKey != null) ours.push(ourKey);
});
}

clear(): void {
this.engine.clear();

Check warning on line 66 in src/plugins/data/common/storage/storage.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/storage/storage.ts#L66

Added line #L66 was not covered by tests
}
}

export function createStorage(deps: { engine: IStorageEngine; prefix: string }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
}

private cacheDataStructure(dataType: string, dataStructure: DataStructure) {
this.setLastCacheTime(new Date());
sejli marked this conversation as resolved.
Show resolved Hide resolved
const cachedDataStructure: CachedDataStructure = {
id: dataStructure.id,
title: dataStructure.title,
Expand All @@ -164,6 +165,18 @@
});
}

public clearCache(): void {
this.sessionStorage.clear();

Check warning on line 169 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L169

Added line #L169 was not covered by tests
}

public getLastCacheTime(): string | undefined {
sejli marked this conversation as resolved.
Show resolved Hide resolved
return this.sessionStorage.get('lastCacheTime');

Check warning on line 173 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L173

Added line #L173 was not covered by tests
sejli marked this conversation as resolved.
Show resolved Hide resolved
}

private setLastCacheTime(time: Date): void {
this.sessionStorage.set('lastCacheTime', time);
}

private async fetchDefaultDataset(): Promise<Dataset | undefined> {
const defaultIndexPatternId = this.uiSettings.get('defaultIndex');
if (!defaultIndexPatternId) {
Expand Down
86 changes: 63 additions & 23 deletions src/plugins/data/public/ui/dataset_selector/dataset_explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import React, { useState } from 'react';
import {
EuiButton,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiLink,
EuiModalBody,
Expand Down Expand Up @@ -68,31 +70,69 @@ export const DatasetExplorer = ({
return (
<>
<EuiModalHeader>
<EuiModalHeaderTitle>
<h1>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.title.step1"
defaultMessage="Step 1: Select data"
/>
</h1>
<EuiText>
<p>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.description"
defaultMessage="Select from those available to you. "
/>
<EuiLink
href={`${services.http.basePath.get()}/app/management/opensearch-dashboards/dataSources`}
target="_blank"
>
<EuiFlexGroup alignItems="center" justifyContent="flexEnd" gutterSize="s">
<EuiFlexItem grow={true}>
<EuiModalHeaderTitle>
<h1>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.dataSourceManagement.title"
defaultMessage="Manage data sources"
id="data.explorer.datasetSelector.advancedSelector.title.step1"
defaultMessage="Step 1: Select data"
/>
</EuiLink>
</p>
</EuiText>
</EuiModalHeaderTitle>
</h1>
<EuiText>
<p>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.description"
defaultMessage="Select from those available to you. "
/>
<EuiLink
href={`${services.http.basePath.get()}/app/management/opensearch-dashboards/dataSources`}
target="_blank"
>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.dataSourceManagement.title"
defaultMessage="Manage data sources"
/>
</EuiLink>
</p>
</EuiText>
</EuiModalHeaderTitle>
</EuiFlexItem>
{queryString.getDatasetService().getLastCacheTime() && (
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="xs">
<EuiFlexItem grow={false}>
<EuiText size="s">
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.lastUpdatedTime"
defaultMessage={`Last updated at: ${new Date(
Date.parse(queryString.getDatasetService().getLastCacheTime()!)
)?.toLocaleTimeString()}. `}
/>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
onClick={() => {
queryString.getDatasetService().clearCache();
onCancel();
}}
size="xs"
iconSide="left"
iconType="refresh"
iconGap="s"
flush="both"
>
<FormattedMessage
id="data.explorer.datasetSelector.advancedSelector.refreshCacheButton"
defaultMessage="Refresh Cache"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiModalHeader>
<EuiModalBody>
<div
Expand Down
Loading