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(EmptyDetailsView): add component #65

Open
wants to merge 2 commits into
base: main
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
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-require-imports": "off",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# Sidenav top-level section
# should be the same for all markdown files
section: AI-infra-ui-components
# Sidenav secondary level section
# should be the same for all markdown files
id: EmptyDetailsView
# Tab (react | react-demos | html | html-demos | design-guidelines | accessibility)
source: react
# If you use typescript, the name of the interface to display props for
# These are found through the sourceProps function provided in patternfly-docs.source.js
propComponents: ['EmptyDetailsView']
---

import { EmptyDetailsView } from "@patternfly/ai-infra-ui-components";
import clusterImage from './empty-state-cluster-storage.svg'

Note: this component documents the API and enhances the [existing EmptyDetailsView](https://github.com/opendatahub-io/odh-dashboard/blob/main/frontend/src/components/EmptyDetailsView.tsx) component from odh-dashboard. It can be imported from [@patternfly/ai-infra-ui-components](https://www.npmjs.com/package/@patternfly/AI-infra-ui-components). Alternatively, it can be used within the odh-dashboard via the import: `~/components/EmptyDetailsView`

### Example

```js file="./EmptyDetailsViewBasic.tsx"

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { EmptyDetailsView } from '@patternfly/ai-infra-ui-components';
import { Button } from '@patternfly/react-core';
import clusterImage from './empty-state-cluster-storage.svg';

export const EmptyDetailsViewBasic: React.FunctionComponent = () => (
<EmptyDetailsView
title="Start by adding cluster storage"
description="Cluster storage saves your project’s data on a selected cluster. You can optionally connect cluster storage to a workbench."
iconImage={clusterImage}
imageSize="240px"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change 240px to 320px

Also, this size is different than the size shown in /EmptyDetailsView/EmptyDetailsView.tsx below, which is using 320px.

We have new guidelines for empty states that recommend using 320px for illustrations. It would be ideal if our examples in the preview use the values we are recommending.

imageAlt="add cluster storage"
createButton={<Button>Add cluster storage</Button>}
/>
);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions packages/module/src/EmptyDetailsView/EmptyDetailsView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from 'react';
import {
EmptyState,
EmptyStateBody,
EmptyStateActions,
EmptyStateFooter,
EmptyStateProps
} from '@patternfly/react-core';

export interface EmptyDetailsViewProps extends Omit<EmptyStateProps, 'children' | 'titleText'> {
/** Empty state title text. */
title?: string;
/** Empty state description - will be rendered inside EmptyStateBody. */
description?: React.ReactNode;
/** Source path to an icon image. */
iconImage?: string;
/** Alternative text for icon image if image can't load. */
imageAlt?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need alt text for this image? This image is purely decorative and doesn't provide any additional meaning to the user that isn't already provided with the contents on the page.

/** Height of an icon image. */
imageSize?: string;
/** Flag indicating that creation is allowed. */
allowCreate?: boolean;
/** Button which initiates the creation. */
createButton?: React.ReactNode;
/** Extra children to render inside EmptyStateFooter. */
footerExtraChildren?: React.ReactNode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The example provided in the preview shows an empty state with just a single primary action, but it would be good to have an example that shows a secondary action, too.

}

export const EmptyDetailsView: React.FunctionComponent<EmptyDetailsViewProps> = ({
title,
description,
iconImage,
imageAlt,
allowCreate = true,
createButton,
footerExtraChildren = null,
imageSize = '320px',
...props
}: EmptyDetailsViewProps) => (
<EmptyState
headingLevel="h3"
titleText={title}
variant="lg"
icon={iconImage ? () => <img style={{ height: imageSize }} src={iconImage} alt={imageAlt} /> : undefined}
{...props}
>
<EmptyStateBody>{description}</EmptyStateBody>
{allowCreate && createButton ? (
<EmptyStateFooter>
<EmptyStateActions>{createButton}</EmptyStateActions>
{footerExtraChildren}
</EmptyStateFooter>
) : null}
</EmptyState>
);
1 change: 1 addition & 0 deletions packages/module/src/EmptyDetailsView/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './EmptyDetailsView';
3 changes: 2 additions & 1 deletion packages/module/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * from './BulkActionExpandableSection';
export * from './DeleteModal';
export * from './EmptyDetailsView';
export * from './EmptyStateErrorMessage';
export * from './FieldGroupHelpLabelIcon';
export * from './IndentSection';
export * from './K8sNameDescriptionField';
export * from './TruncatedText';
export * from './EmptyStateErrorMessage';