Skip to content

Commit

Permalink
updates based on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
joemcelroy committed Oct 1, 2024
1 parent 3ce5e0b commit f25dcec
Show file tree
Hide file tree
Showing 30 changed files with 56 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ src/plugins/screenshot_mode @elastic/appex-sharedux
x-pack/examples/screenshotting_example @elastic/appex-sharedux
x-pack/plugins/screenshotting @elastic/kibana-reporting-services
packages/kbn-screenshotting-server @elastic/appex-sharedux
packages/kbn-search-api-keys-api @elastic/search-kibana
packages/kbn-search-api-keys-server @elastic/search-kibana
packages/kbn-search-api-keys-components @elastic/search-kibana
packages/kbn-search-api-panels @elastic/search-kibana
x-pack/plugins/search_assistant @elastic/search-kibana
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@
"@kbn/screenshotting-example-plugin": "link:x-pack/examples/screenshotting_example",
"@kbn/screenshotting-plugin": "link:x-pack/plugins/screenshotting",
"@kbn/screenshotting-server": "link:packages/kbn-screenshotting-server",
"@kbn/search-api-keys-api": "link:packages/kbn-search-api-keys-api",
"@kbn/search-api-keys-components": "link:packages/kbn-search-api-keys-components",
"@kbn/search-api-keys-server": "link:packages/kbn-search-api-keys-server",
"@kbn/search-api-panels": "link:packages/kbn-search-api-panels",
"@kbn/search-assistant": "link:x-pack/plugins/search_assistant",
"@kbn/search-connectors": "link:packages/kbn-search-connectors",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './components/api_key_flyout_wrapper';
export * from './components/api_key_form';
export * from './hooks/use_search_api_key';
export * from './providers/search_api_key_provider';
export * from './src/components/api_key_flyout_wrapper';
export * from './src/components/api_key_form';
export * from './src/hooks/use_search_api_key';
export * from './src/providers/search_api_key_provider';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import React, { useCallback, useReducer, createContext, useEffect } from 'react';
import { useMutation } from '@tanstack/react-query';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { APIKeyCreationResponse } from '@kbn/search-api-keys-api/server/types';
import type { APIKeyCreationResponse } from '@kbn/search-api-keys-server/types';
import { APIRoutes } from '../types';
import { Status } from '../constants';

Expand Down
7 changes: 4 additions & 3 deletions packages/kbn-search-api-keys-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
"outDir": "target/types",
},
"include": [
"public/**/*",
"src/**/*",
"index.ts",
],
"kbn_references": [
"@kbn/i18n",
"@kbn/i18n-react",
"@kbn/kibana-react-plugin",
"@kbn/security-api-key-management",
"@kbn/search-shared-ui",
"@kbn/search-api-keys-api"
"@kbn/search-api-keys-server"
],
"exclude": [
"target/**/*",
]
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './routes/routes';
export * from './src/routes/routes';
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-search-api-keys-api'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/packages/kbn-search-api-keys-api',
roots: ['<rootDir>/packages/kbn-search-api-keys-server'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/packages/kbn-search-api-keys-server',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/packages/kbn-search-api-keys-api/**/*.{ts,tsx}'],
collectCoverageFrom: ['<rootDir>/packages/kbn-search-api-keys-server/**/*.{ts,tsx}'],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-server",
"id": "@kbn/search-api-keys-api",
"id": "@kbn/search-api-keys-server",
"owner": "@elastic/search-kibana"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@kbn/search-api-keys-api",
"name": "@kbn/search-api-keys-server",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { Logger } from '@kbn/logging';
import type { APIKeyCreationResponse } from '../types';
import type { APIKeyCreationResponse } from '../../types';

export async function createAPIKey(
name: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { Logger } from '@kbn/logging';
import type { GetApiKeyResponse } from '../types';
import type { GetApiKeyResponse } from '../../types';

export async function getAPIKeyById(
id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { IRouter } from '@kbn/core/server';
import type { Logger } from '@kbn/logging';

import { schema } from '@kbn/config-schema';
import { APIRoutes } from '../types';
import { APIRoutes } from '../../types';
import { getAPIKeyById } from '../lib/get_key_by_id';
import { createAPIKey } from '../lib/create_key';
import { fetchClusterHasApiKeys, fetchUserStartPrivileges } from '../lib/privileges';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"outDir": "target/types",
},
"include": [
"server/**/*"
"src/**/*",
"types.ts",
"index.ts"
],
"kbn_references": [
"@kbn/core-elasticsearch-server",
Expand All @@ -15,4 +17,4 @@
"exclude": [
"target/**/*",
]
}
}
10 changes: 6 additions & 4 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1498,10 +1498,10 @@
"@kbn/screenshotting-plugin/*": ["x-pack/plugins/screenshotting/*"],
"@kbn/screenshotting-server": ["packages/kbn-screenshotting-server"],
"@kbn/screenshotting-server/*": ["packages/kbn-screenshotting-server/*"],
"@kbn/search-api-keys-api": ["packages/kbn-search-api-keys-api"],
"@kbn/search-api-keys-api/*": ["packages/kbn-search-api-keys-api/*"],
"@kbn/search-api-keys-components": ["packages/kbn-search-api-keys-components"],
"@kbn/search-api-keys-components/*": ["packages/kbn-search-api-keys-components/*"],
"@kbn/search-api-keys-server": ["packages/kbn-search-api-keys-server"],
"@kbn/search-api-keys-server/*": ["packages/kbn-search-api-keys-server/*"],
"@kbn/search-api-panels": ["packages/kbn-search-api-panels"],
"@kbn/search-api-panels/*": ["packages/kbn-search-api-panels/*"],
"@kbn/search-assistant": ["x-pack/plugins/search_assistant"],
Expand Down Expand Up @@ -2000,7 +2000,9 @@
"@kbn/zod-helpers/*": ["packages/kbn-zod-helpers/*"],
// END AUTOMATED PACKAGE LISTING
// Allows for importing from `kibana` package for the exported types.
"@emotion/core": ["typings/@emotion"]
"@emotion/core": [
"typings/@emotion"
]
},
// Support .tsx files and transform JSX into calls to React.createElement
"jsx": "react",
Expand Down Expand Up @@ -2074,4 +2076,4 @@
"@kbn/ambient-storybook-types"
]
}
}
}
2 changes: 1 addition & 1 deletion x-pack/plugins/search_indices/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { I18nProvider } from '@kbn/i18n-react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

import { SearchApiKeyProvider } from '@kbn/search-api-keys-components/public';
import { SearchApiKeyProvider } from '@kbn/search-api-keys-components';
import { UsageTrackerContextProvider } from './contexts/usage_tracker_context';
import { SearchIndicesServicesContextDeps } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { TryInConsoleButton } from '@kbn/try-in-console';

import { useSearchApiKey } from '@kbn/search-api-keys-components/public';
import { useSearchApiKey } from '@kbn/search-api-keys-components';
import { useKibana } from '../../hooks/use_kibana';
import { IngestCodeSnippetParameters } from '../../types';
import { LanguageSelector } from '../shared/language_selector';
Expand Down Expand Up @@ -59,17 +59,25 @@ export const AddDocumentsCodeExample = ({
// TODO: implement smart document generation
return generateSampleDocument(codeSampleMappings);
}, [codeSampleMappings]);
const { apiKey, apiKeyIsVisible } = useSearchApiKey();
const codeParams: IngestCodeSnippetParameters = useMemo(() => {
return {
indexName,
elasticsearchURL: elasticsearchUrl,
sampleDocument,
indexHasMappings,
mappingProperties: codeSampleMappings,
apiKey: apiKeyIsVisible && apiKey ? apiKey : undefined,
};
}, [indexName, elasticsearchUrl, sampleDocument, codeSampleMappings, indexHasMappings]);

const { apiKey, apiKeyIsVisible } = useSearchApiKey();
}, [
indexName,
elasticsearchUrl,
sampleDocument,
codeSampleMappings,
indexHasMappings,
apiKeyIsVisible,
apiKey,
]);

return (
<EuiPanel
Expand Down Expand Up @@ -116,7 +124,6 @@ export const AddDocumentsCodeExample = ({
})}
language="shell"
code={selectedCodeExamples.installCommand}
apiKey={apiKeyIsVisible ? apiKey : null}
onCodeCopyClick={() => {
usageTracker.click([
AnalyticsEvents.indexDetailsInstallCodeCopy,
Expand All @@ -135,7 +142,6 @@ export const AddDocumentsCodeExample = ({
})}
language={Languages[selectedLanguage].codeBlockLanguage}
code={selectedCodeExamples.updateMappingsCommand(codeParams)}
apiKey={apiKeyIsVisible ? apiKey : null}
onCodeCopyClick={() => {
usageTracker.click([
AnalyticsEvents.indexDetailsAddMappingsCodeCopy,
Expand All @@ -151,7 +157,6 @@ export const AddDocumentsCodeExample = ({
title={ingestCodeExamples.ingestTitle}
language={Languages[selectedLanguage].codeBlockLanguage}
code={selectedCodeExamples.ingestCommand(codeParams)}
apiKey={apiKeyIsVisible ? apiKey : null}
onCodeCopyClick={() => {
usageTracker.click([
AnalyticsEvents.indexDetailsIngestDocumentsCodeCopy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { useParams } from 'react-router-dom';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { SectionLoading } from '@kbn/es-ui-shared-plugin/public';
import { ApiKeyForm } from '@kbn/search-api-keys-components/public';
import { ApiKeyForm } from '@kbn/search-api-keys-components';
import { useIndex } from '../../hooks/api/use_index';
import { useKibana } from '../../hooks/use_kibana';
import { ConnectionDetails } from '../connection_details/connection_details';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@ import {
EuiText,
EuiThemeProvider,
} from '@elastic/eui';
import { API_KEY_PLACEHOLDER } from '../../constants';

export interface CodeSampleProps {
id?: string;
title: string;
language: string;
code: string;
onCodeCopyClick?: React.MouseEventHandler<HTMLElement>;
apiKey?: string | null;
}

export const CodeSample = ({
id,
title,
language,
code,
apiKey,
onCodeCopyClick,
}: CodeSampleProps) => {
export const CodeSample = ({ id, title, language, code, onCodeCopyClick }: CodeSampleProps) => {
const onCodeClick = React.useCallback(
(e: React.MouseEvent<HTMLElement, MouseEvent>) => {
if (onCodeCopyClick === undefined) return;
Expand Down Expand Up @@ -64,7 +55,7 @@ export const CodeSample = ({
isCopyable
transparentBackground
>
{apiKey ? code.replace(API_KEY_PLACEHOLDER, apiKey) : code}
{code}
</EuiCodeBlock>
</div>
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiSpacer, EuiText } from '@elasti
import { i18n } from '@kbn/i18n';
import { TryInConsoleButton } from '@kbn/try-in-console';

import { ApiKeyForm, useSearchApiKey } from '@kbn/search-api-keys-components/public';
import { ApiKeyForm, useSearchApiKey } from '@kbn/search-api-keys-components';
import { AnalyticsEvents } from '../../analytics/constants';
import { Languages, AvailableLanguages, LanguageOptions } from '../../code_examples';

Expand Down Expand Up @@ -48,16 +48,18 @@ export const CreateIndexCodeView = ({
[usageTracker, changeCodingLanguage]
);
const elasticsearchUrl = useElasticsearchUrl();
const { apiKey, apiKeyIsVisible } = useSearchApiKey();

const codeParams = useMemo(() => {
return {
indexName: createIndexForm.indexName || undefined,
elasticsearchURL: elasticsearchUrl,
apiKey: apiKeyIsVisible && apiKey ? apiKey : undefined,
};
}, [createIndexForm.indexName, elasticsearchUrl]);
}, [createIndexForm.indexName, elasticsearchUrl, apiKeyIsVisible, apiKey]);
const selectedCodeExample = useMemo(() => {
return selectedCodeExamples[selectedLanguage];
}, [selectedLanguage, selectedCodeExamples]);
const { displayedApiKey, apiKeyIsVisible } = useSearchApiKey();

return (
<EuiFlexGroup direction="column" data-test-subj="createIndexCodeView">
Expand Down Expand Up @@ -128,7 +130,6 @@ export const CreateIndexCodeView = ({
defaultMessage: 'Connect and create an index',
})}
language={Languages[selectedLanguage].codeBlockLanguage}
apiKey={apiKeyIsVisible ? displayedApiKey : null}
code={selectedCodeExample.createIndex(codeParams)}
onCodeCopyClick={() => {
usageTracker.click([
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/search_indices/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { IRouter } from '@kbn/core/server';
import type { Logger } from '@kbn/logging';

import { registerSearchApiKeysRoutes } from '@kbn/search-api-keys-api/server';
import { registerSearchApiKeysRoutes } from '@kbn/search-api-keys-server';
import { registerIndicesRoutes } from './indices';
import { registerStatusRoutes } from './status';

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/search_indices/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"@kbn/cloud-plugin",
"@kbn/search-index-documents",
"@kbn/es-types",
"@kbn/search-api-keys-api",
"@kbn/search-api-keys-server",
"@kbn/search-api-keys-components",
"@kbn/search-shared-ui"
],
"exclude": [
"target/**/*",
]
}
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6267,11 +6267,11 @@
version "0.0.0"
uid ""

"@kbn/search-api-keys-api@link:packages/kbn-search-api-keys-api":
"@kbn/search-api-keys-components@link:packages/kbn-search-api-keys-components":
version "0.0.0"
uid ""

"@kbn/search-api-keys-components@link:packages/kbn-search-api-keys-components":
"@kbn/search-api-keys-server@link:packages/kbn-search-api-keys-server":
version "0.0.0"
uid ""

Expand Down

0 comments on commit f25dcec

Please sign in to comment.