Skip to content

Commit

Permalink
Merge branch 'feat/get_toolbar' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jan 29, 2025
2 parents 5791843 + f043786 commit 7e121bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/models/erpFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum ErpFeatureKeys {
FEATURE_OMNISEARCH = "omnisearch",
FEATURE_READFORVIEW = "read_for_view",
FEATURE_USERVIEWPREFS = "user_view_prefs",
FEATURE_GET_TOOLBAR = "get_toolbar",
// ... add more features here
}

Expand Down
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ type GetViewRequest = {
context?: any;
};

type GetToolbarRequest = {
model: string;
id?: number;
type: ViewType;
context?: any;
};

type GetFieldsRequest = {
model: string;
fields?: string[];
Expand Down Expand Up @@ -383,6 +390,7 @@ type ConnectionProviderType = {
{ key }: { key: string },
requestConfig?: any,
) => Promise<any>;
getToolbar: (options: GetViewRequest, requestConfig?: any) => Promise<any>;
};

type ViewType = "tree" | "form" | "dashboard" | "graph" | "calendar";
Expand Down
26 changes: 17 additions & 9 deletions src/widgets/base/one2many/One2many.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from "@/widgets/base/one2many/One2manyInputInfinite";
import useDeepCompareEffect from "use-deep-compare-effect";
import { FormContext, FormContextType } from "@/context/FormContext";
import { useFeatureIsEnabled } from "@/context/ConfigContext";
import { ErpFeatureKeys } from "@/models/erpFeature";

const MIN_ITEMS_TO_USE_INFINITE = 30;

Expand All @@ -35,18 +37,24 @@ export const One2many = (props: Props) => {
fetchData();
}, [ooui]);

const getViewData = async (type: ViewType) => {
const getViewPromise = ConnectionProvider.getHandler().getView({
model: relation,
type,
context: { ...getContext?.(), ...context },
});
const getToolbarEnabled = useFeatureIsEnabled(
ErpFeatureKeys.FEATURE_GET_TOOLBAR,
);

const getViewData = async (type: ViewType) => {
if (oouiViews && oouiViews[type]) {
const view = oouiViews[type];
if (!view.toolbar && (type === "form" || type === "tree")) {
const viewWithToolbar: TreeView | FormView = await getViewPromise;
return { ...view, toolbar: viewWithToolbar.toolbar };
if (
getToolbarEnabled &&
!view.toolbar &&
(type === "form" || type === "tree")
) {
const toolbar = await ConnectionProvider.getHandler().getToolbar({
model: relation,
type,
context: { ...getContext?.(), ...context },
});
return { ...view, toolbar };
}
return view;
}
Expand Down

0 comments on commit 7e121bd

Please sign in to comment.