Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
feat(list): do not show test devices
Browse files Browse the repository at this point in the history
Firmware E2E is now running against prod, so these
devices may show up during the test
  • Loading branch information
coderbyheart committed Jan 20, 2021
1 parent 2e768d6 commit 97b4e37
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
71 changes: 40 additions & 31 deletions src/CatList/CatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,51 @@ export const CatList = ({
cats,
showButtonWarning,
snooze,
filterTestDevices,
}: {
cats: { id: string; name: string; labels?: string[] }[]
cats: { id: string; name: string; labels?: string[]; isTest?: boolean }[]
/**
* Filter out
*/
filterTestDevices?: boolean
} & ButtonWarningProps) => (
<Table>
<tbody>
{cats.map(({ id, name, labels }) => {
const showWarning = showButtonWarning(id)
const Widget = showWarning ? CatWithWarning : Cat
return (
<tr key={id}>
<Widget>
<Link to={`/cat/${id}`}>{name}</Link>
<span>
{labels && (
<Labels>
{labels.map((name) => (
<Badge pill={true} color={'info'}>
{name}
</Badge>
))}
</Labels>
)}
{showWarning && (
<ClearButton
title="Click to snooze alarm"
onClick={() => snooze(id)}
>
{emojify('🔴')}
<RelativeTime ts={showWarning} />
</ClearButton>
)}
</span>
</Widget>
</tr>
{cats
.filter(
({ isTest }) => (filterTestDevices ?? true ? !isTest : true), // This is so that test devices do not show up here
)
})}
.map(({ id, name, labels }) => {
const showWarning = showButtonWarning(id)
const Widget = showWarning ? CatWithWarning : Cat
return (
<tr key={id}>
<Widget>
<Link to={`/cat/${id}`}>{name}</Link>
<span>
{labels && (
<Labels>
{labels.map((name) => (
<Badge pill={true} color={'info'}>
{name}
</Badge>
))}
</Labels>
)}
{showWarning && (
<ClearButton
title="Click to snooze alarm"
onClick={() => snooze(id)}
>
{emojify('🔴')}
<RelativeTime ts={showWarning} />
</ClearButton>
)}
</span>
</Widget>
</tr>
)
})}
</tbody>
</Table>
)
4 changes: 2 additions & 2 deletions src/aws/Cats/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ListCats = ({
} & ButtonWarningProps) => {
const [loading, setLoading] = useState(true)
const [cats, setCats] = useState(
[] as { id: string; name: string; labels?: string[] }[],
[] as { id: string; name: string; labels?: string[]; isTest: boolean }[],
)
const [error, setError] = useState<Error>()

Expand All @@ -48,14 +48,14 @@ const ListCats = ({
.send(new ListThingsCommand({}))
.then(({ things }) => {
if (isCancelled) return
console.log(things)
setCats(
(things ?? []).map(({ thingName, attributes }) => ({
id: thingName ?? 'unknown',
name: attributes?.name ?? thingName ?? 'unknown',
labels: Object.entries(attributes ?? {})
.filter(([name]) => name !== 'name')
.map(([name, value]) => `${name}:${value}`),
isTest: attributes?.test !== undefined,
})),
)
setLoading(false)
Expand Down

0 comments on commit 97b4e37

Please sign in to comment.