Feature: Add tandoor widget (#3060)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>pull/2708/head
parent
8e9920a9d8
commit
b05b9b1420
@ -0,0 +1,15 @@
|
||||
---
|
||||
title: Tandoor
|
||||
description: Tandoor Widget Configuration
|
||||
---
|
||||
|
||||
Generate a user API key under `Settings > API > Generate`. For the token's scope, use `read`.
|
||||
|
||||
Allowed fields: `["users", "recipes", "keywords"]`.
|
||||
|
||||
```yaml
|
||||
widget:
|
||||
type: tandoor
|
||||
url: http://tandoor-frontend.host.or.ip
|
||||
key: tandoor-api-token
|
||||
```
|
@ -0,0 +1,32 @@
|
||||
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 { widget } = service;
|
||||
|
||||
const { data: spaceData, error: spaceError } = useWidgetAPI(widget, "space");
|
||||
const { data: keywordData, error: keywordError } = useWidgetAPI(widget, "keyword");
|
||||
|
||||
if (spaceError || keywordError) {
|
||||
const finalError = spaceError ?? keywordError;
|
||||
return <Container service={service} error={finalError} />;
|
||||
}
|
||||
|
||||
if (!spaceData || !keywordData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="tandoor.users" />
|
||||
<Block label="tandoor.recipes" />
|
||||
<Block label="tandoor.keywords" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="tandoor.users" value={spaceData[0]?.user_count} />
|
||||
<Block label="tandoor.recipes" value={spaceData[0]?.recipe_count} />
|
||||
<Block label="tandoor.keywords" value={keywordData.count} />
|
||||
</Container>
|
||||
);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
|
||||
|
||||
const widget = {
|
||||
api: "{url}/api/{endpoint}/",
|
||||
proxyHandler: credentialedProxyHandler,
|
||||
|
||||
mappings: {
|
||||
space: {
|
||||
endpoint: "space",
|
||||
},
|
||||
keyword: {
|
||||
endpoint: "keyword",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default widget;
|
Loading…
Reference in new issue