Skip to content

Commit

Permalink
Fixes #36350 - Add line breaks to long bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalyjur authored and MariaAga committed Aug 25, 2023
1 parent 5313801 commit 9447c82
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import EllipisWithTooltip from 'react-ellipsis-with-tooltip';
import { PlusIcon } from '@patternfly/react-icons';
import {
DropdownItem,
Expand All @@ -10,6 +9,7 @@ import {
import { sprintf, translate as __ } from '../../../common/I18n';
import { STATUS } from '../../../constants';
import DocumentationUrl from '../DocumentationLink';
import './bookmarks.scss';

export const addBookmarkItem = ({ setModalOpen }) => (
<DropdownGroup key="create-bookmark">
Expand Down Expand Up @@ -39,27 +39,40 @@ const pendingItem = (
</DropdownItem>
);

const bookmarksList = ({ bookmarks, onBookmarkClick }) =>
(bookmarks.length > 0 &&
bookmarks.map(({ name, query }) => (
<DropdownItem
ouiaId={`${name}-dropdown-item`}
key={name}
onClick={() => onBookmarkClick(query)}
>
<EllipisWithTooltip>{name}</EllipisWithTooltip>
const bookmarksList = ({ bookmarks, onBookmarkClick }) => {
const hasLongerName = bookmarks.some(bookmark => bookmark.name.length > 90);

return (
(bookmarks.length > 0 &&
bookmarks.map(({ name, query }) => (
<DropdownItem
ouiaId={`${name}-dropdown-item`}
className={`bookmarks-dropdown-item ${
hasLongerName ? 'adapt-long-bookmark' : ''
}`}
key={name}
onClick={() => onBookmarkClick(query)}
>
{name}
</DropdownItem>
))) || (
<DropdownItem ouiaId="not-found-dropdown-item" key="not found" isDisabled>
{__('None found')}
</DropdownItem>
))) || (
<DropdownItem ouiaId="not-found-dropdown-item" key="not found" isDisabled>
{__('None found')}
</DropdownItem>
)
);
};

const errorItem = errors => (
<DropdownItem ouiaId="error-dropdown-item" key="bookmarks-errors" isDisabled>
<EllipisWithTooltip>
{sprintf('Failed to load bookmarks: %s', errors)}
</EllipisWithTooltip>
<DropdownItem
ouiaId="error-dropdown-item"
className={`bookmarks-dropdown-item ${
errors.length > 90 ? 'adapt-long-bookmark' : ''
}`}
key="bookmarks-errors"
isDisabled
>
{sprintf('Failed to load bookmarks: %s', errors)}
</DropdownItem>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import '~@theforeman/vendor/scss/variables';

.bookmarks-dropdown-item {
word-break: break-word;
overflow-wrap: break-word;
white-space: nowrap;
}

.bookmarks-dropdown-item.adapt-long-bookmark {
width: 450px;
white-space: normal;
}

@media only screen and (min-width: $pf-global--breakpoint--xl) {
.bookmarks-dropdown-item.adapt-long-bookmark {
width: 600px;
white-space: normal;
}
}

@media only screen and (min-width: $pf-global--breakpoint--2xl) {
.bookmarks-dropdown-item.adapt-long-bookmark {
width: 700px;
white-space: normal;
}
}

0 comments on commit 9447c82

Please sign in to comment.