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

feat(ChangelogDialog): change style, add link, events #105

Merged
merged 8 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 12 additions & 2 deletions src/components/ChangelogDialog/ChangelogDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import React, {useEffect} from 'react';

import {ArrowUpRightFromSquare} from '@gravity-ui/icons';
import {Dialog, Icon, Link} from '@gravity-ui/uikit';
import type {DialogProps} from '@gravity-ui/uikit';
import {Dialog, Icon, Link} from '@gravity-ui/uikit';

import {block} from '../utils/cn';

Expand All @@ -21,7 +21,9 @@ export interface ChangelogDialogProps {
items: ChangelogItem[];
disableBodyScrollLock?: boolean;
disableOutsideClick?: boolean;
onOpen: () => void;
onClose: DialogProps['onClose'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove, will do in parent component

onLinkClick?: (link: string) => void;
onStoryClick?: (storyId: string) => void;
}

Expand All @@ -38,12 +40,19 @@ export function ChangelogDialog({
disableBodyScrollLock = true,
disableOutsideClick,
onClose,
onOpen,
onStoryClick,
onLinkClick,
}: ChangelogDialogProps) {
const idRef = React.useRef<number>();
idRef.current = idRef.current || getNextId();
const dialogCaptionId = `changelog-dialog-title-${idRef.current}`;

useEffect(() => {
if (!open) return;
onOpen();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the reason to add callback, if you pass open from outside anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is no need to keep this code inside the component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

}, [open, onOpen]);

return (
<Dialog
className={b()}
Expand Down Expand Up @@ -72,6 +81,7 @@ export function ChangelogDialog({
className={b('item')}
data={item}
onStoryClick={onStoryClick}
onLinkClick={onLinkClick}
/>
))
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ const items: ChangelogItem[] = [
description:
'At the top of the panel is the service navigation for each service. Below are common navigation elements: a component for switching between accounts and organizations, settings, help center, search, notifications, favorites.',
storyId: 'someStoryId1',
link: 'https://github.com/gravity-ui/uikit',
},
{
date: '23 Jun 2022',
isNew: true,
title: 'New components',
description:
'At the top of the panel is the service navigation for each service. Below are common navigation elements: a component for switching between accounts and organizations, settings, help center, search, notifications, favorites.',
link: 'https://github.com/gravity-ui/uikit',
},
{
date: '15 Jun 2022',
Expand Down Expand Up @@ -65,6 +67,7 @@ const items: ChangelogItem[] = [
description:
'At the top of the panel is the service navigation for each service. Below are common navigation elements: a component for switching between accounts and organizations, settings, help center, search, notifications, favorites.',
storyId: 'someStoryId3',
link: 'https://github.com/gravity-ui/uikit',
},
{
date: '10 May 2022',
Expand Down Expand Up @@ -95,8 +98,9 @@ const DefaultTemplate: StoryFn<ChangelogDialogProps> = (props: ChangelogDialogPr
<ChangelogDialog
{...props}
open={visible}
onClose={() => {
onClose={(event, reason) => {
setVisible(false);
props.onClose?.(event, reason);
}}
/>
</React.Fragment>
Expand All @@ -108,8 +112,20 @@ export const Default = DefaultTemplate.bind({});
Default.args = {
open: false,
items,
fullListLink: 'https://github.com/gravity-ui/uikit',
onStoryClick: (storyId) => {
console.log(storyId);
// eslint-disable-next-line no-console
console.log('story click', storyId);
},
onLinkClick: (link) => {
// eslint-disable-next-line no-console
console.log('link click', link);
},
onOpen: () => {
// eslint-disable-next-line no-console
console.log('open');
},
onClose: () => {
// eslint-disable-next-line no-console
console.log('close');
},
};
14 changes: 9 additions & 5 deletions src/components/ChangelogDialog/components/Item/Item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@use '../../../variables';

$block: '.#{variables.$ns}changelog-dialog-item';
$metaWidth: 124px;
$metaWidth: 80px;

#{$block} {
display: flex;
Expand All @@ -17,17 +17,17 @@ $metaWidth: 124px;
}

&__label-new {
margin-top: 4px;
margin-top: 8px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should use --g-spacing-2

}

&__content {
flex: 1;
margin-left: 16px;
margin-left: 20px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should use --g-spacing-5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this and other places too.

}

&__title {
margin: 0;
@include mixins.text-subheader-3();
@include mixins.text-subheader-2();
}

&__image {
Expand All @@ -40,7 +40,11 @@ $metaWidth: 124px;
margin-top: 12px;
}

&__story-button {
&__button {
margin-top: 16px;
}

&__button + &__button {
margin-left: 16px;
}
}
36 changes: 28 additions & 8 deletions src/components/ChangelogDialog/components/Item/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useCallback} from 'react';

import {CirclePlay} from '@gravity-ui/icons';
import {Button, Icon, Label} from '@gravity-ui/uikit';
Expand All @@ -16,9 +16,22 @@ export interface ItemProps {
className?: string;
data: ChangelogItem;
onStoryClick?: (storyId: string) => void;
onLinkClick?: (link: string) => void;
}

export function Item({className, data, onStoryClick}: ItemProps) {
export function Item({className, data, onStoryClick, onLinkClick}: ItemProps) {
const handleLinkClick = useCallback(() => {
if (onLinkClick && data.link) {
onLinkClick(data.link);
}
}, [data.link, onLinkClick]);

const handleStoryClick = useCallback(() => {
if (onStoryClick && data.storyId) {
onStoryClick(data.storyId);
}
}, [data.storyId, onStoryClick]);

return (
<article className={b(null, className)}>
<div className={b('meta')}>
Expand All @@ -42,15 +55,22 @@ export function Item({className, data, onStoryClick}: ItemProps) {
{data.description ? (
<div className={b('description')}>{data.description}</div>
) : null}
{data.link ? (
<Button
className={b('button')}
view="outlined"
href={data.link}
target={'_blank'}
onClick={handleLinkClick}
>
{i18n('action_read-more')}
</Button>
) : null}
{data.storyId && onStoryClick ? (
<Button
className={b('story-button')}
className={b('button')}
view="outlined-action"
onClick={() => {
if (data.storyId) {
onStoryClick(data.storyId);
}
}}
onClick={handleStoryClick}
>
{i18n('button_view_story')}
<Icon data={CirclePlay} size={14} />
Expand Down
3 changes: 2 additions & 1 deletion src/components/ChangelogDialog/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"link_full_list": "View full changelog",
"label_new": "New",
"button_view_story": "View story",
"label_empty": "No data"
"label_empty": "No data",
"action_read-more": "Read more"
}
3 changes: 2 additions & 1 deletion src/components/ChangelogDialog/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"link_full_list": "Открыть полный список изменений",
"label_new": "New",
"button_view_story": "Посмотреть сториз",
"label_empty": "Нет данных"
"label_empty": "Нет данных",
"action_read-more": "Читать далее"
}
1 change: 1 addition & 0 deletions src/components/ChangelogDialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface ChangelogItem {
image?: ImageData;
description: string;
storyId?: string;
link?: string;
}
Loading