Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address UX items with connection types #3201

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/app/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ body,
min-height: 0;
}

.pf-v5-c-truncate {
--pf-v5-c-truncate--MinWidth: 0;
--pf-v5-c-truncate__start--MinWidth: 0;
}
32 changes: 19 additions & 13 deletions frontend/src/concepts/connectionTypes/fields/DropdownFormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@
const hasValidOption = field.properties.items?.find((f) => f.value || f.label);

const menuToggleText = () => {
let text = field.name ? `Select ${field.name} ` : 'No values defined yet ';
if (!isMulti && isPreview) {
const defaultOption = field.properties.items?.find(
(i) => i.value === field.properties.defaultValue?.[0],
);
if (defaultOption) {
text = defaultOption.label || defaultOption.value;
}
} else if (!isMulti && !isPreview) {
const currentSelection = field.properties.items?.find((i) => value?.includes(i.value));
if (currentSelection) {
text = currentSelection.label || currentSelection.value;
let text = field.properties.items?.some((i) => i.label || i.value)
? field.name
? `Select ${field.name} `
: 'Select'

Check warning on line 25 in frontend/src/concepts/connectionTypes/fields/DropdownFormField.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/concepts/connectionTypes/fields/DropdownFormField.tsx#L25

Added line #L25 was not covered by tests
: 'No values defined';
if (!isMulti) {
if (isPreview) {
const defaultOption = field.properties.items?.find(
(i) => i.value === field.properties.defaultValue?.[0],
);
if (defaultOption) {
text = defaultOption.label || defaultOption.value;
}
} else {
const currentSelection = field.properties.items?.find((i) => value?.includes(i.value));
if (currentSelection) {
text = currentSelection.label || currentSelection.value;
}
}
}
return text;
Expand Down Expand Up @@ -74,7 +80,7 @@
<>
{menuToggleText()}
{isMulti && (
<Badge>
<Badge className="pf-v5-u-ml-xs">
{(isPreview ? field.properties.defaultValue?.length : value?.length) ?? 0}{' '}
selected
</Badge>
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/pages/connectionTypes/ConnectionTypesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Props = {

const ConnectionTypesTable: React.FC<Props> = ({ connectionTypes, onUpdate }) => {
const [filterData, setFilterData] = React.useState<FilterDataType>(initialFilterData);
const onClearFilters = React.useCallback(() => setFilterData(initialFilterData), [setFilterData]);
const onClearFilters = React.useCallback(() => setFilterData(initialFilterData), []);

const [deleteConnectionType, setDeleteConnectionType] = React.useState<
ConnectionTypeConfigMapObj | undefined
Expand All @@ -30,7 +30,7 @@ const ConnectionTypesTable: React.FC<Props> = ({ connectionTypes, onUpdate }) =>
() =>
connectionTypes.filter((connectionType) => {
const keywordFilter = filterData.Keyword?.toLowerCase();
const createFilter = filterData['Created by']?.toLowerCase();
const createFilter = filterData.Creator?.toLowerCase();
const categoryFilter = filterData.Category?.toLowerCase();

if (
Expand Down Expand Up @@ -58,10 +58,6 @@ const ConnectionTypesTable: React.FC<Props> = ({ connectionTypes, onUpdate }) =>
[connectionTypes, filterData],
);

const resetFilters = () => {
setFilterData(initialFilterData);
};

return (
<>
<Table
Expand All @@ -88,7 +84,7 @@ const ConnectionTypesTable: React.FC<Props> = ({ connectionTypes, onUpdate }) =>
/>
}
disableItemCount
emptyTableView={<DashboardEmptyTableView onClearFilters={resetFilters} />}
emptyTableView={<DashboardEmptyTableView onClearFilters={onClearFilters} />}
id="connectionTypes-list-table"
/>
{deleteConnectionType ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
onChange={(_event, value) => onChange(value)}
/>
),
[ConnectionTypesOptions.createdBy]: ({ onChange, ...props }) => (
[ConnectionTypesOptions.creator]: ({ onChange, ...props }) => (

Check warning on line 45 in frontend/src/pages/connectionTypes/ConnectionTypesTableToolbar.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/connectionTypes/ConnectionTypesTableToolbar.tsx#L45

Added line #L45 was not covered by tests
<SearchInput
{...props}
aria-label="Created by"
placeholder="Created by"
aria-label="Creator"
placeholder="Creator"
onChange={(_event, value) => onChange(value)}
/>
),
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/connectionTypes/const.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
export enum ConnectionTypesOptions {
keyword = 'Keyword',
category = 'Category',
createdBy = 'Created by',
creator = 'Creator',
}

export const options = {
[ConnectionTypesOptions.keyword]: 'Keyword',
[ConnectionTypesOptions.category]: 'Category',
[ConnectionTypesOptions.createdBy]: 'Created By',
[ConnectionTypesOptions.creator]: 'Creator',
};

export type FilterDataType = Record<ConnectionTypesOptions, string | undefined>;

export const initialFilterData: Record<ConnectionTypesOptions, string | undefined> = {
[ConnectionTypesOptions.keyword]: '',
[ConnectionTypesOptions.category]: '',
[ConnectionTypesOptions.createdBy]: '',
[ConnectionTypesOptions.creator]: '',
};

export const categoryOptions = ['Object storage', 'Database', 'Model registry', 'URI'];
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ export const ConnectionTypeMoveFieldToSectionModal: React.FC<Props> = ({
/>
}
>
Select the section heading that <b>{row.field.name}</b> will be moved to.
<Form>
<div>
Select the section heading that <b>{row.field.name}</b> will be moved to.
</div>
<FormGroup fieldId="sectionHeading" label="Section heading" isRequired>
<SimpleSelect
id="sectionHeading"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { ExclamationCircleIcon } from '@patternfly/react-icons';
import { ActionsColumn, Td, Tr } from '@patternfly/react-table';
import { Button, Icon, Label, Switch } from '@patternfly/react-core';
import { ActionsColumn, TableText, Td, Tr } from '@patternfly/react-table';
import { Button, Flex, FlexItem, Icon, Label, Switch, Truncate } from '@patternfly/react-core';
import {
ConnectionTypeField,
ConnectionTypeFieldType,
Expand Down Expand Up @@ -90,7 +90,7 @@ const ManageConnectionTypeFieldsTableRow: React.FC<Props> = ({
},
{
title: 'Duplicate',
onClick: () => onDuplicate({ ...row, name: `Duplicate of ${row.name}` }),
onClick: () => onDuplicate({ ...row, name: `Copy of ${row.name}` }),
},
{
title: 'Remove',
Expand Down Expand Up @@ -133,19 +133,26 @@ const ManageConnectionTypeFieldsTableRow: React.FC<Props> = ({
<Td dataLabel={columns[1].label} data-testid="field-type">
{fieldTypeToString(row.type)}
</Td>
<Td dataLabel={columns[2].label} data-testid="field-default" modifier="truncate">
{defaultValueToString(row) || '-'}
<Td dataLabel={columns[2].label} data-testid="field-default">
<TableText wrapModifier="truncate">{defaultValueToString(row) || '-'}</TableText>
</Td>
<Td dataLabel={columns[3].label} data-testid="field-env">
{row.envVar || '-'}
{isEnvVarConflict ? (
<>
<Icon status="danger" size="sm" className="pf-v5-u-ml-xs">
<ExclamationCircleIcon />
</Icon>
<span className="pf-v5-u-screen-reader">This environment variable is in conflict.</span>
</>
) : undefined}
<Flex gap={{ default: 'gapSm' }} flexWrap={{ default: 'nowrap' }}>
<FlexItem>
<Truncate content={row.envVar || '-'} />
</FlexItem>
{isEnvVarConflict ? (
<FlexItem>
<Icon
status="danger"
size="sm"
aria-label="This environment variable is in conflict."
>
<ExclamationCircleIcon />
</Icon>
</FlexItem>
) : undefined}
</Flex>
</Td>
<Td dataLabel={columns[4].label}>
<Switch
Expand All @@ -164,7 +171,7 @@ const ManageConnectionTypeFieldsTableRow: React.FC<Props> = ({
},
{
title: 'Duplicate',
onClick: () => onDuplicate(row),
onClick: () => onDuplicate({ ...row, name: `Copy of ${row.name}` }),
},
...(showMoveToSection
? [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ describe('ManageConnectionTypeFieldsTableRow', () => {
};

const result = render(renderRow({ row: field, fields: [field] }));
expect(screen.getByTestId('field-env')).not.toHaveTextContent('conflict');
expect(screen.queryByLabelText(/conflict/)).not.toBeInTheDocument();

result.rerender(renderRow({ row: field, fields: [field, field2] }));
expect(screen.getByTestId('field-env')).toHaveTextContent('conflict');
expect(screen.queryByLabelText(/conflict/)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ThProps } from '@patternfly/react-table';

export const columns: ThProps[] = [
{ label: 'Section heading/field name', width: 30 },
{ label: 'Section heading / field name', width: 30 },
{ label: 'Type', width: 10 },
{ label: 'Default value', width: 30 },
{ label: 'Environment variable', width: 20 },
Expand Down
Loading