Add empty state (#147)
* add empty states * add two empty states * updates to empty state * update PR * fix merge conflict * fix formatting and add prettier * updated test * review comments * update snapshot
This commit is contained in:
parent
85b8f17f35
commit
35584207c8
4 changed files with 45 additions and 11 deletions
|
@ -9,6 +9,7 @@ import {
|
||||||
EmptyStateSecondaryActions,
|
EmptyStateSecondaryActions,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { PlusCircleIcon } from "@patternfly/react-icons";
|
import { PlusCircleIcon } from "@patternfly/react-icons";
|
||||||
|
import { SearchIcon } from "@patternfly/react-icons";
|
||||||
|
|
||||||
export type Action = {
|
export type Action = {
|
||||||
text: string;
|
text: string;
|
||||||
|
@ -19,8 +20,10 @@ export type Action = {
|
||||||
export type ListEmptyStateProps = {
|
export type ListEmptyStateProps = {
|
||||||
message: string;
|
message: string;
|
||||||
instructions: string;
|
instructions: string;
|
||||||
primaryActionText: string;
|
primaryActionText?: string;
|
||||||
onPrimaryAction: MouseEventHandler<HTMLButtonElement>;
|
onPrimaryAction?: MouseEventHandler<HTMLButtonElement>;
|
||||||
|
hasIcon?: boolean;
|
||||||
|
isSearchVariant?: boolean;
|
||||||
secondaryActions?: Action[];
|
secondaryActions?: Action[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,20 +31,28 @@ export const ListEmptyState = ({
|
||||||
message,
|
message,
|
||||||
instructions,
|
instructions,
|
||||||
onPrimaryAction,
|
onPrimaryAction,
|
||||||
|
hasIcon,
|
||||||
|
isSearchVariant,
|
||||||
primaryActionText,
|
primaryActionText,
|
||||||
secondaryActions,
|
secondaryActions,
|
||||||
}: ListEmptyStateProps) => {
|
}: ListEmptyStateProps) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<EmptyState variant="large">
|
<EmptyState variant="large">
|
||||||
<EmptyStateIcon icon={PlusCircleIcon} />
|
{hasIcon && isSearchVariant ? (
|
||||||
|
<EmptyStateIcon icon={SearchIcon} />
|
||||||
|
) : (
|
||||||
|
<EmptyStateIcon icon={PlusCircleIcon} />
|
||||||
|
)}
|
||||||
<Title headingLevel="h4" size="lg">
|
<Title headingLevel="h4" size="lg">
|
||||||
{message}
|
{message}
|
||||||
</Title>
|
</Title>
|
||||||
<EmptyStateBody>{instructions}</EmptyStateBody>
|
<EmptyStateBody>{instructions}</EmptyStateBody>
|
||||||
<Button variant="primary" onClick={onPrimaryAction}>
|
{primaryActionText && (
|
||||||
{primaryActionText}
|
<Button variant="primary" onClick={onPrimaryAction}>
|
||||||
</Button>
|
{primaryActionText}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{secondaryActions && (
|
{secondaryActions && (
|
||||||
<EmptyStateSecondaryActions>
|
<EmptyStateSecondaryActions>
|
||||||
{secondaryActions.map((action) => (
|
{secondaryActions.map((action) => (
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
ServerGroupMembersRepresentation,
|
ServerGroupMembersRepresentation,
|
||||||
} from "./models/server-info";
|
} from "./models/server-info";
|
||||||
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
|
import { TableToolbar } from "../components/table-toolbar/TableToolbar";
|
||||||
|
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Divider,
|
Divider,
|
||||||
|
@ -90,16 +91,17 @@ export const GroupsSection = () => {
|
||||||
</Title>
|
</Title>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<PageSection variant={PageSectionVariants.light}>
|
<PageSection variant={PageSectionVariants.light}>
|
||||||
{!rawData && (
|
{!rawData && (
|
||||||
<div className="pf-u-text-align-center">
|
<div className="pf-u-text-align-center">
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{rawData && (
|
{rawData && rawData.length > 0 ? (
|
||||||
<TableToolbar
|
<TableToolbar
|
||||||
inputGroupName="groupsToolbarTextInput"
|
inputGroupName="groupsToolbarTextInput"
|
||||||
inputGroupPlaceholder="Search groups"
|
inputGroupPlaceholder={t("searchGroups")}
|
||||||
inputGroupOnChange={filterGroups}
|
inputGroupOnChange={filterGroups}
|
||||||
toolbarItem={
|
toolbarItem={
|
||||||
<>
|
<>
|
||||||
|
@ -122,8 +124,25 @@ export const GroupsSection = () => {
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<GroupsList list={filteredData || rawData} />
|
{rawData && (
|
||||||
|
<GroupsList list={filteredData ? filteredData : rawData} />
|
||||||
|
)}
|
||||||
|
{filteredData && filteredData.length === 0 && (
|
||||||
|
<ListEmptyState
|
||||||
|
hasIcon={true}
|
||||||
|
isSearchVariant={true}
|
||||||
|
message={t("noSearchResults")}
|
||||||
|
instructions={t("noSearchResultsInstructions")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</TableToolbar>
|
</TableToolbar>
|
||||||
|
) : (
|
||||||
|
<ListEmptyState
|
||||||
|
hasIcon={true}
|
||||||
|
message={t("noGroupsInThisRealm")}
|
||||||
|
instructions={t("noGroupsInThisRealmInstructions")}
|
||||||
|
primaryActionText={t("createGroup")}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</PageSection>
|
</PageSection>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
"members": "Members",
|
"members": "Members",
|
||||||
"moveTo": "Move to",
|
"moveTo": "Move to",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
"tableOfGroups": "Table of groups"
|
"tableOfGroups": "Table of groups",
|
||||||
|
"noSearchResults": "No search results",
|
||||||
|
"noSearchResultsInstructions" : "Click on the search bar above to search for groups",
|
||||||
|
"noGroupsInThisRealm" : "No groups in this Realm",
|
||||||
|
"noGroupsInThisRealmInstructions" : "You haven't created any groups in this realm. Create a group to get started."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15237,7 +15237,7 @@ prepend-http@^1.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
|
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc"
|
||||||
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
|
integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw=
|
||||||
|
|
||||||
prettier@^2.0.5:
|
prettier@2.1.2:
|
||||||
version "2.1.2"
|
version "2.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
||||||
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
||||||
|
|
Loading…
Reference in a new issue