Feature: Plant-it widget (#2941)
parent
841c74d58a
commit
619f365c92
@ -0,0 +1,15 @@
|
||||
---
|
||||
title: Plant-it
|
||||
description: Plant-it Widget Configuration
|
||||
---
|
||||
|
||||
Learn more about [Plantit](https://github.com/MDeLuise/plant-it).
|
||||
|
||||
API key can be created from the REST API.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: plantit
|
||||
url: http://plant-it.host.or.ip:port # api port
|
||||
key: plantit-api-key
|
||||
```
|
@ -0,0 +1,37 @@
|
||||
import { useTranslation } from "next-i18next";
|
||||
|
||||
import Container from "components/services/widget/container";
|
||||
import Block from "components/services/widget/block";
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { widget } = service;
|
||||
|
||||
const { data: plantitData, error: plantitError } = useWidgetAPI(widget, "plantit");
|
||||
|
||||
if (plantitError) {
|
||||
return <Container service={service} error={plantitError} />;
|
||||
}
|
||||
|
||||
if (!plantitData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="plantit.events" />
|
||||
<Block label="plantit.plants" />
|
||||
<Block label="plantit.photos" />
|
||||
<Block label="plantit.species" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="plantit.events" value={t("common.number", { value: plantitData.diaryEntryCount })} />
|
||||
<Block label="plantit.plants" value={t("common.number", { value: plantitData.plantCount })} />
|
||||
<Block label="plantit.photos" value={t("common.number", { value: plantitData.imageCount })} />
|
||||
<Block label="plantit.species" value={t("common.number", { value: plantitData.botanicalInfoCount })} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import { asJson } from "utils/proxy/api-helpers";
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
plantit: {
|
||||
endpoint: "stats",
|
||||
},
|
||||
map: (data) => ({
|
||||
events: Object.values(asJson(data).diaryEntryCount).reduce((acc, i) => acc + i, 0),
|
||||
plants: Object.values(asJson(data).plantCount).reduce((acc, i) => acc + i, 0),
|
||||
photos: Object.values(asJson(data).imageCount).reduce((acc, i) => acc + i, 0),
|
||||
species: Object.values(asJson(data).botanicalInfoCount).reduce((acc, i) => acc + i, 0),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Reference in new issue