Skip to content

Commit

Permalink
[Index Management] Verify if isLoading before showing warning in add …
Browse files Browse the repository at this point in the history
…lifecycle confirm modal (elastic#209108)

Fixes elastic#208958

## Summary
In this modal, we show a warning banner if there is no policies. The
problem was that the modal was render before the policies are loading.
This PR adds a `isLoading` state that ensures that this warning only is
shown if the policy list is empty after it has been fully loaded.


### How to test

1. Navigate to Index Management.
2. Create an index.
3. Select the index --> Click "Manage index" --> Click "Add lifecycle
policy"
4. Verify that no warning flashes before the policy shows.

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
SoniaSanzV and elasticmachine authored Feb 3, 2025
1 parent 762fd8c commit b922481
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface State {
selectedAlias: string;
policies: PolicyFromES[];
policyErrorMessage?: string;
isLoading: boolean;
}

export class AddLifecyclePolicyConfirmModal extends Component<Props, State> {
Expand All @@ -53,6 +54,7 @@ export class AddLifecyclePolicyConfirmModal extends Component<Props, State> {
policies: [],
selectedPolicyName: '',
selectedAlias: '',
isLoading: true,
};
}
addPolicy = async () => {
Expand Down Expand Up @@ -218,7 +220,7 @@ export class AddLifecyclePolicyConfirmModal extends Component<Props, State> {
async componentDidMount() {
try {
const policies = await loadPolicies();
this.setState({ policies });
this.setState({ policies, isLoading: false });
} catch (err) {
showApiError(
err,
Expand All @@ -233,7 +235,7 @@ export class AddLifecyclePolicyConfirmModal extends Component<Props, State> {
}
}
render() {
const { policies } = this.state;
const { policies, isLoading } = this.state;
const { indexName, closeModal, getUrlForApp } = this.props;
const title = (
<FormattedMessage
Expand All @@ -244,7 +246,7 @@ export class AddLifecyclePolicyConfirmModal extends Component<Props, State> {
}}
/>
);
if (!policies.length) {
if (!isLoading && !policies.length) {
return (
<EuiModal onClose={closeModal}>
<EuiModalHeader>
Expand Down

0 comments on commit b922481

Please sign in to comment.