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

[HomePage] Add home page static list card #7351

Merged
merged 6 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions changelogs/fragments/7351.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Add home page static list card ([#7351](https:/opensearch-project/OpenSearch-Dashboards/pull/7351))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render } from '@testing-library/react';

import { HomeListCard } from './home_list_card';

describe('<HomeListCard />', () => {
it('should render static content normally', async () => {
const mockConfig = {
title: `What's New`,
list: [
{
label: 'Quickstart guide',
href: 'https://opensearch.org/docs/latest/dashboards/quickstart/',
target: '_blank',
},
],
};
const { baseElement } = render(<HomeListCard config={mockConfig} />);
expect(baseElement).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiCard, EuiLink, EuiListGroup } from '@elastic/eui';

export const LEARN_OPENSEARCH_CONFIG = {
title: 'Learn Opensearch',
Copy link
Member

Choose a reason for hiding this comment

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

Shall we at least wrap it with i18n?

list: [
{
label: 'Quickstart guide',
href: 'https://opensearch.org/docs/latest/dashboards/quickstart/',
target: '_blank',
},
{
label: 'Building data visualizations',
href: 'https://opensearch.org/docs/latest/dashboards/visualize/viz-index/',
target: '_blank',
},
{
label: 'Creating dashboards',
href: 'https://opensearch.org/docs/latest/dashboards/dashboard/index/',
target: '_blank',
},
],
allLink: 'https://opensearch.org/docs/latest/',
};

export const WHATS_NEW_CONFIG = {
title: `What's New`,
list: [
{
label: 'Quickstart guide',
href: 'https://opensearch.org/docs/latest/dashboards/quickstart/',
target: '_blank',
},
],
};

interface Config {
title: string;
list: Array<{
label: string;
href: string;
target?: string;
}>;
allLink?: string;
}

export const HomeListCard = ({ config }: { config: Config }) => {
return (
<>
<EuiCard
title={config.title}
description={false}
hasBorder={false}
display="plain"
footer={
config.allLink ? (
<EuiLink href={config.allLink} external={true} target="_blank">
view all
</EuiLink>
) : null
}
>
<EuiListGroup listItems={config.list} color="text" size="s" />
Copy link
Member

Choose a reason for hiding this comment

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

If description is needed, I think we should use DescriptionList component https://oui.opensearch.org/1.8/#/display/description-list

</EuiCard>
</>
);
};
36 changes: 34 additions & 2 deletions src/plugins/home/public/application/home_render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
ContentManagementPluginSetup,
ContentManagementPluginStart,
} from '../../../../plugins/content_management/public';
import { HOME_PAGE_ID, SECTIONS } from '../../common/constants';
import { HOME_PAGE_ID, SECTIONS, HOME_CONTENT_AREAS } from '../../common/constants';
import {
WHATS_NEW_CONFIG,
LEARN_OPENSEARCH_CONFIG,
HomeListCard,
} from './components/home_list_card';

export const setupHome = (contentManagement: ContentManagementPluginSetup) => {
contentManagement.registerPage({
Expand Down Expand Up @@ -38,4 +43,31 @@
});
};

export const initHome = (contentManagement: ContentManagementPluginStart, core: CoreStart) => {};
export const initHome = (contentManagement: ContentManagementPluginStart, core: CoreStart) => {
contentManagement.registerContentProvider({

Check warning on line 47 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L47

Added line #L47 was not covered by tests
id: 'whats_new_cards',
getContent: () => ({

Check warning on line 49 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L49

Added line #L49 was not covered by tests
id: 'whats_new',
kind: 'custom',
order: 3,
render: () =>
React.createElement(HomeListCard, {

Check warning on line 54 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L54

Added line #L54 was not covered by tests
config: WHATS_NEW_CONFIG,
}),
}),
getTargetArea: () => HOME_CONTENT_AREAS.SERVICE_CARDS,

Check warning on line 58 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L58

Added line #L58 was not covered by tests
});
contentManagement.registerContentProvider({

Check warning on line 60 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L60

Added line #L60 was not covered by tests
id: 'learn_opensearch_new_cards',
getContent: () => ({

Check warning on line 62 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L62

Added line #L62 was not covered by tests
id: 'learn_opensearch',
kind: 'custom',
order: 4,
render: () =>
React.createElement(HomeListCard, {

Check warning on line 67 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L67

Added line #L67 was not covered by tests
config: LEARN_OPENSEARCH_CONFIG,
}),
}),
getTargetArea: () => HOME_CONTENT_AREAS.SERVICE_CARDS,

Check warning on line 71 in src/plugins/home/public/application/home_render.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/home/public/application/home_render.tsx#L71

Added line #L71 was not covered by tests
});
};
Loading