-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix: long headers values #76
Changes from 4 commits
8eb531f
7af5521
c229b1f
64db05e
807997e
bf43df5
ec3b257
e035e1e
737b8c3
3e2d318
3dfa2cd
180516e
183c98c
3c6c2de
7b7056f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import React from 'react'; | |
|
||
import {HelpPopover} from '@gravity-ui/components'; | ||
import {ChevronDown} from '@gravity-ui/icons'; | ||
import {Button, Card as CardBase, Icon} from '@gravity-ui/uikit'; | ||
import {Button, Card as CardBase, Icon, Popover, type PopoverProps} from '@gravity-ui/uikit'; | ||
import _ from 'lodash'; | ||
|
||
import {block} from '../../utils'; | ||
|
@@ -24,6 +24,9 @@ export interface CardProps { | |
checkEmptyBody?: boolean; | ||
} | ||
|
||
const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; | ||
const MAX_TITLE_WIDTH = 533; | ||
|
||
export const Card: React.FC<CardProps> = ({ | ||
name, | ||
title: propsTitle, | ||
|
@@ -37,6 +40,7 @@ export const Card: React.FC<CardProps> = ({ | |
children, | ||
}) => { | ||
const containerRef = React.useRef<HTMLDivElement>(null); | ||
const titleRef = React.useRef<HTMLDivElement>(null); | ||
const bodyRef = React.useRef<HTMLDivElement>(null); | ||
const [open, setOpen] = React.useState(alwaysOpen || propsOpen || false); | ||
|
||
|
@@ -66,22 +70,26 @@ export const Card: React.FC<CardProps> = ({ | |
[], | ||
); | ||
|
||
const titlePopoverDisabled = (titleRef.current?.offsetWidth || 0) < MAX_TITLE_WIDTH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
const title = React.useMemo(() => { | ||
if (_.isString(propsTitle)) { | ||
return ( | ||
<React.Fragment> | ||
<div className={b('title')}>{propsTitle}</div> | ||
<Popover content={propsTitle} disabled={titlePopoverDisabled}> | ||
<div className={b('title')}>{propsTitle}</div> | ||
</Popover> | ||
{description ? ( | ||
<div className={b('note')}> | ||
<HelpPopover htmlContent={description} placement={['bottom', 'top']} /> | ||
<HelpPopover htmlContent={description} placement={POPOVER_PLACEMENT} /> | ||
</div> | ||
) : null} | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
return propsTitle; | ||
}, [propsTitle, description]); | ||
}, [propsTitle, titlePopoverDisabled, description]); | ||
|
||
React.useEffect(() => { | ||
if (!alwaysOpen && propsOpen !== undefined && propsOpen !== open) { | ||
|
@@ -112,7 +120,9 @@ export const Card: React.FC<CardProps> = ({ | |
className={b('header', {interactive: Boolean(handleHeaderToggle)})} | ||
onClick={handleHeaderToggle} | ||
> | ||
<div className={b('header-left')}>{title}</div> | ||
<div ref={titleRef} className={b('header-left')}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{title} | ||
</div> | ||
<div className={b('header-right')} onClick={preventEvent}> | ||
{actions ? <div className={b('actions')}>{actions}</div> : null} | ||
{alwaysOpen ? null : ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import React from 'react'; | ||
|
||
import {HelpPopover} from '@gravity-ui/components'; | ||
import {Popover, type PopoverProps} from '@gravity-ui/uikit'; | ||
|
||
import {GroupIndent} from '../../'; | ||
import {ErrorWrapper} from '../../../'; | ||
import { | ||
FieldRenderProps, | ||
FieldValue, | ||
FormValue, | ||
LayoutProps, | ||
Spec, | ||
ViewLayoutProps, | ||
type FieldRenderProps, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not change code that is not related to the current task |
||
type FieldValue, | ||
type FormValue, | ||
type LayoutProps, | ||
type Spec, | ||
type ViewLayoutProps, | ||
isArraySpec, | ||
isObjectSpec, | ||
} from '../../../../core'; | ||
|
@@ -27,6 +28,9 @@ interface SectionProps { | |
descriptionAsSubtitle?: boolean; | ||
} | ||
|
||
const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; | ||
const MAX_TITLE_WIDTH = 533; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to common constants |
||
|
||
const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>({ | ||
name, | ||
spec, | ||
|
@@ -39,6 +43,7 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>( | |
}: (LayoutProps<D, S> | ViewLayoutProps<T, S>) & SectionProps) => { | ||
const meta = (restProps as FieldRenderProps<D>).meta as FieldRenderProps<D>['meta'] | undefined; | ||
const arrOrObjFlag = isArraySpec(spec) || isObjectSpec(spec); | ||
const titleRef = React.useRef<HTMLHeadingElement>(null); | ||
let content = children; | ||
|
||
if (meta) { | ||
|
@@ -76,15 +81,26 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>( | |
} | ||
} | ||
|
||
const layoutTitle = spec.viewSpec.layoutTitle; | ||
const layoutTitlePopoverDisabled = (titleRef.current?.offsetWidth || 0) < MAX_TITLE_WIDTH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return ( | ||
<section className={b()}> | ||
{spec.viewSpec.layoutTitle ? ( | ||
{layoutTitle ? ( | ||
<div | ||
className={b('header', { | ||
'with-popover': !descriptionAsSubtitle, | ||
})} | ||
> | ||
<h2 className={b('title', {size: titleSize})}>{spec.viewSpec.layoutTitle}</h2> | ||
<Popover | ||
content={layoutTitle} | ||
placement={POPOVER_PLACEMENT} | ||
disabled={layoutTitlePopoverDisabled} | ||
> | ||
<h2 className={b('title', {size: titleSize})} ref={titleRef}> | ||
{layoutTitle} | ||
</h2> | ||
</Popover> | ||
{description} | ||
</div> | ||
) : null} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ $animationDuration: 0.3s; | |
|
||
&-inner { | ||
margin-left: -13px; | ||
max-width: 543px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is there 543 here while everywhere is 533? |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import React from 'react'; | |
|
||
import {HelpPopover} from '@gravity-ui/components'; | ||
import {ChevronDown} from '@gravity-ui/icons'; | ||
import {Button, Icon} from '@gravity-ui/uikit'; | ||
import {Button, Icon, Popover, type PopoverProps} from '@gravity-ui/uikit'; | ||
|
||
import {block} from '../../utils'; | ||
|
||
|
@@ -34,6 +34,9 @@ interface SimpleVerticalAccordeonState { | |
isFirstRender: boolean; | ||
} | ||
|
||
const MAX_TITLE_TEXT_WIDTH = 495; /** 543px max-width - 48px of padding */ | ||
const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; | ||
|
||
export class SimpleVerticalAccordeon extends React.Component< | ||
SimpleVerticalAccordeonProps, | ||
SimpleVerticalAccordeonState | ||
|
@@ -45,6 +48,7 @@ export class SimpleVerticalAccordeon extends React.Component< | |
}; | ||
|
||
componentRef = React.createRef<HTMLDivElement>(); | ||
titleRef = React.createRef<HTMLElement>(); | ||
|
||
constructor(props: SimpleVerticalAccordeonProps) { | ||
super(props); | ||
|
@@ -97,19 +101,38 @@ export class SimpleVerticalAccordeon extends React.Component< | |
return null; | ||
} | ||
|
||
const title = this.getTitle(); | ||
const titlePopoverDisabled = | ||
(this.titleRef.current?.offsetWidth || 0) < MAX_TITLE_TEXT_WIDTH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return ( | ||
Boolean(React.Children.count(children)) && ( | ||
<div className={b({branch: withBranchView, view: viewLayout}, className)}> | ||
<div className={b('header')}> | ||
<Button | ||
view="flat" | ||
className={b('header-inner', buttonClassName)} | ||
onClick={this.handleClick} | ||
qa={`${name}-accordeon-toggler`} | ||
<Popover | ||
content={title} | ||
disabled={titlePopoverDisabled} | ||
placement={POPOVER_PLACEMENT} | ||
> | ||
<b className={b('title', {size: titleSize})}>{this.getTitle()}</b> | ||
<Icon data={ChevronDown} className={b('chevron', {open})} size={16} /> | ||
</Button> | ||
<Button | ||
view="flat" | ||
className={b('header-inner', buttonClassName)} | ||
onClick={this.handleClick} | ||
qa={`${name}-accordeon-toggler`} | ||
width="auto" | ||
> | ||
{' '} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the extra space |
||
<b ref={this.titleRef} className={b('title', {size: titleSize})}> | ||
{title} | ||
</b> | ||
<Icon | ||
data={ChevronDown} | ||
className={b('chevron', {open})} | ||
size={16} | ||
/> | ||
</Button> | ||
</Popover> | ||
|
||
{this.getTooltip()} | ||
{headerActionsTemplate ? headerActionsTemplate : null} | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
|
||
import {Popover} from '@gravity-ui/uikit'; | ||
import {Popover, type PopoverProps} from '@gravity-ui/uikit'; | ||
|
||
import {ArrayView} from '../../../../core'; | ||
import {block} from '../../../utils'; | ||
|
@@ -9,6 +9,8 @@ import './MultiSelectView.scss'; | |
|
||
const b = block('multiselect-view'); | ||
|
||
const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to the current task, you should remove them, if you want to change imports and parameters, it is better to do it in a separate task |
||
|
||
export const MultiSelectView: ArrayView = ({spec, value = []}) => { | ||
const _value = value as string[]; | ||
|
||
|
@@ -21,7 +23,7 @@ export const MultiSelectView: ArrayView = ({spec, value = []}) => { | |
<React.Fragment> | ||
{items.map((item) => ( | ||
<Popover | ||
placement={['bottom', 'top']} | ||
placement={POPOVER_PLACEMENT} | ||
key={item} | ||
content={item} | ||
className={b('tooltip-container')} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
|
||
import {Popover} from '@gravity-ui/uikit'; | ||
import {Popover, type PopoverProps} from '@gravity-ui/uikit'; | ||
|
||
import {StringViewProps} from '../../../../core'; | ||
import {block, isCorrectSizeParams} from '../../../utils'; | ||
|
@@ -10,14 +10,16 @@ import './NumberWithScaleView.scss'; | |
|
||
const b = block('number-with-scale-view'); | ||
|
||
const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to the current task, you should remove them, if you want to change imports and parameters, it is better to do it in a separate task |
||
|
||
const NumberWithScaleViewBase: React.FC<StringViewProps> = ({spec, value}) => { | ||
const {initialValue, initialType} = useInitial(value || '', spec, [value]); | ||
const {scale} = spec.viewSpec.sizeParams!; | ||
|
||
return ( | ||
<div className={b()}> | ||
<Popover | ||
placement={['bottom', 'top']} | ||
placement={POPOVER_PLACEMENT} | ||
content={initialValue} | ||
className={b('tooltip-container')} | ||
contentClassName={b('tooltip')} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a separate file of constants you need to take out there