Skip to content

Commit 8f40fa0

Browse files
update data on events drag/drop
1 parent ccbdc6d commit 8f40fa0

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import adaptivePlugin from "@fullcalendar/adaptive";
1212
import dayGridPlugin from "@fullcalendar/daygrid";
1313
import multiMonthPlugin from '@fullcalendar/multimonth';
1414
import timeGridPlugin from "@fullcalendar/timegrid";
15-
import interactionPlugin from "@fullcalendar/interaction";
15+
import interactionPlugin, { EventResizeDoneArg } from "@fullcalendar/interaction";
1616
import listPlugin from "@fullcalendar/list";
1717
import allLocales from "@fullcalendar/core/locales-all";
18-
import { EventContentArg, DateSelectArg } from "@fullcalendar/core";
18+
import { EventContentArg, DateSelectArg, EventDropArg } from "@fullcalendar/core";
1919
import momentPlugin from "@fullcalendar/moment";
2020

2121
import ErrorBoundary from "./errorBoundary";
@@ -83,6 +83,7 @@ import {
8383
resourceTimeGridHeaderToolbar,
8484
} from "./calendarConstants";
8585
import { EventOptionControl } from "./eventOptionsControl";
86+
import { EventImpl } from "@fullcalendar/core/internal";
8687

8788
function fixOldData(oldData: any) {
8889
if(!Boolean(oldData)) return;
@@ -823,20 +824,34 @@ let CalendarBasicComp = (function () {
823824
showModal(event, false);
824825
}, [editEvent, showModal]);
825826

826-
const handleDrop = useCallback((eventInfo: EventType) => {
827+
const updateEventsOnDragOrResize = useCallback((eventInfo: EventImpl) => {
828+
const {extendedProps, title, ...event} = eventInfo.toJSON();
829+
827830
let eventsList = [...props.events];
828831
const eventIdx = eventsList.findIndex(
829-
(item: EventType) => item.id === eventInfo.id
832+
(item: EventType) => item.id === event.id
830833
);
831834
if (eventIdx > -1) {
832-
eventsList[eventIdx] = eventInfo;
835+
eventsList[eventIdx] = {
836+
label: title,
837+
...event,
838+
...extendedProps,
839+
};
833840
handleEventDataChange(eventsList);
834841
}
842+
}, [props.events, handleEventDataChange]);
843+
844+
const handleDrop = useCallback((eventInfo: EventDropArg) => {
845+
updateEventsOnDragOrResize(eventInfo.event);
835846

836847
if (typeof props.onDropEvent === 'function') {
837848
props.onDropEvent("dropEvent");
838849
}
839-
}, [props.onDropEvent]);
850+
}, [props.onDropEvent, updateEventsOnDragOrResize]);
851+
852+
const handleResize = useCallback((eventInfo: EventResizeDoneArg) => {
853+
updateEventsOnDragOrResize(eventInfo.event);
854+
}, [props.onDropEvent, updateEventsOnDragOrResize]);
840855

841856
return (
842857
<Wrapper
@@ -854,7 +869,7 @@ let CalendarBasicComp = (function () {
854869
slotEventOverlap={false}
855870
events={ events }
856871
dayHeaders={true}
857-
dayHeaderFormat={{ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }}
872+
// dayHeaderFormat={{ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }}
858873
expandRows={true}
859874
multiMonthMinWidth={250}
860875
nowIndicator={true}
@@ -944,15 +959,8 @@ let CalendarBasicComp = (function () {
944959
props.onEvent("change");
945960
}
946961
}}
947-
eventDrop={(info) => {
948-
const {extendedProps, ...event} = info.event.toJSON();
949-
if (info.view) {
950-
handleDrop({
951-
...event,
952-
...extendedProps,
953-
});
954-
}
955-
}}
962+
eventDrop={handleDrop}
963+
eventResize={handleResize}
956964
/>
957965
</ErrorBoundary>
958966
</Wrapper>

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -988,25 +988,6 @@ export const defaultEvents = [
988988
end: dayjs().hour(21).minute(30).second(0).format(DATE_TIME_FORMAT),
989989
color: "#079968",
990990
},
991-
{
992-
id: "6",
993-
label: "Coding",
994-
start: dayjs().hour(15).minute(0).second(0).format(DATE_TIME_FORMAT),
995-
end: dayjs().hour(17).minute(30).second(0).format(DATE_TIME_FORMAT),
996-
color: "#079968",
997-
backgroundColor:"#ffffff",
998-
detail: 'Discuss project milestones and deliverables.',
999-
titleColor:"#000000",
1000-
detailColor:"#000000",
1001-
titleFontWeight:"normal",
1002-
titleFontStyle:"italic",
1003-
detailFontWeight:"normal",
1004-
detailFontStyle:"italic",
1005-
animation:"none",
1006-
animationDelay:"0s",
1007-
animationDuration:"0s",
1008-
animationIterationCount:"0",
1009-
},
1010991
];
1011992
export const resourcesEventsDefaultData = [
1012993
{

0 commit comments

Comments
 (0)