-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenMediaVault widget: Part 2 #1817
Changes from all commits
edb5916
8368b53
fc2a933
b0bc292
5ba980d
b6036ca
0ec6393
6bb80ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||
// noinspection JSUnresolvedVariable | ||||
|
||||
import { useTranslation } from "next-i18next"; | ||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api"; | ||||
import Container from "components/services/widget/container"; | ||||
import Block from "components/services/widget/block"; | ||||
|
||||
const items = [ | ||||
{ | ||||
label: "openmediavault.updatesAvailable", | ||||
getValue: (data, t) => (data.length > 0 ? t("openmediavault.yes") : t("openmediavault.no")), | ||||
}, | ||||
]; | ||||
|
||||
// noinspection DuplicatedCode | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
export default function Component({ service }) { | ||||
const { t } = useTranslation(); | ||||
const { data, error } = useWidgetAPI(service.widget); | ||||
|
||||
if (error) { | ||||
return <Container service={service} error={error} />; | ||||
} | ||||
|
||||
const itemsWithData = items.map((item) => ({ | ||||
...item, | ||||
number: data?.response ? item.getValue(data.response, t) : null, | ||||
})); | ||||
|
||||
return ( | ||||
<Container service={service}> | ||||
{itemsWithData.map((e) => ( | ||||
<Block key={e.label} label={e.label} value={e.number} /> | ||||
))} | ||||
</Container> | ||||
); | ||||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||
// noinspection JSUnresolvedVariable | ||||
|
||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api"; | ||||
import Container from "components/services/widget/container"; | ||||
import Block from "components/services/widget/block"; | ||||
|
@@ -10,10 +12,11 @@ const downloadReduce = (acc, e) => { | |||
}; | ||||
|
||||
const items = [ | ||||
{ label: "openmediavault.downloading", getNumber: (data) => (!data ? null : data.reduce(downloadReduce, 0)) }, | ||||
{ label: "openmediavault.total", getNumber: (data) => (!data ? null : data?.length) }, | ||||
{ label: "openmediavault.downloading", getNumber: (data) => data.reduce(downloadReduce, 0) }, | ||||
{ label: "openmediavault.total", getNumber: (data) => data?.length }, | ||||
]; | ||||
|
||||
// noinspection DuplicatedCode | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
export default function Component({ service }) { | ||||
const { data, error } = useWidgetAPI(service.widget); | ||||
|
||||
|
@@ -23,7 +26,7 @@ export default function Component({ service }) { | |||
|
||||
const itemsWithData = items.map((item) => ({ | ||||
...item, | ||||
number: item.getNumber(data?.response?.data), | ||||
number: data?.response?.data ? item.getNumber(data?.response?.data) : null, | ||||
})); | ||||
|
||||
return ( | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -16,11 +16,12 @@ const notRunningReduce = (acc, e) => { | |||
}; | ||||
|
||||
const items = [ | ||||
{ label: "openmediavault.running", getNumber: (data) => (!data ? null : data.reduce(isRunningReduce, 0)) }, | ||||
{ label: "openmediavault.stopped", getNumber: (data) => (!data ? null : data.reduce(notRunningReduce, 0)) }, | ||||
{ label: "openmediavault.total", getNumber: (data) => (!data ? null : data?.length) }, | ||||
{ label: "openmediavault.running", getNumber: (data) => data.reduce(isRunningReduce, 0) }, | ||||
{ label: "openmediavault.stopped", getNumber: (data) => data.reduce(notRunningReduce, 0) }, | ||||
{ label: "openmediavault.total", getNumber: (data) => data?.length }, | ||||
]; | ||||
|
||||
// noinspection DuplicatedCode | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
export default function Component({ service }) { | ||||
const { data, error } = useWidgetAPI(service.widget); | ||||
|
||||
|
@@ -30,7 +31,7 @@ export default function Component({ service }) { | |||
|
||||
const itemsWithData = items.map((item) => ({ | ||||
...item, | ||||
number: item.getNumber(data?.response?.data), | ||||
number: data?.response?.data ? item.getNumber(data?.response?.data) : null, | ||||
})); | ||||
|
||||
return ( | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||
// noinspection JSUnresolvedVariable | ||||
|
||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api"; | ||||
import Container from "components/services/widget/container"; | ||||
import Block from "components/services/widget/block"; | ||||
|
@@ -16,8 +18,8 @@ const failedReduce = (acc, e) => { | |||
}; | ||||
|
||||
const items = [ | ||||
{ label: "openmediavault.passed", getNumber: (data) => (!data ? null : data.reduce(passedReduce, 0)) }, | ||||
{ label: "openmediavault.failed", getNumber: (data) => (!data ? null : data.reduce(failedReduce, 0)) }, | ||||
{ label: "openmediavault.passed", getNumber: (data) => data.reduce(passedReduce, 0) }, | ||||
{ label: "openmediavault.failed", getNumber: (data) => data.reduce(failedReduce, 0) }, | ||||
]; | ||||
|
||||
export default function Component({ service }) { | ||||
|
@@ -29,7 +31,7 @@ export default function Component({ service }) { | |||
|
||||
const itemsWithData = items.map((item) => ({ | ||||
...item, | ||||
number: item.getNumber(JSON.parse(data?.response?.output || "{}")?.data), | ||||
number: data?.response?.output ? item.getNumber(JSON.parse(data?.response?.output || "{}")?.data) : null, | ||||
})); | ||||
|
||||
return ( | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||
// noinspection JSUnresolvedVariable | ||||
|
||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
import { formatApiCall } from "utils/proxy/api-helpers"; | ||||
import { httpProxy } from "utils/proxy/http"; | ||||
import getServiceWidget from "utils/config/service-helpers"; | ||||
|
@@ -11,6 +13,7 @@ const BG_POLL_PERIOD = 500; | |||
|
||||
const logger = createLogger(PROXY_NAME); | ||||
|
||||
// noinspection DuplicatedCode | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
async function getWidget(req) { | ||||
const { group, service } = req.query; | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.