Skip to content

Commit

Permalink
[HomePage] Add home page static list card (#7351) (#7355) (#7383)
Browse files Browse the repository at this point in the history
* feat: add home static list card

* Changeset file for PR #7351 created/updated

* update link property

* add i18n and description

---------

(cherry picked from commit e64de15)





(cherry picked from commit 6685bce)

Signed-off-by: tygao <tygao@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent a9fd071 commit 5708d4b
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 2 deletions.
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://github.com/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,27 @@
/*
* 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',
description: 'Get started in minutes with OpenSearch Dashboards',
},
],
};
const { baseElement } = render(<HomeListCard config={mockConfig} />);
expect(baseElement).toMatchSnapshot();
});
});
102 changes: 102 additions & 0 deletions src/plugins/home/public/application/components/home_list_card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import {
EuiDescriptionList,
EuiText,
EuiLink,
EuiTitle,
EuiPanel,
EuiDescriptionListTitle,
EuiDescriptionListDescription,
EuiSpacer,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';

export const LEARN_OPENSEARCH_CONFIG = {
title: i18n.translate('homepage.card.learnOpenSearch.title', {
defaultMessage: 'Learn Opensearch',
}),
list: [
{
label: 'Quickstart guide',
href: 'https://opensearch.org/docs/latest/dashboards/quickstart/',
description: 'Get started in minutes with OpenSearch Dashboards',
},
{
label: 'Building data visualizations',
href: 'https://opensearch.org/docs/latest/dashboards/visualize/viz-index/',
description: 'Design interactive charts and graphs to unlock insights form your data.',
},
{
label: 'Creating dashboards',
href: 'https://opensearch.org/docs/latest/dashboards/dashboard/index/',
description: 'Build interactive dashboards to explore and analyze your data',
},
],
allLink: 'https://opensearch.org/docs/latest/',
};

export const WHATS_NEW_CONFIG = {
title: i18n.translate('homepage.card.whatsNew.title', {
defaultMessage: `What's New`,
}),
list: [
{
label: 'Quickstart guide',
href: 'https://opensearch.org/docs/latest/dashboards/quickstart/',
description: 'Get started in minutes with OpenSearch Dashboards',
},
],
};

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

export const HomeListCard = ({ config }: { config: Config }) => {
return (
<>
<EuiPanel paddingSize="s" hasBorder={false} hasShadow={false}>
<EuiTitle>
<h4>{config.title}</h4>
</EuiTitle>
<EuiSpacer />
{config.list.length > 0 && (
<EuiDescriptionList>
{config.list.map((item) => (
<>
<EuiDescriptionListTitle>
<EuiLink href={item.href} target="_blank">
{item.label}
</EuiLink>
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>{item.description}</EuiDescriptionListDescription>
</>
))}
</EuiDescriptionList>
)}

{config.allLink ? (
<>
<EuiSpacer />
<EuiLink href={config.allLink} target="_blank">
<EuiText size="s" style={{ display: 'inline' }}>
View all
</EuiText>
</EuiLink>
</>
) : null}
</EuiPanel>
</>
);
};
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 @@ import {
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 @@ -50,4 +55,31 @@ export const setupHome = (contentManagement: ContentManagementPluginSetup) => {
});
};

export const initHome = (contentManagement: ContentManagementPluginStart, core: CoreStart) => {};
export const initHome = (contentManagement: ContentManagementPluginStart, core: CoreStart) => {
contentManagement.registerContentProvider({
id: 'whats_new_cards',
getContent: () => ({
id: 'whats_new',
kind: 'custom',
order: 3,
render: () =>
React.createElement(HomeListCard, {
config: WHATS_NEW_CONFIG,
}),
}),
getTargetArea: () => HOME_CONTENT_AREAS.SERVICE_CARDS,
});
contentManagement.registerContentProvider({
id: 'learn_opensearch_new_cards',
getContent: () => ({
id: 'learn_opensearch',
kind: 'custom',
order: 4,
render: () =>
React.createElement(HomeListCard, {
config: LEARN_OPENSEARCH_CONFIG,
}),
}),
getTargetArea: () => HOME_CONTENT_AREAS.SERVICE_CARDS,
});
};

0 comments on commit 5708d4b

Please sign in to comment.