Skip to content

Commit

Permalink
Fix after review, better typing and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Apr 28, 2020
1 parent de61e62 commit 1b078e6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { HttpFetchQuery } from 'src/core/public';
import { useRequest, sendRequest, useConditionnalRequest } from './use_request';
import {
useRequest,
sendRequest,
useConditionalRequest,
SendConditionalRequestConfig,
} from './use_request';
import { agentConfigRouteService } from '../../services';
import {
GetAgentConfigsResponse,
Expand All @@ -26,17 +31,11 @@ export const useGetAgentConfigs = (query: HttpFetchQuery = {}) => {
};

export const useGetOneAgentConfig = (agentConfigId: string | undefined) => {
return useConditionnalRequest<GetOneAgentConfigResponse>(
agentConfigId
? {
path: agentConfigRouteService.getInfoPath(agentConfigId),
method: 'get',
shouldSendRequest: true,
}
: {
shouldSendRequest: false,
}
);
return useConditionalRequest<GetOneAgentConfigResponse>({
path: agentConfigId ? agentConfigRouteService.getInfoPath(agentConfigId) : undefined,
method: 'get',
shouldSendRequest: !!agentConfigId,
} as SendConditionalRequestConfig);
};

export const useGetOneAgentConfigFull = (agentConfigId: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { useRequest, UseRequestConfig, sendRequest, useConditionnalRequest } from './use_request';
import {
useRequest,
UseRequestConfig,
sendRequest,
useConditionalRequest,
SendConditionalRequestConfig,
} from './use_request';
import { enrollmentAPIKeyRouteService } from '../../services';
import {
GetOneEnrollmentAPIKeyResponse,
Expand All @@ -15,17 +21,11 @@ import {
type RequestOptions = Pick<Partial<UseRequestConfig>, 'pollIntervalMs'>;

export function useGetOneEnrollmentAPIKey(keyId: string | undefined) {
return useConditionnalRequest<GetOneEnrollmentAPIKeyResponse>(
keyId
? {
method: 'get',
path: enrollmentAPIKeyRouteService.getInfoPath(keyId),
shouldSendRequest: true,
}
: {
shouldSendRequest: false,
}
);
return useConditionalRequest<GetOneEnrollmentAPIKeyResponse>({
method: 'get',
path: keyId ? enrollmentAPIKeyRouteService.getInfoPath(keyId) : undefined,
shouldSendRequest: !!keyId,
} as SendConditionalRequestConfig);
}

export function sendGetOneEnrollmentAPIKey(keyId: string, options?: RequestOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export const useRequest = <D = any>(config: UseRequestConfig) => {
return _useRequest<D>(httpClient, config);
};

type SendConditionnalRequestConfig =
export type SendConditionalRequestConfig =
| (SendRequestConfig & { shouldSendRequest: true })
| (Partial<SendRequestConfig> & { shouldSendRequest: false });

export const useConditionnalRequest = <D = any>(config: SendConditionnalRequestConfig) => {
export const useConditionalRequest = <D = any>(config: SendConditionalRequestConfig) => {
const [state, setState] = useState<{
error: Error | null;
data: D | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface Props {
agentConfigs: AgentConfig[];
}

function useCreateApiKeyForm(configId: string | null, onSuccess: (keyId: string) => void) {
function useCreateApiKeyForm(configId: string | undefined, onSuccess: (keyId: string) => void) {
const { notifications } = useCore();
const [isLoading, setIsLoading] = useState(false);
const apiKeyNameInput = useInput('');
Expand Down Expand Up @@ -67,11 +67,10 @@ export const APIKeySelection: React.FunctionComponent<Props> = ({ onKeyChange, a
});

const [selectedState, setSelectedState] = useState<{
agentConfigId: string | null;
enrollmentAPIKeyId: string | undefined;
agentConfigId?: string;
enrollmentAPIKeyId?: string;
}>({
agentConfigId: agentConfigs.length ? agentConfigs[0].id : null,
enrollmentAPIKeyId: undefined,
agentConfigId: agentConfigs.length ? agentConfigs[0].id : undefined,
});
const filteredEnrollmentAPIKeys = React.useMemo(() => {
if (!selectedState.agentConfigId || !enrollmentAPIKeysRequest.data) {
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -8325,13 +8325,6 @@
"xpack.ingestManager.agentListStatus.offlineLabel": "オフライン",
"xpack.ingestManager.agentListStatus.onlineLabel": "オンライン",
"xpack.ingestManager.agentListStatus.totalLabel": "エージェント",
"xpack.ingestManager.apiKeysForm.configLabel": "構成",
"xpack.ingestManager.apiKeysForm.nameLabel": "キー名",
"xpack.ingestManager.apiKeysForm.saveButton": "保存",
"xpack.ingestManager.apiKeysList.apiKeyColumnTitle": "API キー",
"xpack.ingestManager.apiKeysList.configColumnTitle": "構成",
"xpack.ingestManager.apiKeysList.emptyEnrollmentKeysMessage": "API キーがありません",
"xpack.ingestManager.apiKeysList.nameColumnTitle": "名前",
"xpack.ingestManager.appNavigation.configurationsLinkText": "構成",
"xpack.ingestManager.appNavigation.fleetLinkText": "フリート",
"xpack.ingestManager.appNavigation.overviewLinkText": "概要",
Expand Down Expand Up @@ -8410,8 +8403,6 @@
"xpack.ingestManager.deleteAgentConfigs.successMultipleNotificationTitle": "{count} 件のエージェント構成を削除しました",
"xpack.ingestManager.deleteAgentConfigs.successSingleNotificationTitle": "エージェント構成「{id}」を削除しました",
"xpack.ingestManager.deleteApiKeys.confirmModal.cancelButtonLabel": "キャンセル",
"xpack.ingestManager.deleteApiKeys.confirmModal.confirmButtonLabel": "削除",
"xpack.ingestManager.deleteApiKeys.confirmModal.title": "API キーを削除: {apiKeyId}",
"xpack.ingestManager.deleteDatasource.confirmModal.affectedAgentsMessage": "{agentConfigName} が一部のエージェントで既に使用されていることをフリートが検出しました。",
"xpack.ingestManager.deleteDatasource.confirmModal.affectedAgentsTitle": "このアクションは {agentsCount} {agentsCount, plural, one {# エージェント} other {# エージェント}}に影響します",
"xpack.ingestManager.deleteDatasource.confirmModal.cancelButtonLabel": "キャンセル",
Expand All @@ -8434,9 +8425,7 @@
"xpack.ingestManager.editConfig.successNotificationTitle": "エージェント構成「{name}」を更新しました",
"xpack.ingestManager.enrollmentApiKeyForm.namePlaceholder": "名前を選択",
"xpack.ingestManager.enrollmentApiKeyList.createNewButton": "新規キーを作成",
"xpack.ingestManager.enrollmentApiKeyList.hideTableButton": "を非表示",
"xpack.ingestManager.enrollmentApiKeyList.useExistingsButton": "既存のキーを使用",
"xpack.ingestManager.enrollmentApiKeyList.viewTableButton": "表示",
"xpack.ingestManager.epm.addDatasourceButtonText": "データソースを作成",
"xpack.ingestManager.epm.pageSubtitle": "人気のアプリやサービスのパッケージを参照する",
"xpack.ingestManager.epm.pageTitle": "Elastic Package Manager",
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -8328,13 +8328,6 @@
"xpack.ingestManager.agentListStatus.offlineLabel": "脱机",
"xpack.ingestManager.agentListStatus.onlineLabel": "联机",
"xpack.ingestManager.agentListStatus.totalLabel": "代理",
"xpack.ingestManager.apiKeysForm.configLabel": "配置",
"xpack.ingestManager.apiKeysForm.nameLabel": "密钥名称",
"xpack.ingestManager.apiKeysForm.saveButton": "保存",
"xpack.ingestManager.apiKeysList.apiKeyColumnTitle": "API 密钥",
"xpack.ingestManager.apiKeysList.configColumnTitle": "配置",
"xpack.ingestManager.apiKeysList.emptyEnrollmentKeysMessage": "无 API 密钥",
"xpack.ingestManager.apiKeysList.nameColumnTitle": "名称",
"xpack.ingestManager.appNavigation.configurationsLinkText": "配置",
"xpack.ingestManager.appNavigation.fleetLinkText": "Fleet",
"xpack.ingestManager.appNavigation.overviewLinkText": "概览",
Expand Down Expand Up @@ -8413,8 +8406,6 @@
"xpack.ingestManager.deleteAgentConfigs.successMultipleNotificationTitle": "已删除 {count} 个代理配置",
"xpack.ingestManager.deleteAgentConfigs.successSingleNotificationTitle": "已删除代理配置“{id}”",
"xpack.ingestManager.deleteApiKeys.confirmModal.cancelButtonLabel": "取消",
"xpack.ingestManager.deleteApiKeys.confirmModal.confirmButtonLabel": "删除",
"xpack.ingestManager.deleteApiKeys.confirmModal.title": "删除 api 密钥:{apiKeyId}",
"xpack.ingestManager.deleteDatasource.confirmModal.affectedAgentsMessage": "Fleet 已检测到 {agentConfigName} 已由您的部分代理使用。",
"xpack.ingestManager.deleteDatasource.confirmModal.affectedAgentsTitle": "此操作将影响 {agentsCount} 个 {agentsCount, plural, one {代理} other {代理}}。",
"xpack.ingestManager.deleteDatasource.confirmModal.cancelButtonLabel": "取消",
Expand All @@ -8437,9 +8428,7 @@
"xpack.ingestManager.editConfig.successNotificationTitle": "代理配置“{name}”已更新",
"xpack.ingestManager.enrollmentApiKeyForm.namePlaceholder": "选择名称",
"xpack.ingestManager.enrollmentApiKeyList.createNewButton": "创建新密钥",
"xpack.ingestManager.enrollmentApiKeyList.hideTableButton": "隐藏",
"xpack.ingestManager.enrollmentApiKeyList.useExistingsButton": "使用现有密钥",
"xpack.ingestManager.enrollmentApiKeyList.viewTableButton": "查看",
"xpack.ingestManager.epm.addDatasourceButtonText": "创建数据源",
"xpack.ingestManager.epm.pageSubtitle": "浏览热门应用和服务的软件。",
"xpack.ingestManager.epm.pageTitle": "Elastic Package Manager",
Expand Down

0 comments on commit 1b078e6

Please sign in to comment.