Skip to content

Commit

Permalink
Merge branch 'controls/dndKitDragDrop' of https://github.com/ThomThom…
Browse files Browse the repository at this point in the history
…son/kibana into controls/dndKitDragDrop
  • Loading branch information
ThomThomson committed Oct 4, 2021
2 parents c8a0b53 + 930e551 commit 8a99e89
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { DownloadStep } from '../../../../components';
import {
useStartServices,
useGetOutputs,
useDefaultOutput,
sendGenerateServiceToken,
usePlatform,
PLATFORM_OPTIONS,
Expand Down Expand Up @@ -242,17 +242,15 @@ export const FleetServerCommandStep = ({
};

export const useFleetServerInstructions = (policyId?: string) => {
const outputsRequest = useGetOutputs();
const { output, refresh: refreshOutputs } = useDefaultOutput();
const { notifications } = useStartServices();
const [serviceToken, setServiceToken] = useState<string>();
const [isLoadingServiceToken, setIsLoadingServiceToken] = useState<boolean>(false);
const { platform, setPlatform } = usePlatform();
const [deploymentMode, setDeploymentMode] = useState<DeploymentMode>('production');
const { data: settings, resendRequest: refreshSettings } = useGetSettings();
const fleetServerHost = settings?.item.fleet_server_hosts?.[0];
const output = outputsRequest.data?.items?.[0];
const esHost = output?.hosts?.[0];
const refreshOutputs = outputsRequest.resendRequest;

const installCommand = useMemo((): string => {
if (!serviceToken || !esHost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
useGetSettings,
useInput,
sendPutSettings,
useGetOutputs,
useDefaultOutput,
sendPutOutput,
} from '../../hooks';
import { isDiffPathProtocol, normalizeHostsForAgents } from '../../../common';
Expand Down Expand Up @@ -258,8 +258,7 @@ export const SettingFlyout: React.FunctionComponent<Props> = ({ onClose }) => {

const settingsRequest = useGetSettings();
const settings = settingsRequest?.data?.item;
const outputsRequest = useGetOutputs();
const output = outputsRequest.data?.items?.[0];
const { output } = useDefaultOutput();
const { inputs, submit, validate, isLoading } = useSettingsForm(output?.id, onClose);

const [isConfirmModalVisible, setConfirmModalVisible] = React.useState(false);
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugins/fleet/public/hooks/use_request/outputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { useMemo, useCallback } from 'react';

import { outputRoutesService } from '../../services';
import type { PutOutputRequest, GetOutputsResponse } from '../../types';

Expand All @@ -17,6 +19,21 @@ export function useGetOutputs() {
});
}

export function useDefaultOutput() {
const outputsRequest = useGetOutputs();
const output = useMemo(() => {
return outputsRequest.data?.items.find((o) => o.is_default);
}, [outputsRequest.data]);

const refresh = useCallback(() => {
return outputsRequest.resendRequest();
}, [outputsRequest]);

return useMemo(() => {
return { output, refresh };
}, [output, refresh]);
}

export function sendPutOutput(outputId: string, body: PutOutputRequest['body']) {
return sendRequest({
method: 'put',
Expand Down

0 comments on commit 8a99e89

Please sign in to comment.