fix paint layers
This commit is contained in:
parent
fa4f2841f3
commit
e1f36ce9df
4 changed files with 44 additions and 21 deletions
|
|
@ -72,7 +72,7 @@ const RotationForm: FC<RotationFormProps> = observer((props) => {
|
|||
shiftColor = '#3D71D9',
|
||||
} = props;
|
||||
|
||||
console.log('shiftColor', shiftColor);
|
||||
// console.log('shiftColor', shiftColor);
|
||||
|
||||
const [isOpen, setIsOpen] = useState<boolean>(false);
|
||||
|
||||
|
|
@ -100,9 +100,10 @@ const RotationForm: FC<RotationFormProps> = observer((props) => {
|
|||
|
||||
const coords = getCoords(elm);
|
||||
|
||||
// elm.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'nearest' });
|
||||
// setOffsetTop(Math.max(coords.top + elm.offsetHeight, 0));
|
||||
|
||||
setOffsetTop(coords.top - modal?.offsetHeight - 10);
|
||||
setOffsetTop(Math.max(coords.top - modal?.offsetHeight - 10, 10));
|
||||
});
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
|
@ -176,6 +177,7 @@ const RotationForm: FC<RotationFormProps> = observer((props) => {
|
|||
shiftId,
|
||||
layerPriority,
|
||||
shift,
|
||||
endLess,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ const ScheduleOverrideForm: FC<RotationFormProps> = (props) => {
|
|||
|
||||
const coords = getCoords(elm);
|
||||
|
||||
setOffsetTop(coords.top - modal?.offsetHeight - 10);
|
||||
setOffsetTop(Math.max(coords.top - modal?.offsetHeight - 10, 10));
|
||||
});
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
|
|
|||
|
|
@ -1,21 +1,38 @@
|
|||
import { getColor, getOverrideColor } from 'models/schedule/schedule.helpers';
|
||||
import { Layer, Shift } from 'models/schedule/schedule.types';
|
||||
|
||||
export const findColor = (shiftId, layers, overrides?) => {
|
||||
export const findColor = (shiftId: Shift['id'], layers: Layer[], overrides?) => {
|
||||
let color = undefined;
|
||||
|
||||
const layerIndex = layers ? layers.findIndex((layer) => layer.shifts.some((shift) => shift.shiftId === shiftId)) : -1;
|
||||
let layerIndex = -1;
|
||||
let rotationIndex = -1;
|
||||
if (layers) {
|
||||
outer: for (var i = 0; i < layers.length; i++) {
|
||||
for (var j = 0; j < layers[i].shifts.length; j++) {
|
||||
const shift = layers[i].shifts[j];
|
||||
if (shift.shiftId === shiftId || (shiftId === 'new' && shift.isPreview)) {
|
||||
layerIndex = i;
|
||||
rotationIndex = j;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rotationIndex =
|
||||
layerIndex > -1 ? layers[layerIndex].shifts.findIndex((shift) => shift.shiftId === shiftId) : -1;
|
||||
let overrideIndex = -1;
|
||||
if (layerIndex === -1 && rotationIndex === -1 && overrides) {
|
||||
for (var k = 0; k < overrides.length; k++) {
|
||||
const shift = overrides[k];
|
||||
if (shift.shiftId === shiftId || (shiftId === 'new' && shift.isPreview)) {
|
||||
overrideIndex = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (layerIndex > -1 && rotationIndex > -1) {
|
||||
color = getColor(layerIndex, rotationIndex);
|
||||
} else if (overrides) {
|
||||
const overrideIndex = overrides ? overrides.findIndex((shift) => shift.shiftId === shiftId) : -1;
|
||||
|
||||
if (overrideIndex > -1) {
|
||||
color = getOverrideColor(overrideIndex);
|
||||
}
|
||||
} else if (overrideIndex > -1) {
|
||||
color = getOverrideColor(overrideIndex);
|
||||
}
|
||||
|
||||
return color;
|
||||
|
|
|
|||
|
|
@ -89,25 +89,28 @@ export const enrichLayers = (
|
|||
shiftId: Shift['id'] | 'new',
|
||||
priority: Shift['priority_level']
|
||||
) => {
|
||||
let shiftIdFromEvent = shiftId;
|
||||
if (shiftId === 'new') {
|
||||
const event = newEvents.find((event) => !event.is_gap);
|
||||
if (event) {
|
||||
shiftId = event.shift.pk;
|
||||
shiftIdFromEvent = event.shift.pk;
|
||||
}
|
||||
}
|
||||
|
||||
const updatingLayer = {
|
||||
priority,
|
||||
shifts: [
|
||||
{ shiftId: shiftId, isPreview: true, events: fillGaps(newEvents.filter((event: Event) => !event.is_gap)) },
|
||||
{
|
||||
shiftId: shiftIdFromEvent,
|
||||
isPreview: true,
|
||||
events: fillGaps(newEvents.filter((event: Event) => !event.is_gap)),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const isNew = updatingLayer.shifts[0].shiftId === 'new';
|
||||
|
||||
let added = false;
|
||||
layers = layers.reduce((memo, layer, index) => {
|
||||
if (isNew) {
|
||||
if (shiftId === 'new') {
|
||||
if (layer.priority === priority) {
|
||||
const newLayer = { ...layer };
|
||||
newLayer.shifts = [...layer.shifts, ...updatingLayer.shifts];
|
||||
|
|
@ -144,14 +147,15 @@ export const enrichOverrides = (
|
|||
newEvents: Event[],
|
||||
shiftId: Shift['id']
|
||||
) => {
|
||||
let shiftIdFromEvent = shiftId;
|
||||
if (shiftId === 'new') {
|
||||
const event = newEvents.find((event) => !event.is_gap);
|
||||
if (event) {
|
||||
shiftId = event.shift.pk;
|
||||
shiftIdFromEvent = event.shift.pk;
|
||||
}
|
||||
}
|
||||
|
||||
const newShift = { shiftId, isPreview: true, events: fillGaps(newEvents) };
|
||||
const newShift = { shiftId: shiftIdFromEvent, isPreview: true, events: fillGaps(newEvents) };
|
||||
|
||||
const index = overrides.findIndex((shift) => shift.shiftId === shiftId);
|
||||
|
||||
|
|
@ -172,7 +176,7 @@ const L3_COLORS = ['#377277', '#638282', '#364E4E', '#423220'];
|
|||
|
||||
const OVERRIDE_COLORS = ['#C69B06', '#C2C837'];
|
||||
|
||||
const COLORS = [L1_COLORS, L2_COLORS, L3_COLORS, OVERRIDE_COLORS];
|
||||
const COLORS = [L1_COLORS, L2_COLORS, L3_COLORS];
|
||||
|
||||
export const getColor = (layerIndex: number, rotationIndex: number) => {
|
||||
const normalizedLayerIndex = layerIndex % COLORS.length;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue