Skip to content

fix(MessageView): don't show unnecessary scrollbar in details view #5355

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

Merged
merged 1 commit into from
Dec 15, 2023
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
28 changes: 24 additions & 4 deletions .storybook/mockData/generateMessageItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ const informationMessageItems = (count) => {
return [];
}
return new Array(count).fill('').map((_, index) => (
<MessageItem titleText={'Information Message'} type={ValueState.Information} groupName={`Group${index}`}>
<MessageItem
key={`InformationMessage${index}`}
titleText={'Information Message'}
type={ValueState.Information}
groupName={`Group${index}`}
>
{LoremIpsum}
</MessageItem>
));
Expand All @@ -24,7 +29,12 @@ const successMessageItems = (count) => {
return [];
}
return new Array(count).fill('').map((_, index) => (
<MessageItem titleText={'Success Message'} type={ValueState.Success} groupName={`Group${index}`}>
<MessageItem
key={`SuccessMessage${index}`}
titleText={'Success Message'}
type={ValueState.Success}
groupName={`Group${index}`}
>
{LoremIpsum}
</MessageItem>
));
Expand All @@ -35,7 +45,12 @@ const warningMessageItems = (count) => {
return [];
}
return new Array(count).fill('').map((_, index) => (
<MessageItem titleText={'Warning Message'} type={ValueState.Warning} groupName={`Group${index}`}>
<MessageItem
key={`WarningMessage${index}`}
titleText={'Warning Message'}
type={ValueState.Warning}
groupName={`Group${index}`}
>
{LoremIpsum}
</MessageItem>
));
Expand All @@ -46,7 +61,12 @@ const errorMessageItems = (count) => {
return [];
}
return new Array(count).fill('').map((_, index) => (
<MessageItem titleText={'Error Message'} type={ValueState.Error} groupName={`Group${index}`}>
<MessageItem
key={`ErrorMessage${index}`}
titleText={'Error Message'}
type={ValueState.Error}
groupName={`Group${index}`}
>
{LoremIpsum}
</MessageItem>
));
Expand Down
9 changes: 5 additions & 4 deletions packages/main/src/components/MessageView/MessageView.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ describe('MessageView', () => {
};
cy.mount(<TestComp />);
cy.findByText('Error').click();
cy.findAllByText('Error').should('have.length', 2);
cy.findAllByText('Error').should('have.length', 1);
cy.findByText('Error Message').should('be.visible');
cy.get('[ui5-button]').click();
cy.findAllByText('Error').should('have.length', 1);
cy.findByText('Error Message').should('not.exist');
cy.get('@select').should('have.been.calledOnce');
cy.findByText('Information').click();
cy.findAllByText('Information').should('have.length', 2);
cy.findAllByText('Information').should('have.length', 1);
cy.findByText('Information Message').should('be.visible');
cy.findByText('nav back').click();
cy.findAllByText('Information').should('have.length', 1);
Expand Down Expand Up @@ -142,6 +142,7 @@ describe('MessageView', () => {
cy.get('[ui5-bar]').should('not.exist');
});
});

it('MessageItem', () => {
cy.mount(
<MessageView>
Expand All @@ -160,7 +161,7 @@ describe('MessageView', () => {
cy.findByText('SubtitleText').should('be.visible');
cy.findByText('1337').should('be.visible');
cy.get('[name="slim-arrow-right"]').should('be.visible').click();
cy.findByText('SubtitleText').should('not.be.visible');
cy.findByText('1337').should('not.be.visible');
cy.findByText('SubtitleText').should('not.exist');
cy.findByText('1337').should('not.exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export const WithMessageViewButton: Story = {
}
>
<MessageView
style={{ height: '500px', maxWidth: '600px' }}
ref={messageViewRef}
showDetailsPageHeader={false}
groupItems
Expand Down
110 changes: 66 additions & 44 deletions packages/main/src/components/MessageView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { clsx } from 'clsx';
import type { ReactElement, ReactNode } from 'react';
import React, { Children, forwardRef, Fragment, isValidElement, useCallback, useEffect, useState } from 'react';
import { createUseStyles } from 'react-jss';
import { ButtonDesign, FlexBoxDirection, TitleLevel, ValueState, WrappingType } from '../../enums/index.js';
import {
ButtonDesign,
FlexBoxDirection,
GlobalStyleClasses,
TitleLevel,
ValueState,
WrappingType
} from '../../enums/index.js';
import { ALL, LIST_NO_DATA } from '../../i18n/i18n-defaults.js';
import type { CommonProps } from '../../interfaces/index.js';
import { MessageViewContext } from '../../internal/MessageViewContext.js';
Expand Down Expand Up @@ -115,7 +122,7 @@ const useStyles = createUseStyles(
'&[data-key="Success"]:not([pressed])': { color: ThemingParameters.sapPositiveElementColor },
'&[data-key="Information"]:not([pressed])': { color: ThemingParameters.sapInformativeElementColor }
},
detailsContainer: {
details: {
padding: '1rem'
},
detailsIcon: {
Expand All @@ -136,6 +143,12 @@ const useStyles = createUseStyles(
lineHeight: 1.4,
color: ThemingParameters.sapTextColor,
marginBlockEnd: '1rem'
},
messagesContainer: {
height: '100%'
},
detailsContainer: {
height: '100%'
}
},
{ name: 'MessageView' }
Expand Down Expand Up @@ -188,7 +201,12 @@ const MessageView = forwardRef<MessageViewDomRef, MessageViewPropTypes>((props,
setListFilter(e.detail.selectedItem.dataset.key);
};

const outerClasses = clsx(classes.container, className, selectedMessage && classes.showDetails);
const outerClasses = clsx(
classes.container,
GlobalStyleClasses.sapScrollBar,
className,
selectedMessage && classes.showDetails
);

return (
<div ref={componentRef} {...rest} className={outerClasses}>
Expand All @@ -197,49 +215,53 @@ const MessageView = forwardRef<MessageViewDomRef, MessageViewPropTypes>((props,
selectMessage: setSelectedMessage
}}
>
<div style={{ visibility: selectedMessage ? 'hidden' : 'visible' }}>
{filledTypes > 1 && (
<Bar
startContent={
<SegmentedButton onSelectionChange={handleListFilterChange}>
<SegmentedButtonItem data-key="All" pressed={listFilter === 'All'}>
{i18nBundle.getText(ALL)}
</SegmentedButtonItem>
{/* @ts-expect-error: The key can't be typed, it's always `string`, but since the `ValueState` enum only contains strings it's fine to use here*/}
{Object.entries(messageTypes).map(([valueState, count]: [ValueState, number]) => {
if (count === 0) {
return null;
}
return (
<SegmentedButtonItem
key={valueState}
data-key={valueState}
pressed={listFilter === valueState}
icon={getIconNameForType(valueState)}
className={classes.button}
>
{count}
<div style={{ visibility: selectedMessage ? 'hidden' : 'visible' }} className={classes.messagesContainer}>
{!selectedMessage && (
<>
{filledTypes > 1 && (
<Bar
startContent={
<SegmentedButton onSelectionChange={handleListFilterChange}>
<SegmentedButtonItem data-key="All" pressed={listFilter === 'All'}>
{i18nBundle.getText(ALL)}
</SegmentedButtonItem>
);
})}
</SegmentedButton>
}
/>
{/* @ts-expect-error: The key can't be typed, it's always `string`, but since the `ValueState` enum only contains strings it's fine to use here*/}
{Object.entries(messageTypes).map(([valueState, count]: [ValueState, number]) => {
if (count === 0) {
return null;
}
return (
<SegmentedButtonItem
key={valueState}
data-key={valueState}
pressed={listFilter === valueState}
icon={getIconNameForType(valueState)}
className={classes.button}
>
{count}
</SegmentedButtonItem>
);
})}
</SegmentedButton>
}
/>
)}
<List onItemClick={onItemSelect} noDataText={i18nBundle.getText(LIST_NO_DATA)}>
{groupItems
? groupedMessages.map(([groupName, items]) => {
return (
<Fragment key={groupName}>
{groupName && <GroupHeaderListItem>{groupName}</GroupHeaderListItem>}
{items}
</Fragment>
);
})
: filteredChildren}
</List>
</>
)}
<List onItemClick={onItemSelect} noDataText={i18nBundle.getText(LIST_NO_DATA)}>
{groupItems
? groupedMessages.map(([groupName, items]) => {
return (
<Fragment key={groupName}>
{groupName && <GroupHeaderListItem>{groupName}</GroupHeaderListItem>}
{items}
</Fragment>
);
})
: filteredChildren}
</List>
</div>
<div>
<div className={classes.detailsContainer}>
{childrenArray.length > 0 ? (
<>
{showDetailsPageHeader && selectedMessage && (
Expand All @@ -250,7 +272,7 @@ const MessageView = forwardRef<MessageViewDomRef, MessageViewPropTypes>((props,
/>
)}
{selectedMessage && (
<FlexBox className={classes.detailsContainer}>
<FlexBox className={classes.details}>
<Icon
data-type={selectedMessage.type}
name={getIconNameForType(selectedMessage.type)}
Expand Down