Skip to content

Commit 3031ff7

Browse files
authored
Allow enrollment flyout to load well on slow networks (#71487)
1 parent 649a16b commit 3031ff7

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { sendGetEnrollmentAPIKeys, useCore } from '../../../../hooks';
1313
import { AgentConfigPackageBadges } from '../agent_config_package_badges';
1414

1515
type Props = {
16-
agentConfigs: AgentConfig[];
16+
agentConfigs?: AgentConfig[];
1717
onConfigChange?: (key: string) => void;
1818
} & (
1919
| {
@@ -37,9 +37,16 @@ export const EnrollmentStepAgentConfig: React.FC<Props> = (props) => {
3737
const [selectedState, setSelectedState] = useState<{
3838
agentConfigId?: string;
3939
enrollmentAPIKeyId?: string;
40-
}>({
41-
agentConfigId: agentConfigs.length ? agentConfigs[0].id : undefined,
42-
});
40+
}>({});
41+
42+
useEffect(() => {
43+
if (agentConfigs && agentConfigs.length && !selectedState.agentConfigId) {
44+
setSelectedState({
45+
...selectedState,
46+
agentConfigId: agentConfigs[0].id,
47+
});
48+
}
49+
}, [agentConfigs, selectedState]);
4350

4451
useEffect(() => {
4552
if (onConfigChange && selectedState.agentConfigId) {
@@ -110,7 +117,8 @@ export const EnrollmentStepAgentConfig: React.FC<Props> = (props) => {
110117
/>
111118
</EuiText>
112119
}
113-
options={agentConfigs.map((config) => ({
120+
isLoading={!agentConfigs}
121+
options={(agentConfigs || []).map((config) => ({
114122
value: config.id,
115123
text: config.name,
116124
}))}

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import { StandaloneInstructions } from './standalone_instructions';
2424

2525
interface Props {
2626
onClose: () => void;
27-
agentConfigs: AgentConfig[];
27+
agentConfigs?: AgentConfig[];
2828
}
2929

3030
export const AgentEnrollmentFlyout: React.FunctionComponent<Props> = ({
3131
onClose,
32-
agentConfigs = [],
32+
agentConfigs,
3333
}) => {
3434
const [mode, setMode] = useState<'managed' | 'standalone'>('managed');
3535

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import { ManualInstructions } from '../../../../components/enrollment_instructio
2121
import { DownloadStep, AgentConfigSelectionStep } from './steps';
2222

2323
interface Props {
24-
agentConfigs: AgentConfig[];
24+
agentConfigs?: AgentConfig[];
2525
}
2626

27-
export const ManagedInstructions: React.FunctionComponent<Props> = ({ agentConfigs = [] }) => {
27+
export const ManagedInstructions: React.FunctionComponent<Props> = ({ agentConfigs }) => {
2828
const { getHref } = useLink();
2929
const core = useCore();
3030
const fleetStatus = useFleetStatus();
@@ -85,7 +85,7 @@ export const ManagedInstructions: React.FunctionComponent<Props> = ({ agentConfi
8585
}}
8686
/>
8787
</>
88-
)}{' '}
88+
)}
8989
</>
9090
);
9191
};

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import { DownloadStep, AgentConfigSelectionStep } from './steps';
2525
import { configToYaml, agentConfigRouteService } from '../../../../services';
2626

2727
interface Props {
28-
agentConfigs: AgentConfig[];
28+
agentConfigs?: AgentConfig[];
2929
}
3030

3131
const RUN_INSTRUCTIONS = './elastic-agent run';
3232

33-
export const StandaloneInstructions: React.FunctionComponent<Props> = ({ agentConfigs = [] }) => {
33+
export const StandaloneInstructions: React.FunctionComponent<Props> = ({ agentConfigs }) => {
3434
const core = useCore();
3535
const { notifications } = core;
3636

x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const AgentConfigSelectionStep = ({
4646
setSelectedAPIKeyId,
4747
setSelectedConfigId,
4848
}: {
49-
agentConfigs: AgentConfig[];
49+
agentConfigs?: AgentConfig[];
5050
setSelectedAPIKeyId?: (key: string) => void;
5151
setSelectedConfigId?: (configId: string) => void;
5252
}) => {

0 commit comments

Comments
 (0)