mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
Use reusable HealthCheckAlert component.
This commit is contained in:
26
awx/ui/src/components/HealthCheckAlert/HealthCheckAlert.js
Normal file
26
awx/ui/src/components/HealthCheckAlert/HealthCheckAlert.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { t } from '@lingui/macro';
|
||||||
|
import { Alert, Button, AlertActionCloseButton } from '@patternfly/react-core';
|
||||||
|
|
||||||
|
function HealthCheckAlert({ onSetHealthCheckAlert }) {
|
||||||
|
return (
|
||||||
|
<Alert
|
||||||
|
variant="default"
|
||||||
|
actionClose={
|
||||||
|
<AlertActionCloseButton onClose={() => onSetHealthCheckAlert(false)} />
|
||||||
|
}
|
||||||
|
title={
|
||||||
|
<>
|
||||||
|
{t`Health check request(s) submitted. Please wait and reload the page.`}{' '}
|
||||||
|
<Button
|
||||||
|
variant="link"
|
||||||
|
isInline
|
||||||
|
onClick={() => window.location.reload(false)}
|
||||||
|
>{t`Reload`}</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HealthCheckAlert;
|
||||||
1
awx/ui/src/components/HealthCheckAlert/index.js
Normal file
1
awx/ui/src/components/HealthCheckAlert/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { default } from './HealthCheckAlert';
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useCallback, useEffect } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import 'styled-components/macro';
|
import 'styled-components/macro';
|
||||||
@@ -23,6 +23,7 @@ import useSelected from 'hooks/useSelected';
|
|||||||
import { InstancesAPI, SettingsAPI } from 'api';
|
import { InstancesAPI, SettingsAPI } from 'api';
|
||||||
import { getQSConfig, parseQueryString } from 'util/qs';
|
import { getQSConfig, parseQueryString } from 'util/qs';
|
||||||
import HealthCheckButton from 'components/HealthCheckButton';
|
import HealthCheckButton from 'components/HealthCheckButton';
|
||||||
|
import HealthCheckAlert from 'components/HealthCheckAlert';
|
||||||
import InstanceListItem from './InstanceListItem';
|
import InstanceListItem from './InstanceListItem';
|
||||||
import RemoveInstanceButton from '../Shared/RemoveInstanceButton';
|
import RemoveInstanceButton from '../Shared/RemoveInstanceButton';
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ const QS_CONFIG = getQSConfig('instance', {
|
|||||||
function InstanceList() {
|
function InstanceList() {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const { me } = useConfig();
|
const { me } = useConfig();
|
||||||
|
const [showHealthCheckAlert, setShowHealthCheckAlert] = useState(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
result: { instances, count, relatedSearchableKeys, searchableKeys, isK8s },
|
result: { instances, count, relatedSearchableKeys, searchableKeys, isK8s },
|
||||||
@@ -83,18 +85,23 @@ function InstanceList() {
|
|||||||
isLoading: isHealthCheckLoading,
|
isLoading: isHealthCheckLoading,
|
||||||
} = useRequest(
|
} = useRequest(
|
||||||
useCallback(async () => {
|
useCallback(async () => {
|
||||||
await Promise.all(
|
const [...response] = await Promise.all(
|
||||||
selected
|
selected
|
||||||
.filter(({ node_type }) => node_type !== 'hop')
|
.filter(({ node_type }) => node_type !== 'hop')
|
||||||
.map(({ id }) => InstancesAPI.healthCheck(id))
|
.map(({ id }) => InstancesAPI.healthCheck(id))
|
||||||
);
|
);
|
||||||
fetchInstances();
|
if (response) {
|
||||||
}, [selected, fetchInstances])
|
setShowHealthCheckAlert(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}, [selected])
|
||||||
);
|
);
|
||||||
const handleHealthCheck = async () => {
|
const handleHealthCheck = async () => {
|
||||||
await fetchHealthCheck();
|
await fetchHealthCheck();
|
||||||
clearSelected();
|
clearSelected();
|
||||||
};
|
};
|
||||||
|
|
||||||
const { error, dismissError } = useDismissableError(healthCheckError);
|
const { error, dismissError } = useDismissableError(healthCheckError);
|
||||||
|
|
||||||
const { expanded, isAllExpanded, handleExpand, expandAll } =
|
const { expanded, isAllExpanded, handleExpand, expandAll } =
|
||||||
@@ -115,6 +122,9 @@ function InstanceList() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{showHealthCheckAlert ? (
|
||||||
|
<HealthCheckAlert onSetHealthCheckAlert={setShowHealthCheckAlert} />
|
||||||
|
) : null}
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<Card>
|
||||||
<PaginatedTable
|
<PaginatedTable
|
||||||
@@ -204,7 +214,9 @@ function InstanceList() {
|
|||||||
key={instance.id}
|
key={instance.id}
|
||||||
value={instance.hostname}
|
value={instance.hostname}
|
||||||
instance={instance}
|
instance={instance}
|
||||||
onSelect={() => handleSelect(instance)}
|
onSelect={() => {
|
||||||
|
handleSelect(instance);
|
||||||
|
}}
|
||||||
isSelected={selected.some((row) => row.id === instance.id)}
|
isSelected={selected.some((row) => row.id === instance.id)}
|
||||||
fetchInstances={fetchInstances}
|
fetchInstances={fetchInstances}
|
||||||
rowIndex={index}
|
rowIndex={index}
|
||||||
|
|||||||
Reference in New Issue
Block a user