🚑 Fix Error with latest Dashdot changes (#725)

This commit is contained in:
Mauz
2023-02-22 22:04:09 +01:00
committed by GitHub
parent f56f4b33ce
commit fddcfb3f06
4 changed files with 47 additions and 14 deletions

View File

@@ -57,9 +57,12 @@ export function WrapperContent({ apps, refs, widgets }: WrapperContentProps) {
{...widget.shape[shapeSize]?.location} {...widget.shape[shapeSize]?.location}
{...widget.shape[shapeSize]?.size} {...widget.shape[shapeSize]?.size}
> >
<WidgetWrapper className="grid-stack-item-content" widget={widget} widgetId={widget.id}> <WidgetWrapper
<definition.component className="grid-stack-item-content" widget={widget} /> className="grid-stack-item-content"
</WidgetWrapper> widget={widget}
widgetId={widget.id}
WidgetComponent={definition.component}
/>
</GridstackTileWrapper> </GridstackTileWrapper>
); );
})} })}

View File

@@ -1,4 +1,5 @@
import { ReactNode } from 'react'; import { ComponentType, useMemo } from 'react';
import Widgets from '.';
import { HomarrCardWrapper } from '../components/Dashboard/Tiles/HomarrCardWrapper'; import { HomarrCardWrapper } from '../components/Dashboard/Tiles/HomarrCardWrapper';
import { WidgetsMenu } from '../components/Dashboard/Tiles/Widgets/WidgetsMenu'; import { WidgetsMenu } from '../components/Dashboard/Tiles/Widgets/WidgetsMenu';
import { IWidget } from './widgets'; import { IWidget } from './widgets';
@@ -7,12 +8,41 @@ interface WidgetWrapperProps {
widgetId: string; widgetId: string;
widget: IWidget<string, any>; widget: IWidget<string, any>;
className: string; className: string;
children: ReactNode; WidgetComponent: ComponentType<{ widget: IWidget<string, any> }>;
} }
export const WidgetWrapper = ({ widgetId, widget, className, children }: WidgetWrapperProps) => ( // If a property has no value, set it to the default value
const useWidget = <T extends IWidget<string, any>>(widget: T): T => {
const definition = Widgets[widget.id as keyof typeof Widgets];
return useMemo(() => {
const newProps = { ...widget.properties };
Object.entries(definition.options).forEach(([key, option]) => {
if (newProps[key] == null) {
newProps[key] = option.defaultValue;
}
});
return {
...widget,
properties: newProps,
};
}, [widget]);
};
export const WidgetWrapper = ({
widgetId,
widget,
className,
WidgetComponent,
}: WidgetWrapperProps) => {
const widgetWithDefaultProps = useWidget(widget);
return (
<HomarrCardWrapper className={className}> <HomarrCardWrapper className={className}>
<WidgetsMenu integration={widgetId} widget={widget} /> <WidgetsMenu integration={widgetId} widget={widgetWithDefaultProps} />
{children} <WidgetComponent widget={widgetWithDefaultProps} />
</HomarrCardWrapper> </HomarrCardWrapper>
); );
};

View File

@@ -43,7 +43,7 @@ const definition = defineWidget({
component: CalendarTile, component: CalendarTile,
}); });
export type ICalendarWidget = IWidget<typeof definition['id'], typeof definition>; export type ICalendarWidget = IWidget<(typeof definition)['id'], typeof definition>;
interface CalendarTileProps { interface CalendarTileProps {
widget: ICalendarWidget; widget: ICalendarWidget;
@@ -124,7 +124,7 @@ const getReleasedMediasForDate = (
date: Date, date: Date,
widget: ICalendarWidget widget: ICalendarWidget
): MediasType => { ): MediasType => {
const radarrReleaseType = widget.properties.radarrReleaseType ?? 'inCinemas'; const { radarrReleaseType } = widget.properties;
const books = const books =
medias?.books.filter((b) => new Date(b.releaseDate).toDateString() === date.toDateString()) ?? medias?.books.filter((b) => new Date(b.releaseDate).toDateString() === date.toDateString()) ??

View File

@@ -188,7 +188,7 @@ function DashDotTile({ widget }: DashDotTileProps) {
{graphsOrder {graphsOrder
.filter((g) => g.subValues.enabled) .filter((g) => g.subValues.enabled)
.map((g) => ( .map((g) => (
<Grid.Col span={Math.min(columns, g.subValues.span)}> <Grid.Col key={g.key} span={Math.min(columns, g.subValues.span)}>
<DashDotGraph <DashDotGraph
dashDotUrl={dashDotUrl} dashDotUrl={dashDotUrl}
info={info} info={info}