Skip to content

Commit

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

Signed-off-by: tygao <[email protected]>

* Changeset file for PR #7351 created/updated

* update link property

Signed-off-by: tygao <[email protected]>

* add i18n and description

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit e64de15)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent c30287a commit c4178ee
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 @@ -38,4 +43,31 @@ export const setupHome = (contentManagement: ContentManagementPluginSetup) => {
});
};

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
});
};

0 comments on commit c4178ee

Please sign in to comment.