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

fix loading state on watch list page + better handling for reloads #39339

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions x-pack/legacy/plugins/watcher/public/lib/use_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const useRequest = ({
// Tied to every render and bound to each request.
let isOutdatedRequest = false;

const createRequest = async () => {
const createRequest = async (isInitialRequest = true) => {
// Set a neutral state for a non-request.
if (!path) {
setError(null);
Expand All @@ -71,8 +71,12 @@ export const useRequest = ({
}

setError(null);
setData(initialData);
setIsLoading(true);

// Only set loading state to true and initial data on the first request
if (isInitialRequest) {
setIsLoading(true);
setData(initialData);
}

const { data: responseData, error: responseError } = await sendRequest({
path,
Expand All @@ -99,7 +103,8 @@ export const useRequest = ({
createRequest();

if (interval) {
const intervalRequest = setInterval(createRequest, interval);
const intervalRequest = setInterval(createRequest.bind(null, false), interval);

return () => {
cancelOutdatedRequest();
clearInterval(intervalRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const WatchVisualizationUi = () => {
if (isInitialRequest) {
return setIsInitialRequest(false);
}
reload();
reload(false);
},
[
index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
DeleteWatchesModal,
WatchStatus,
SectionError,
SectionLoading,
} from '../../../components';
import { loadWatches } from '../../../lib/api';
import { watcherGettingStartedUrl } from '../../../lib/documentation_links';
Expand Down Expand Up @@ -157,6 +158,17 @@ const WatchListUi = () => {
</EuiPopover>
);

if (isWatchesLoading) {
return (
<SectionLoading>
<FormattedMessage
id="xpack.watcher.sections.watchList.loadingWatchesDescription"
defaultMessage="Loading watches…"
/>
</SectionLoading>
);
}

if (getPageErrorCode(error)) {
return (
<EuiPageContent>
Expand Down Expand Up @@ -399,7 +411,6 @@ const WatchListUi = () => {
sorting={true}
selection={selectionConfig}
isSelectable={true}
loading={isWatchesLoading}
message={
<FormattedMessage
id="xpack.watcher.sections.watchList.watchTable.noWatchesMessage"
Expand All @@ -417,55 +428,58 @@ const WatchListUi = () => {
);
}

return (
<EuiPageContent>
<DeleteWatchesModal
callback={(deleted?: string[]) => {
if (deleted) {
setDeletedWatches([...deletedWatches, ...watchesToDelete]);
}
setWatchesToDelete([]);
}}
watchesToDelete={watchesToDelete}
/>
if (content) {
return (
<EuiPageContent>
<DeleteWatchesModal
callback={(deleted?: string[]) => {
if (deleted) {
setDeletedWatches([...deletedWatches, ...watchesToDelete]);
}
setWatchesToDelete([]);
}}
watchesToDelete={watchesToDelete}
/>

<EuiTitle size="l">
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={true}>
<h1 data-test-subj="appTitle">
<FormattedMessage
id="xpack.watcher.sections.watchList.header"
defaultMessage="Watcher"
/>
</h1>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
href={watcherGettingStartedUrl}
target="_blank"
iconType="help"
data-test-subj="documentationLink"
>
<FormattedMessage
id="xpack.watcher.sections.watchList.watcherGettingStartedDocsLinkText"
defaultMessage="Watcher docs"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiTitle>
<EuiTitle size="l">
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={true}>
<h1 data-test-subj="appTitle">
<FormattedMessage
id="xpack.watcher.sections.watchList.header"
defaultMessage="Watcher"
/>
</h1>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
href={watcherGettingStartedUrl}
target="_blank"
iconType="help"
data-test-subj="documentationLink"
>
<FormattedMessage
id="xpack.watcher.sections.watchList.watcherGettingStartedDocsLinkText"
defaultMessage="Watcher docs"
/>
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiTitle>

<EuiSpacer size="s" />
<EuiSpacer size="s" />

<EuiText color="subdued">
<p>{watcherDescriptionText}</p>
</EuiText>
<EuiText color="subdued">
<p>{watcherDescriptionText}</p>
</EuiText>

<EuiSpacer size="xl" />
<EuiSpacer size="xl" />

{content}
</EuiPageContent>
);
{content}
</EuiPageContent>
);
}
return null;
};

export const WatchList = injectI18n(WatchListUi);