Skip to content

Commit

Permalink
🐛 fix(dashboard): filter portal dashbord types correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed May 31, 2024
1 parent 061e652 commit a962c51
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/frontend/views/Dashboard/Widget/_manage/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,28 @@ import { MessageDescriptor } from "@lingui/core";
import { useDomainMessages } from "frontend/lib/crud-config";
import { LANG_DOMAINS } from "frontend/lib/crud-config/lang-domains";
import { DashboardWidgetPresentation } from "../Presentation";
import { WIDGET_CONFIG } from "../constants";
import { BASE_WIDGET_CONFIG } from "../constants";
import { PortalFormFields, PortalFormSchema } from "./portal";
import { WidgetFormField } from "./types";
import { DASHBOARD_WIDGET_HEIGHTS } from "./constants";
import { usePortalDashboardTypesOptions } from "../portal";

const DashboardTypesOptions: {
const FormSchema: Partial<Record<IWidgetConfig["_type"], WidgetFormField[]>> = {
"summary-card": ["color", "icon"],
table: [],
...PortalFormSchema,
};

const baseDashboardTypesOptions: {
label: MessageDescriptor;
value: IWidgetConfig["_type"];
}[] = typescriptSafeObjectDotEntries(WIDGET_CONFIG).map(
}[] = typescriptSafeObjectDotEntries(BASE_WIDGET_CONFIG).map(
([value, { label }]) => ({
label,
value: value as IWidgetConfig["_type"],
})
);

const FormSchema: Partial<Record<IWidgetConfig["_type"], WidgetFormField[]>> = {
"summary-card": ["color", "icon"],
table: [],
...PortalFormSchema,
};

export function useRunWidgetScript() {
return useMutation({
mutationFn: async (script: string) =>
Expand Down Expand Up @@ -89,6 +90,8 @@ export function DashboardWidgetForm({
}
}, [initialValues]);

const portalDashboardTypesOptions = usePortalDashboardTypesOptions();

return (
<>
<Form
Expand Down Expand Up @@ -140,7 +143,10 @@ export function DashboardWidgetForm({
required
label={msg`Type`}
disabledOptions={[]}
selectData={DashboardTypesOptions}
selectData={[
...baseDashboardTypesOptions,
...portalDashboardTypesOptions,
]}
meta={meta}
input={input}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/views/Dashboard/Widget/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IWidgetConfigBag } from "./types";
import { TableWidgetSchema } from "./_render/Table/types";
import { SummaryCardWidgetSchema } from "./_render/Summary/types";

const BASE_WIDGET_CONFIG: Partial<
export const BASE_WIDGET_CONFIG: Partial<
Record<IWidgetConfig["_type"], IWidgetConfigBag>
> = {
table: {
Expand Down
1 change: 1 addition & 0 deletions src/frontend/views/Dashboard/Widget/portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { PORTAL_WIDGET_CONFIG } from "./main/constants";
export { PortalDashboardWidget } from "./main/DashboardWidget";
export { usePortalDashboardTypesOptions } from "./main/constants";
4 changes: 4 additions & 0 deletions src/frontend/views/Dashboard/Widget/portal/main/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ import { IWidgetConfigBag } from "../../types";
export const PORTAL_WIDGET_CONFIG: Partial<
Record<IWidgetConfig["_type"], IWidgetConfigBag>
> = {};

export const usePortalDashboardTypesOptions = () => {
return [];
};
File renamed without changes.
File renamed without changes.

0 comments on commit a962c51

Please sign in to comment.