Skip to content

Calendar Component - Bugfixes and Premium views #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 4, 2024
Merged
Prev Previous commit
Next Next commit
added licence key data field
  • Loading branch information
freddysundowner committed Feb 22, 2024
commit ebfbdfdfd794e58923ee1952fd9593bfb5bc7708
4 changes: 3 additions & 1 deletion client/packages/lowcoder-comps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lowcoder-comps",
"version": "0.0.24",
"version": "0.0.25",
"type": "module",
"license": "MIT",
"dependencies": {
Expand All @@ -10,6 +10,8 @@
"@fullcalendar/list": "^6.1.9",
"@fullcalendar/moment": "^6.1.6",
"@fullcalendar/react": "^6.1.6",
"@fullcalendar/resource": "^6.1.11",
"@fullcalendar/resource-timeline": "^6.1.11",
"@fullcalendar/timegrid": "^6.1.6",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { default as Form } from "antd/es/form";
import { default as Input } from "antd/es/input";
import { trans, getCalendarLocale } from "../../i18n/comps";
import { createRef, useContext, useRef, useState } from "react";
import resourceTimelinePlugin from "@fullcalendar/resource-timeline";
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import timeGridPlugin from "@fullcalendar/timegrid";
Expand Down Expand Up @@ -66,8 +67,9 @@ const childrenMap = {
dayMaxEvents: withDefault(NumberControl, 2),
eventMaxStack: withDefault(NumberControl, 0),
style: styleControl(CalendarStyle),
licenceKey: withDefault(StringControl, ""),
};

let CalendarBasicComp = (function () {
return new UICompBuilder(childrenMap, (props) => {
const theme = useContext(ThemeContext);
Expand All @@ -83,7 +85,9 @@ let CalendarBasicComp = (function () {
start: dayjs(item.start, DateParser).format(),
end: dayjs(item.end, DateParser).format(),
allDay: item.allDay,
color: isValidColor(item.color || "") ? item.color : theme?.theme?.primary,
color: isValidColor(item.color || "")
? item.color
: theme?.theme?.primary,
...(item.groupId ? { groupId: item.groupId } : null),
};
});
Expand All @@ -104,8 +108,13 @@ let CalendarBasicComp = (function () {
function renderEventContent(eventInfo: EventContentArg) {
const isList = eventInfo.view.type === "listWeek";
let sizeClass = "";
if ([ViewType.WEEK, ViewType.DAY].includes(eventInfo.view.type as ViewType)) {
const duration = dayjs(eventInfo.event.end).diff(dayjs(eventInfo.event.start), "minutes");
if (
[ViewType.WEEK, ViewType.DAY].includes(eventInfo.view.type as ViewType)
) {
const duration = dayjs(eventInfo.event.end).diff(
dayjs(eventInfo.event.start),
"minutes"
);
if (duration <= 30 || eventInfo.event.allDay) {
sizeClass = "small";
} else if (duration <= 60) {
Expand Down Expand Up @@ -137,7 +146,9 @@ let CalendarBasicComp = (function () {
onClick={(e) => {
e.stopPropagation();
props.onEvent("change");
const event = events.filter((item: EventType) => item.id !== eventInfo.event.id);
const event = events.filter(
(item: EventType) => item.id !== eventInfo.event.id
);
props.events.onChange(event);
}}
onMouseDown={(e) => {
Expand Down Expand Up @@ -195,7 +206,9 @@ let CalendarBasicComp = (function () {
};

const showModal = (event: EventType, ifEdit: boolean) => {
const modalTitle = ifEdit ? trans("calendar.editEvent") : trans("calendar.creatEvent");
const modalTitle = ifEdit
? trans("calendar.editEvent")
: trans("calendar.creatEvent");
form && form.setFieldsValue(event);
const eventId = editEvent.current?.id;
CustomModal.confirm({
Expand All @@ -209,14 +222,18 @@ let CalendarBasicComp = (function () {
</Tooltip>
}
name="id"
rules={[{ required: true, message: trans("calendar.eventIdRequire") }]}
rules={[
{ required: true, message: trans("calendar.eventIdRequire") },
]}
>
<Input />
</Form.Item>
<Form.Item
label={trans("calendar.eventName")}
name="title"
rules={[{ required: true, message: trans("calendar.eventNameRequire") }]}
rules={[
{ required: true, message: trans("calendar.eventNameRequire") },
]}
>
<Input />
</Form.Item>
Expand All @@ -239,9 +256,13 @@ let CalendarBasicComp = (function () {
form.submit();
return form.validateFields().then(() => {
const { id, groupId, color, title = "" } = form.getFieldsValue();
const idExist = props.events.value.findIndex((item: EventType) => item.id === id);
const idExist = props.events.value.findIndex(
(item: EventType) => item.id === id
);
if (idExist > -1 && id !== eventId) {
form.setFields([{ name: "id", errors: [trans("calendar.eventIdExist")] }]);
form.setFields([
{ name: "id", errors: [trans("calendar.eventIdExist")] },
]);
throw new Error();
}
if (ifEdit) {
Expand Down Expand Up @@ -306,7 +327,14 @@ let CalendarBasicComp = (function () {
locale={getCalendarLocale()}
locales={allLocales}
firstDay={Number(firstDay)}
plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin, listPlugin, momentPlugin]}
plugins={[
dayGridPlugin,
timeGridPlugin,
interactionPlugin,
listPlugin,
momentPlugin,
resourceTimelinePlugin,
]}
headerToolbar={headerToolbar}
moreLinkClick={(info) => {
let left = 0;
Expand All @@ -319,15 +347,19 @@ let CalendarBasicComp = (function () {
}
} else {
if (info.allDay) {
left = ele.offsetParent?.parentElement?.parentElement?.offsetLeft || 0;
left =
ele.offsetParent?.parentElement?.parentElement?.offsetLeft ||
0;
} else {
left =
ele.offsetParent?.parentElement?.parentElement?.parentElement?.offsetLeft || 0;
ele.offsetParent?.parentElement?.parentElement?.parentElement
?.offsetLeft || 0;
}
}
setLeft(left);
}}
buttonText={buttonText}
schedulerLicenseKey={props.licenceKey.value}
views={views}
eventClassNames={() => (!showEventTime ? "no-time" : "")}
slotLabelFormat={slotLabelFormat}
Expand All @@ -346,7 +378,9 @@ let CalendarBasicComp = (function () {
eventContent={renderEventContent}
select={(info) => handleCreate(info)}
eventClick={(info) => {
const event = events.find((item: EventType) => item.id === info.event.id);
const event = events.find(
(item: EventType) => item.id === info.event.id
);
editEvent.current = event;
setTimeout(() => {
editEvent.current = undefined;
Expand Down Expand Up @@ -387,12 +421,19 @@ let CalendarBasicComp = (function () {
.setPropertyViewFn((children) => {
return (
<>
<Section name={sectionNames.basic}>{children.events.propertyView({})}</Section>
<Section name={sectionNames.interaction}>{children.onEvent.getPropertyView()}</Section>
<Section name={sectionNames.basic}>
{children.events.propertyView({})}
</Section>
<Section name={sectionNames.interaction}>
{children.licenceKey.propertyView({
label: trans("calendar.licence"),
})}
{children.onEvent.getPropertyView()}
</Section>
<Section name={sectionNames.advanced}>
{children.editable.propertyView({
label: trans("calendar.editable"),
})}
label: trans("calendar.editable"),
})}
{children.defaultDate.propertyView({
label: trans("calendar.defaultDate"),
tooltip: trans("calendar.defaultDateTooltip"),
Expand Down Expand Up @@ -424,8 +465,12 @@ let CalendarBasicComp = (function () {
tooltip: trans("calendar.eventMaxStackTooltip"),
})}
</Section>
<Section name={sectionNames.layout}>{hiddenPropertyView(children)}</Section>
<Section name={sectionNames.style}>{children.style.getPropertyView()}</Section>
<Section name={sectionNames.layout}>
{hiddenPropertyView(children)}
</Section>
<Section name={sectionNames.style}>
{children.style.getPropertyView()}
</Section>
</>
);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export const Wrapper = styled.div<{
flex-direction: inherit;
}
.fc-day-today .fc-daygrid-day-number {
background-color: ${(props) => props.$theme.primary};
background-color: ${(props) => props.$theme?.primary};
color: ${(props) =>
contrastText(props.$theme.primary || "", props.$theme.textDark, props.$theme.textLight)};
contrastText(props.$theme?.primary || "", props.$theme?.textDark, props.$theme?.textLight)};
}
.fc-daygrid-day-events {
padding: 1px 0 5px 0;
Expand Down Expand Up @@ -585,10 +585,10 @@ export const Wrapper = styled.div<{
}
.fc-day-today.fc-col-header-cell {
background-color: ${(props) =>
isDarkColor(props.$style.background) ? "#ffffff19" : toHex(props.$theme.primary!) + "19"};
isDarkColor(props.$style.background) ? "#ffffff19" : toHex(props.$theme?.primary!) + "19"};
a {
color: ${(props) =>
!isDarkColor(props.$style.background) && darkenColor(props.$theme.primary!, 0.1)};
!isDarkColor(props.$style.background) && darkenColor(props.$theme?.primary!, 0.1)};
}
}
.fc-col-header-cell-cushion {
Expand Down
Loading