Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.x' into backport-log-collisi…
Browse files Browse the repository at this point in the history
…on-2x
  • Loading branch information
Swiddis committed Aug 8, 2023
2 parents 13a93fd + 389f3b9 commit 562ecd8
Show file tree
Hide file tree
Showing 16 changed files with 921 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const doPropertyValidation = (
};

export function AddIntegrationFlyout(props: IntegrationFlyoutProps) {
const { onClose, onCreate, integrationName, integrationType } = props;
const { onClose, onCreate, integrationName, integrationType, http } = props;

const [isDataSourceValid, setDataSourceValid] = useState<null | false | true>(null);

Expand Down Expand Up @@ -131,11 +131,13 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) {
const fetchDataSourceMappings = async (
targetDataSource: string
): Promise<{ [key: string]: { properties: any } } | null> => {
return fetch(`/api/console/proxy?path=${targetDataSource}/_mapping&method=GET`, {
method: 'POST',
headers: [['osd-xsrf', 'true']],
})
.then((response) => response.json())
return http
.post('/api/console/proxy', {
query: {
path: `${targetDataSource}/_mapping`,
method: 'GET',
},
})
.then((response) => {
// Un-nest properties by a level for caller convenience
Object.keys(response).forEach((key) => {
Expand All @@ -152,8 +154,8 @@ export function AddIntegrationFlyout(props: IntegrationFlyoutProps) {
const fetchIntegrationMappings = async (
targetName: string
): Promise<{ [key: string]: { template: { mappings: { properties?: any } } } } | null> => {
return fetch(`/api/integrations/repository/${targetName}/schema`)
.then((response) => response.json())
return http
.get(`/api/integrations/repository/${targetName}/schema`)
.then((response) => {
if (response.statusCode && response.statusCode !== 200) {
throw new Error('Failed to retrieve Integration schema', { cause: response });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { INTEGRATIONS_BASE } from '../../../../common/constants/shared';
import { badges } from './integration_category_badge_group';

export function AvailableIntegrationsCardView(props: AvailableIntegrationsCardViewProps) {
const http = props.http;
const [toggleIconIdSelected, setToggleIconIdSelected] = useState('1');

const getImage = (url?: string) => {
Expand Down Expand Up @@ -72,7 +73,9 @@ export function AvailableIntegrationsCardView(props: AvailableIntegrationsCardVi
<EuiFlexItem key={v} style={{ minWidth: '14rem', maxWidth: '14rem' }}>
<EuiCard
icon={getImage(
`${INTEGRATIONS_BASE}/repository/${i.name}/static/${i.statics.logo.path}`
http.basePath.prepend(
`${INTEGRATIONS_BASE}/repository/${i.name}/static/${i.statics.logo.path}`
)
)}
title={i.displayName ? i.displayName : i.name}
description={i.description}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { AvailableIntegrationsCardView } from './available_integration_card_view
import { INTEGRATIONS_BASE } from '../../../../common/constants/shared';
import { AvailableIntegrationOverviewPageProps } from './integration_types';
import { useToast } from '../../../../public/components/common/toast';
import { HttpStart } from '../../../../../../src/core/public';

export interface AvailableIntegrationType {
name: string;
Expand Down Expand Up @@ -54,6 +55,7 @@ export interface AvailableIntegrationsCardViewProps {
query: string;
setQuery: (input: string) => void;
renderCateogryFilters: () => React.JSX.Element;
http: HttpStart;
}

export function AvailableIntegrationOverviewPage(props: AvailableIntegrationOverviewPageProps) {
Expand Down Expand Up @@ -190,6 +192,7 @@ export function AvailableIntegrationOverviewPage(props: AvailableIntegrationOver
query,
setQuery,
renderCateogryFilters,
http,
})
: AvailableIntegrationsTable({
loading: false,
Expand Down
73 changes: 42 additions & 31 deletions public/components/integrations/components/integration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,38 @@ export function Integration(props: AvailableIntegrationProps) {
dataSourceName: string
): Promise<{ [key: string]: { properties: any } } | null> => {
const version = payload.template.mappings._meta.version;
payload.index_patterns = [dataSourceName];
return http
.post('/api/console/proxy', {
body: JSON.stringify(payload),
query: {
path: `_index_template/ss4o_${componentName}-${integration.name}-${version}-sample`,
method: 'POST',
},
})
.catch((err: any) => {
console.error(err);
return err;
});
if (componentName !== integration.type) {
return http
.post('/api/console/proxy', {
body: JSON.stringify(payload),
query: {
path: `_component_template/ss4o_${componentName}_${version}_template`,
method: 'POST',
},
})
.catch((err: any) => {
console.error(err);
return err;
});
} else {
payload.index_patterns = [dataSourceName];
return http
.post('/api/console/proxy', {
body: JSON.stringify(payload),
query: {
path: `_index_template/${componentName}_${version}`,
method: 'POST',
},
})
.catch((err: any) => {
console.error(err);
return err;
});
}
};

const createDataSourceMappings = async (targetDataSource: string): Promise<any> => {
const data = await fetch(
`${INTEGRATIONS_BASE}/repository/${integrationTemplateId}/schema`
).then((response) => {
return response.json();
});
const data = await http.get(`${INTEGRATIONS_BASE}/repository/${integrationTemplateId}/schema`);
let error = null;
const mappings = data.data.mappings;
mappings[integration.type].composed_of = mappings[integration.type].composed_of.map(
Expand Down Expand Up @@ -152,8 +163,8 @@ export function Integration(props: AvailableIntegrationProps) {
if (Object.keys(integration).length === 0) {
return;
}
fetch(`${INTEGRATIONS_BASE}/repository/${integration.name}/schema`)
.then((response) => response.json())
http
.get(`${INTEGRATIONS_BASE}/repository/${integration.name}/schema`)
.then((parsedResponse) => {
if (parsedResponse.statusCode && parsedResponse.statusCode !== 200) {
throw new Error('Request for schema failed: ' + parsedResponse.message);
Expand All @@ -170,8 +181,8 @@ export function Integration(props: AvailableIntegrationProps) {
if (Object.keys(integration).length === 0) {
return;
}
fetch(`${INTEGRATIONS_BASE}/repository/${integration.name}/assets`)
.then((response) => response.json())
http
.get(`${INTEGRATIONS_BASE}/repository/${integration.name}/assets`)
.then((parsedResponse) => {
if (parsedResponse.statusCode && parsedResponse.statusCode !== 200) {
throw new Error('Request for assets failed: ' + parsedResponse.message);
Expand Down Expand Up @@ -229,14 +240,14 @@ export function Integration(props: AvailableIntegrationProps) {
data.sampleData
.map((record) => `{"create": { "_index": "${dataSource}" } }\n${JSON.stringify(record)}`)
.join('\n') + '\n';
fetch(`/api/console/proxy?path=${dataSource}/_bulk&method=POST`, {
method: 'POST',
body: requestBody,
headers: [
['osd-xsrf', 'true'],
['Content-Type', 'application/json; charset=utf-8'],
],
})
http
.post('/api/console/proxy', {
body: requestBody,
query: {
path: `${dataSource}/_bulk`,
method: 'POST',
},
})
.catch((err) => {
console.error(err);
setToast('Failed to load sample data', 'danger');
Expand Down Expand Up @@ -303,7 +314,7 @@ export function Integration(props: AvailableIntegrationProps) {
<EuiSpacer />
{IntegrationDetails({ integration })}
<EuiSpacer />
{IntegrationScreenshots({ integration })}
{IntegrationScreenshots({ integration, http })}
<EuiSpacer />
<EuiTabs display="condensed">{renderTabs()}</EuiTabs>
<EuiSpacer size="s" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { INTEGRATIONS_BASE } from '../../../../common/constants/shared';

export function IntegrationScreenshots(props: any) {
const config = props.integration;
const http = props.http;
let screenshots;
if (config.statics.gallery) {
screenshots = config.statics.gallery;
Expand All @@ -23,7 +24,9 @@ export function IntegrationScreenshots(props: any) {
return (
<EuiFlexItem key={screenshot.path} grow={false}>
<EuiImage
src={`${INTEGRATIONS_BASE}/repository/${config.name}/static/${screenshot.path}`}
src={http.basePath.prepend(
`${INTEGRATIONS_BASE}/repository/${config.name}/static/${screenshot.path}`
)}
alt={screenshot.annotation ? screenshot.annotation : ''}
allowFullScreen={true}
size={300}
Expand Down
Loading

0 comments on commit 562ecd8

Please sign in to comment.