MCPcopy Index your code
hub / github.com/apitable/apitable / getLevels

Function getLevels

packages/components/src/components/calendar/utils.ts:156–218  ·  view source on GitHub ↗
({ week, year, tasks, resizeMsg }: ILevel)

Source from the content-addressed store, hash-verified

154};
155
156export const getLevels = ({ week, year, tasks, resizeMsg }: ILevel) => {
157 const start = week[0]!;
158 const end = week[week.length - 1]!;
159 const startDate = new Date(year, start.month - 1, start.day);
160 const endDate = new Date(year, end.month - 1, end.day);
161 let updateTasks = tasks;
162 if (resizeMsg) {
163 const { id, day, direction } = resizeMsg;
164 updateTasks = tasks.map(task => {
165 if (id === task.id) {
166 const { startDate, endDate } = task;
167 const formatData = resizeFormat({ startDate, endDate, day, direction });
168 return {
169 ...task,
170 ...formatData,
171 };
172 }
173 return task;
174 });
175 }
176
177 const rowTasks = updateTasks.filter(task =>
178 (!isAfter(date2Day(task.startDate || task.endDate), endDate) && !isAfter(startDate, task.endDate || task.startDate)) ||
179 // The start date is greater than the end date. Exception task processing
180 (isAfter(task.startDate, task.endDate) && !isBefore(task.startDate, startDate) && !isBefore(endDate, task.startDate))
181 ).map(task => {
182 const isWarning = isAfter(task.startDate, task.endDate);
183 const taskStartDate = date2Day(task.startDate || task.endDate);
184 const taskEndDate = date2Day(task.endDate || task.startDate);
185 const currMaxStartDay = date2Day(max([startDate, taskStartDate]));
186 const currMinLastDay = date2Day(min([endDate, taskEndDate]));
187 const len = isWarning ? 1 : (differenceInDays(currMinLastDay, currMaxStartDay) + 1);
188 const diffStart = differenceInDays(taskStartDate, startDate);
189 const diffEnd = differenceInDays(endDate, taskEndDate);
190 const left = diffStart < 0 ? 0 : diffStart;
191 return {
192 task,
193 len,
194 left: left + 1,
195 right: left + len,
196 isStart: diffStart >= 0 || isWarning,
197 isEmptyStart: !task.startDate,
198 isEnd: diffEnd >= 0 || isWarning,
199 isEmptyEnd: !task.endDate,
200 warn: isWarning,
201 };
202 });
203 const levels: ILevelResult[][] = [];
204 let j: number;
205 for (let i = 0; i < rowTasks.length; i++) {
206 const task = rowTasks[i]!;
207 for (j = 0; j < levels.length; j++) {
208 const isOver = levels[j]!.some(seg =>
209 seg.left <= task.right && seg.right >= task.left
210 );
211 if (!isOver) {
212 break;
213 }

Callers 1

MonthBaseFunction · 0.90

Calls 5

resizeFormatFunction · 0.85
date2DayFunction · 0.85
mapMethod · 0.45
filterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected