Skip to content

Commit 1786173

Browse files
author
FalkWolsky
committed
Improving conditional withMethodExposing rendering for backwards compatibility
1 parent f253a14 commit 1786173

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

client/packages/lowcoder-comps/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lowcoder-comps",
3-
"version": "0.0.37",
3+
"version": "0.0.38",
44
"type": "module",
55
"license": "MIT",
66
"dependencies": {

client/packages/lowcoder-comps/src/comps/calendarComp/calendarComp.tsx

+25-14
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {
4343
jsonValueExposingStateControl,
4444
CalendarDeleteIcon,
4545
Tooltip,
46+
AbstractComp,
47+
MultiBaseComp,
4648
} from "lowcoder-sdk";
4749

4850
import {
@@ -71,6 +73,7 @@ import {
7173

7274
// this should ensure backwards compatibility with older versions of the SDK
7375
const safeDragEventHandlerControl = typeof DragEventHandlerControl !== 'undefined' ? DragEventHandlerControl : () => {};
76+
const isVariantCompAvailable = typeof AbstractComp !== 'undefined' && AbstractComp !== null && typeof MultiBaseComp !== 'undefined' && MultiBaseComp !== null;
7477

7578
const childrenMap = {
7679
events: jsonValueExposingStateControl("events", defaultData),
@@ -624,17 +627,25 @@ const TmpCalendarComp = withExposingConfigs(CalendarBasicComp, [
624627
NameConfigHidden,
625628
]);
626629

627-
export const CalendarComp = withMethodExposing(TmpCalendarComp, [
628-
{
629-
method: {
630-
name: "setCalendarView",
631-
description: "timeGridWeek || timeGridDay || dayGridMonth || listWeek || resourceTimelineDay || resourceTimeGridDay || resourceTimelineWeek || resourceTimelineMonth",
632-
params: [{ name: "viewType", type: "string" }],
633-
},
634-
execute: (comp, values) => {
635-
const viewType = values[0] as string;
636-
viewType == "" ? viewType : "timeGridWeek";
637-
return comp.children.licenseKey.getView() == "" ? comp.children.defaultFreeView.dispatchChangeValueAction(viewType) : comp.children.defaultPremiumView.dispatchChangeValueAction(viewType);
638-
}
639-
},
640-
]);
630+
let CalendarComp;
631+
632+
if (isVariantCompAvailable) {
633+
CalendarComp = withMethodExposing(TmpCalendarComp, [
634+
{
635+
method: {
636+
name: "setCalendarView",
637+
description: "Sets the view of the calendar to a specified type",
638+
params: [{ name: "viewType", type: "string" }],
639+
},
640+
execute: (comp, values) => {
641+
const viewType = values[0] as string || "timeGridWeek"; // Default to "timeGridWeek" if undefined
642+
const viewKey = comp.children.licenseKey.getView() === "" ? 'defaultFreeView' : 'defaultPremiumView';
643+
comp.children[viewKey].dispatchChangeValueAction(viewType);
644+
}
645+
},
646+
]);
647+
} else {
648+
CalendarComp = TmpCalendarComp;
649+
}
650+
651+
export { CalendarComp };

0 commit comments

Comments
 (0)