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 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
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 @@
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