fix(alerts): empty state

pull/15072/head
Andrew Watkins 2019-09-09 14:35:14 -07:00
parent 7f07270ece
commit 848936b5dc
3 changed files with 80 additions and 41 deletions

View File

@ -32,30 +32,32 @@ const CheckCards: FunctionComponent<Props> = ({
onCreateCheck, onCreateCheck,
}) => { }) => {
const cards = cs => cs.map(c => <CheckCard key={c.id} check={c} />) const cards = cs => cs.map(c => <CheckCard key={c.id} check={c} />)
const filteredCards = ( const body = filtered => (
<ResourceList.Body
emptyState={
<EmptyChecksList
showFirstTimeWidget={showFirstTimeWidget}
onCreateCheck={onCreateCheck}
searchTerm={searchTerm}
/>
}
>
{cards(filtered)}
</ResourceList.Body>
)
const filteredChecks = (
<FilterList<Check> <FilterList<Check>
list={checks} list={checks}
searchKeys={['name']} searchKeys={['name']}
searchTerm={searchTerm} searchTerm={searchTerm}
> >
{filtered => cards(filtered)} {filtered => body(filtered)}
</FilterList> </FilterList>
) )
return ( return (
<> <>
<ResourceList> <ResourceList>{filteredChecks}</ResourceList>
<ResourceList.Body
emptyState={
<EmptyChecksList
showFirstTimeWidget={showFirstTimeWidget}
onCreateCheck={onCreateCheck}
/>
}
>
{filteredCards}
</ResourceList.Body>
</ResourceList>
</> </>
) )
} }
@ -63,12 +65,25 @@ const CheckCards: FunctionComponent<Props> = ({
interface EmptyProps { interface EmptyProps {
showFirstTimeWidget: boolean showFirstTimeWidget: boolean
onCreateCheck: () => void onCreateCheck: () => void
searchTerm: string
} }
const EmptyChecksList: FunctionComponent<EmptyProps> = ({ const EmptyChecksList: FunctionComponent<EmptyProps> = ({
showFirstTimeWidget, showFirstTimeWidget,
onCreateCheck, onCreateCheck,
searchTerm,
}) => { }) => {
if (searchTerm) {
return (
<EmptyState size={ComponentSize.Small} className="alert-column--empty">
<EmptyState.Text
text="No checks match your search"
highlightWords={['checks']}
/>
</EmptyState>
)
}
if (showFirstTimeWidget) { if (showFirstTimeWidget) {
return ( return (
<Panel <Panel

View File

@ -20,32 +20,45 @@ const EndpointCards: FC<Props> = ({endpoints, searchTerm}) => {
<EndpointCard key={endpoint.id} endpoint={endpoint} /> <EndpointCard key={endpoint.id} endpoint={endpoint} />
)) ))
const filteredCards = ( const body = (
<FilterList<NotificationEndpoint> <FilterList<NotificationEndpoint>
list={endpoints} list={endpoints}
searchKeys={['name']} searchKeys={['name']}
searchTerm={searchTerm} searchTerm={searchTerm}
> >
{filteredEndpoints => cards(filteredEndpoints)} {filteredEndpoints => (
<ResourceList.Body
emptyState={<EmptyEndpointList searchTerm={searchTerm} />}
>
{cards(filteredEndpoints)}
</ResourceList.Body>
)}
</FilterList> </FilterList>
) )
return <ResourceList>{body}</ResourceList>
}
const EmptyEndpointList: FC<{searchTerm: string}> = ({searchTerm}) => {
if (searchTerm) {
return (
<EmptyState size={ComponentSize.Small} className="alert-column--empty">
<EmptyState.Text
text="No endpoints match your search"
highlightWords={['endpoints']}
/>
</EmptyState>
)
}
return ( return (
<ResourceList> <EmptyState size={ComponentSize.Small} className="alert-column--empty">
<ResourceList.Body emptyState={<EmptyEndpointList />}> <EmptyState.Text
{filteredCards} text="Want to send notifications to Slack, LINEBREAK PagerDuty or an HTTP server? LINEBREAK LINEBREAK Try creating a Notification Endpoint"
</ResourceList.Body> highlightWords={['Notification', 'Endpoint']}
</ResourceList> />
</EmptyState>
) )
} }
const EmptyEndpointList: FC = () => (
<EmptyState size={ComponentSize.Small} className="alert-column--empty">
<EmptyState.Text
text="Want to send notifications to Slack, LINEBREAK PagerDuty or an HTTP server? LINEBREAK LINEBREAK Try creating a Notification Endpoint"
highlightWords={['Notification', 'Endpoint']}
/>
</EmptyState>
)
export default EndpointCards export default EndpointCards

View File

@ -15,7 +15,7 @@ interface Props {
searchTerm: string searchTerm: string
} }
const NotificationRuleCards: FC<Props> = ({rules}) => { const NotificationRuleCards: FC<Props> = ({rules, searchTerm}) => {
const cards = rules => const cards = rules =>
rules.map(nr => <NotificationRuleCard key={nr.id} rule={nr} />) rules.map(nr => <NotificationRuleCard key={nr.id} rule={nr} />)
@ -23,22 +23,33 @@ const NotificationRuleCards: FC<Props> = ({rules}) => {
<FilterList<NotificationRuleDraft> <FilterList<NotificationRuleDraft>
list={rules} list={rules}
searchKeys={['name']} searchKeys={['name']}
searchTerm="" searchTerm={searchTerm}
> >
{filtered => cards(filtered)} {filtered => (
<ResourceList.Body
emptyState={<EmptyNotificationRulesList searchTerm={searchTerm} />}
>
{cards(filtered)}
</ResourceList.Body>
)}
</FilterList> </FilterList>
) )
return ( return <ResourceList>{filteredCards}</ResourceList>
<ResourceList>
<ResourceList.Body emptyState={<EmptyNotificationRulesList />}>
{filteredCards}
</ResourceList.Body>
</ResourceList>
)
} }
const EmptyNotificationRulesList: FC = () => { const EmptyNotificationRulesList: FC<{searchTerm: string}> = ({searchTerm}) => {
if (searchTerm) {
return (
<EmptyState size={ComponentSize.Small} className="alert-column--empty">
<EmptyState.Text
text="No rules match your search"
highlightWords={['rules']}
/>
</EmptyState>
)
}
return ( return (
<EmptyState size={ComponentSize.Small} className="alert-column--empty"> <EmptyState size={ComponentSize.Small} className="alert-column--empty">
<EmptyState.Text <EmptyState.Text