Skip to content

Commit

Permalink
Add mds support for Integration flyout only for creation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Sep 5, 2024
1 parent e14c643 commit 0bf5a58
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
EuiCard,
EuiAccordion,
} from '@elastic/eui';
import { ApplicationStart, HttpStart, NotificationsStart } from 'opensearch-dashboards/public';
import {
ApplicationStart,
HttpStart,
NotificationsStart,
SavedObjectsStart,
} from 'opensearch-dashboards/public';
import { useLocation, useParams } from 'react-router-dom';
import { escapeRegExp } from 'lodash';
import { DATACONNECTIONS_BASE } from '../../../constants';
Expand All @@ -46,7 +51,7 @@ import {
IntegrationInstancesSearchResult,
} from '../../../../framework/types';
import { INTEGRATIONS_BASE } from '../../../../framework/utils/shared';
import { isPluginInstalled } from '../../utils';
import { isPluginInstalled, getDataSourcesWithFields } from '../../utils';

interface DirectQueryDataConnectionDetailProps {
featureFlagStatus: boolean;
Expand All @@ -55,6 +60,7 @@ interface DirectQueryDataConnectionDetailProps {
application: ApplicationStart;
setBreadcrumbs: (breadcrumbs: any) => void;
useNewUX: boolean;
savedObjects: SavedObjectsStart;
}

export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnectionDetailProps> = ({
Expand All @@ -64,6 +70,7 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
application,
setBreadcrumbs,
useNewUX,
savedObjects,
}) => {
const [observabilityDashboardsExists, setObservabilityDashboardsExists] = useState(false);
const { dataSourceName } = useParams<{ dataSourceName: string }>();
Expand Down Expand Up @@ -117,6 +124,31 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
const [refreshIntegrationsFlag, setRefreshIntegrationsFlag] = useState(false);
const refreshInstances = () => setRefreshIntegrationsFlag((prev) => !prev);

const [clusterTitle, setDataSourceTitle] = useState<string | undefined>();
const fetchDataSources = async () => {
try {
const dataSources = await getDataSourcesWithFields(savedObjects.client, ['id', 'title']);

Check warning on line 130 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx#L129-L130

Added lines #L129 - L130 were not covered by tests

// Find the data source title based on the dataSourceMDSId
const foundDataSource = dataSources.find((ds: any) => ds.id === dataSourceMDSId);

Check warning on line 133 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx#L133

Added line #L133 was not covered by tests
if (foundDataSource) {
setDataSourceTitle(foundDataSource.attributes.title);

Check warning on line 135 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx#L135

Added line #L135 was not covered by tests
}
} catch (error) {
notifications.toasts.addDanger({

Check warning on line 138 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx#L138

Added line #L138 was not covered by tests
title: 'Failed to fetch data sources',
text: error.message,
});
}
};

useEffect(() => {
if (featureFlagStatus) {
fetchDataSources();

Check warning on line 147 in src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/data_source_management/public/components/direct_query_data_sources_components/connection_detail/direct_query_connection_detail.tsx#L147

Added line #L147 was not covered by tests
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [featureFlagStatus, savedObjects, notifications, dataSourceMDSId]);

useEffect(() => {
const searchDataSourcePattern = new RegExp(
`flint_${escapeRegExp(datasourceDetails.name)}_default_.*`
Expand Down Expand Up @@ -147,6 +179,7 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
datasourceName={datasourceDetails.name}
http={http}
selectedDataSourceId={dataSourceMDSId || ''}
selectedClusterName={clusterTitle}
/>
) : null;

Expand Down Expand Up @@ -403,21 +436,21 @@ export const DirectQueryDataConnectionDetail: React.FC<DirectQueryDataConnection
/>
),
},
!featureFlagStatus &&
observabilityDashboardsExists && {
id: 'installed_integrations',
name: 'Installed Integrations',
disabled: false,
content: (
<InstalledIntegrationsTable
integrations={dataSourceIntegrations}
datasourceType={datasourceDetails.connector}
datasourceName={datasourceDetails.name}
refreshInstances={refreshInstances}
http={http}
/>
),
},
observabilityDashboardsExists && {
id: 'installed_integrations',
name: 'Installed Integrations',
disabled: false,
content: (
<InstalledIntegrationsTable
integrations={dataSourceIntegrations}
datasourceType={datasourceDetails.connector}
datasourceName={datasourceDetails.name}
refreshInstances={refreshInstances}
http={http}
selectedDataSourceId={featureFlagStatus ? dataSourceMDSId ?? undefined : undefined}
/>
),
},
].filter(Boolean)
: [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const InstallIntegrationFlyout = ({
datasourceName,
refreshInstances,
selectedDataSourceId,
selectedClusterName,
http,
}: {
closeFlyout: () => void;
Expand All @@ -116,6 +117,7 @@ export const InstallIntegrationFlyout = ({
refreshInstances: () => void;
http: HttpStart;
selectedDataSourceId?: string;
selectedClusterName?: string;
}) => {
const [availableIntegrations, setAvailableIntegrations] = useState({
hits: [],
Expand Down Expand Up @@ -157,6 +159,7 @@ export const InstallIntegrationFlyout = ({
/>
) : (
<SetupIntegrationForm
selectedClusterName={selectedClusterName}
selectedDataSourceId={selectedDataSourceId}
integration={installingIntegration}
unsetIntegration={() => setInstallingIntegration(null)}
Expand Down Expand Up @@ -189,12 +192,14 @@ export const InstalledIntegrationsTable = ({
datasourceName,
refreshInstances,
http,
selectedDataSourceId,
}: {
integrations: IntegrationInstanceResult[];
datasourceType: DatasourceType;
datasourceName: string;
refreshInstances: () => void;
http: HttpStart;
selectedDataSourceId?: string;
}) => {
const basePathLink = (link: string): string => {
if (http.basePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export function SetupIntegrationForm({
setIsInstalling,
http,
selectedDataSourceId,
selectedClusterName,
}: {
integration: string;
renderType: 'page' | 'flyout';
Expand All @@ -368,6 +369,7 @@ export function SetupIntegrationForm({
setIsInstalling?: (isInstalling: boolean, success?: boolean) => void;
http: HttpStart;
selectedDataSourceId?: string | undefined;
selectedClusterName?: string | undefined;
}) {
const [integConfig, setConfig] = useState({
displayName: `${integration} Integration`,
Expand Down Expand Up @@ -432,6 +434,7 @@ export function SetupIntegrationForm({
unsetIntegration={unsetIntegration}
setIsInstalling={setIsInstalling}
dataSourceMDSId={selectedDataSourceId}
dataSourceMDSLabel={selectedClusterName}
http={http}
/>
</EuiBottomBar>
Expand Down Expand Up @@ -464,6 +467,7 @@ export function SetupIntegrationForm({
unsetIntegration={unsetIntegration}
setIsInstalling={setIsInstalling}
dataSourceMDSId={selectedDataSourceId}
dataSourceMDSLabel={selectedClusterName}
http={http}
/>
</EuiFlyoutFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export async function mountManagementSection(
setBreadcrumbs={params.setBreadcrumbs}
application={application}
useNewUX={useNewUX}
savedObjects={savedObjects}
/>
</Route>
{canManageDataSource && (
Expand Down

0 comments on commit 0bf5a58

Please sign in to comment.