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(mrc): add changelog component #14889

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const Headers: React.FC<HeadersProps> = ({
</OdsText>
)}
</div>
{headerButton && <div>{headerButton}</div>}
{headerButton && (
<div className="flex flex-wrap justify-end">{headerButton}</div>
)}
anooparveti marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +29 to +31
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Instead of accepting all the buttons as one single react node, i think it can be beneficial to accept it as a separate prop called changelogButton. Also, since the current prop is just headerButton (singular button) it does not convey implicitly that it could accept and well adjust the layout for more buttons.

</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { vitest } from 'vitest';
import { vitest, vi } from 'vitest';
import { waitFor, screen } from '@testing-library/react';
import { render } from '../../../utils/test.provider';
import {
header,
subHeader,
headerWithGuides,
headerWithHeaderButtons,
headerWithActions,
} from './headers.stories';
import { IamAuthorizationResponse } from '../../../hooks/iam/iam.interface';
import { useAuthorizationIam } from '../../../hooks/iam';

vitest.mock('../../../hooks/iam');
vitest.mock('@ovh-ux/manager-react-shell-client', () => ({
useOvhTracking: () => ({
trackClick: vi.fn(),
}),
}));

const mockedHook =
useAuthorizationIam as unknown as jest.Mock<IamAuthorizationResponse>;
Expand Down Expand Up @@ -40,11 +45,11 @@ describe('Headers component', () => {
});
});

it('renders header with guides correctly', async () => {
render(headerWithGuides());
it('renders header with header buttons correctly', async () => {
render(headerWithHeaderButtons());
await waitFor(() => {
expect(
screen.getByText('Example for header with guides'),
screen.getByText('Example for header with header buttons'),
).toBeInTheDocument();
expect(screen.getByText('description for subheader')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Meta } from '@storybook/react';
import Headers, { HeadersProps } from './headers.component';
import ActionMenu from '../../navigation/menus/action/action.component';
import GuideButton from '../../navigation/menus/guide/guide.component';
import ChangelogButton, {
ChangelogLinks,
} from '../../navigation/menus/changelog/changelog.component';

const Heading: HeadersProps = {
title: 'Example for header',
Expand Down Expand Up @@ -43,20 +46,37 @@ const guideItems = [
},
];

const changelogChapters: string[] = ['baremetal', 'server', 'dedicated'];
const changelogLinks: ChangelogLinks = {
roadmap:
'https://github.com/orgs/ovh/projects/16/views/1?pane=info&sliceBy%5Bvalue%5D=Baremetal',
changelog:
'https://github.com/orgs/ovh/projects/16/views/1?pane=info&sliceBy%5Bvalue%5D=Baremetal',
'feature-request':
'https://github.com/orgs/ovh/projects/16/views/1?pane=info&sliceBy%5Bvalue%5D=Baremetal',
};

const HeadingWithActionButton: HeadersProps = {
title: 'Example for header with actions ',
description: 'description for header',
headerButton: <ActionMenu id="1" items={actionItems} />,
};
const HeadingWithGuideButton: HeadersProps = {
title: 'Example for header with guides',
const HeadingWithHeaderButtons: HeadersProps = {
title: 'Example for header with header buttons',
description: 'description for subheader',
headerButton: <GuideButton items={guideItems} />,
headerButton: (
<>
<ChangelogButton links={changelogLinks} chapters={changelogChapters} />
<GuideButton items={guideItems} />
</>
),
};

export const header = () => <Headers {...Heading} />;
export const subHeader = () => <Headers {...SubHeading} />;
export const headerWithGuides = () => <Headers {...HeadingWithGuideButton} />;
export const headerWithHeaderButtons = () => (
<Headers {...HeadingWithHeaderButtons} />
);
export const headerWithActions = () => <Headers {...HeadingWithActionButton} />;

const meta: Meta = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { ODS_BUTTON_SIZE, ODS_BUTTON_VARIANT } from '@ovhcloud/ods-components';
import { OdsPopover, OdsButton } from '@ovhcloud/ods-components/react';
import { useTranslation } from 'react-i18next';
import { useOvhTracking } from '@ovh-ux/manager-react-shell-client';
import { Links, LinkType } from '../../../typography';
import '../translations/translation';

export interface ChangelogLinks {
changelog: string;
roadmap: string;
'feature-request': string;
}

export interface ChangelogButtonProps {
links: ChangelogLinks;
chapters?: string[];
}

export const CHANGELOG_PREFIXES = ['tile-changelog-roadmap', 'external-link'];
const GO_TO = (link: string) => `go-to-${link}`;

export const ChangelogButton: React.FC<ChangelogButtonProps> = ({
links,
chapters = [],
}) => {
const { t } = useTranslation('buttons');
const { trackClick } = useOvhTracking();
return (
<>
<div id="navigation-menu-changelog-trigger">
<OdsButton
slot="menu-title"
variant={ODS_BUTTON_VARIANT.ghost}
size={ODS_BUTTON_SIZE.sm}
label={t('mrc_changelog_header')}
className="whitespace-nowrap"
></OdsButton>
</div>

<OdsPopover
triggerId="navigation-menu-changelog-trigger"
with-arrow="true"
>
{Object.entries(links).map(([key, value]) => (
<div key={key}>
<Links
href={value}
target="_blank"
type={LinkType.external}
rel={LinkType.external}
label={t(`mrc_changelog_${key}`)}
onClickReturn={() =>
trackClick({
actionType: 'navigation',
actions: [...chapters, ...CHANGELOG_PREFIXES, GO_TO(key)],
})
}
/>
</div>
))}
</OdsPopover>
</>
);
};

export default ChangelogButton;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { Meta } from '@storybook/react';
import {
ChangelogButton,
ChangelogLinks,
ChangelogButtonProps,
} from './changelog.component';

const changelogChapters: string[] = ['baremetal', 'server', 'dedicated'];
const changelogLinks: ChangelogLinks = {
roadmap:
'https://github.com/orgs/ovh/projects/16/views/1?pane=info&sliceBy%5Bvalue%5D=Baremetal',
changelog:
'https://github.com/orgs/ovh/projects/16/views/1?pane=info&sliceBy%5Bvalue%5D=Baremetal',
'feature-request':
'https://github.com/orgs/ovh/projects/16/views/1?pane=info&sliceBy%5Bvalue%5D=Baremetal',
};

export const changelogButton: ChangelogButtonProps = {
links: changelogLinks,
chapters: changelogChapters,
};

const meta: Meta<ChangelogButtonProps> = {
title: 'Navigation/Menus',
decorators: [(story) => <div>{story()}</div>],
component: ChangelogButton,
argTypes: {},
args: changelogButton,
};

export default meta;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './action/action.component';
export * from './guide/guide.component';
export * from './changelog/changelog.component';
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"common_actions": "Aktionen",
"user_account_guides_header": "Anleitungen"
"user_account_guides_header": "Anleitungen",
"mrc_changelog_header": "Roadmap &amp; Changelog",
"mrc_changelog_roadmap": "Roadmap",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Feature Request"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"common_actions": "Actions",
"user_account_guides_header": "Guides"
"user_account_guides_header": "Guides",
"mrc_changelog_header": "Roadmap &amp; Changelog",
"mrc_changelog_roadmap": "Roadmap",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Feature request"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"common_actions": "Acciones",
"user_account_guides_header": "Guías"
"user_account_guides_header": "Guías",
"mrc_changelog_header": "Roadmap &amp; Changelog"
}
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{ "common_actions": "Actions", "user_account_guides_header": "Guides" }
{
"common_actions": "Actions",
"user_account_guides_header": "Guides",
"mrc_changelog_header": "Roadmap & Changelog",
"mrc_changelog_roadmap": "Roadmap",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Feature request"
}
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{ "common_actions": "Actions", "user_account_guides_header": "Guides" }
{
"common_actions": "Actions",
"user_account_guides_header": "Guides",
"mrc_changelog_header": "Roadmap & Changelog",
"mrc_changelog_roadmap": "Roadmap",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Feature request"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"common_actions": "Azioni",
"user_account_guides_header": "Guide"
"user_account_guides_header": "Guide",
"mrc_changelog_header": "Roadmap &amp; Changelog",
"mrc_changelog_roadmap": "Roadmap",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Feature Request"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"common_actions": "Operacje",
"user_account_guides_header": "Przewodniki"
"user_account_guides_header": "Przewodniki",
"mrc_changelog_header": "Roadmap &amp; Changelog",
"mrc_changelog_roadmap": "Roadmapa",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Propozycja wdrożenia nowej funkcji"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"common_actions": "Ações",
"user_account_guides_header": "Manuais"
"user_account_guides_header": "Manuais",
"mrc_changelog_header": "Roadmap &amp; Changelog",
"mrc_changelog_roadmap": "Roadmap",
"mrc_changelog_changelog": "Changelog",
"mrc_changelog_feature-request": "Feature request"
}
Loading