Skip to content

Commit

Permalink
Show conn type name in options and details (opendatahub-io#3390)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilys314 authored Oct 28, 2024
1 parent 62d93ff commit 7e65faf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import {
DescriptionListTerm,
HelperText,
HelperTextItem,
LabelGroup,
Popover,
} from '@patternfly/react-core';
import { getDescriptionFromK8sResource, getDisplayNameFromK8sResource } from '~/concepts/k8s/utils';
import TruncatedText from '~/components/TruncatedText';
import { Connection, ConnectionTypeConfigMapObj } from './types';
import CategoryLabel from './CategoryLabel';
import { getConnectionTypeDisplayName } from './utils';

type Props = {
connection: Connection;
Expand All @@ -23,6 +22,7 @@ type Props = {
export const ConnectionDetailsHelperText: React.FC<Props> = ({ connection, connectionType }) => {
const displayName = getDisplayNameFromK8sResource(connection);
const description = getDescriptionFromK8sResource(connection);
const connectionTypeName = getConnectionTypeDisplayName(connection, connectionType);

return (
<HelperText>
Expand All @@ -48,17 +48,7 @@ export const ConnectionDetailsHelperText: React.FC<Props> = ({ connection, conne
) : undefined}
<DescriptionListGroup>
<DescriptionListTerm>Type</DescriptionListTerm>
<DescriptionListDescription>
{connectionType?.data?.category?.length ? (
<LabelGroup>
{connectionType.data.category.map((category) => (
<CategoryLabel key={category} category={category} />
))}
</LabelGroup>
) : (
'-'
)}
</DescriptionListDescription>
<DescriptionListDescription>{connectionTypeName}</DescriptionListDescription>
</DescriptionListGroup>
</DescriptionList>
}
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/concepts/connectionTypes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,14 @@ export const parseConnectionSecretValues = (

export const getConnectionTypeDisplayName = (
connection: Connection,
connectionTypes: ConnectionTypeConfigMapObj[],
connectionTypes?: ConnectionTypeConfigMapObj[] | ConnectionTypeConfigMapObj,
): string => {
const matchingType = connectionTypes.find(
(type) =>
type.metadata.name === connection.metadata.annotations['opendatahub.io/connection-type'],
);
const matchingType = Array.isArray(connectionTypes)
? connectionTypes.find(
(type) =>
type.metadata.name === connection.metadata.annotations['opendatahub.io/connection-type'],
)
: connectionTypes;
return (
matchingType?.metadata.annotations?.['openshift.io/display-name'] ||
connection.metadata.annotations['opendatahub.io/connection-type']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import React from 'react';
import { Button, FormGroup, FormSection, Popover, Radio } from '@patternfly/react-core';
import {
Button,
Flex,
FlexItem,
FormGroup,
FormSection,
Popover,
Radio,
Truncate,
} from '@patternfly/react-core';
import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons';
import {
getDescriptionFromK8sResource,
getDisplayNameFromK8sResource,
getResourceNameFromK8sResource,
} from '~/concepts/k8s/utils';
Expand All @@ -16,6 +26,7 @@ import { useK8sNameDescriptionFieldData } from '~/concepts/k8s/K8sNameDescriptio
import { isK8sNameDescriptionDataValid } from '~/concepts/k8s/K8sNameDescriptionField/utils';
import {
assembleConnectionSecret,
getConnectionTypeDisplayName,
getDefaultValues,
isConnectionTypeDataField,
S3ConnectionTypeKeys,
Expand Down Expand Up @@ -54,13 +65,26 @@ const ExistingConnectionField: React.FC<ExistingConnectionFieldProps> = ({
projectConnections.map((connection) => ({
content: getDisplayNameFromK8sResource(connection),
value: getResourceNameFromK8sResource(connection),
description: connection.metadata.annotations['openshift.io/description'],
description: (
<Flex direction={{ default: 'column' }} rowGap={{ default: 'rowGapNone' }}>
{getDescriptionFromK8sResource(connection) && (
<FlexItem>
<Truncate content={getDescriptionFromK8sResource(connection)} />
</FlexItem>
)}
<FlexItem>
<Truncate
content={`Type: ${getConnectionTypeDisplayName(connection, connectionTypes)}`}
/>
</FlexItem>
</Flex>
),
isSelected:
!!selectedConnection &&
getResourceNameFromK8sResource(connection) ===
getResourceNameFromK8sResource(selectedConnection),
})),
[projectConnections, selectedConnection],
[connectionTypes, projectConnections, selectedConnection],
);
const selectedConnectionType = React.useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('ConnectionsFormSection', () => {
expect(result.getByRole('textbox', { name: 'folder-path' })).toHaveValue('');

await act(async () => result.getByRole('button', { name: 'Typeahead menu toggle' }).click());
await act(async () => result.getByRole('option', { name: 's3-connection' }).click());
await act(async () => result.getByRole('option', { name: 's3-connection Type: s3' }).click());
expect(mockSetData).toHaveBeenLastCalledWith('storage', {
type: InferenceServiceStorageType.EXISTING_STORAGE,
path: '',
Expand Down

0 comments on commit 7e65faf

Please sign in to comment.