diff --git a/grafana-plugin/src/containers/RotationForm/RotationForm.tsx b/grafana-plugin/src/containers/RotationForm/RotationForm.tsx index 2181b83c..3c19b25d 100644 --- a/grafana-plugin/src/containers/RotationForm/RotationForm.tsx +++ b/grafana-plugin/src/containers/RotationForm/RotationForm.tsx @@ -72,7 +72,7 @@ const RotationForm: FC = observer((props) => { shiftColor = '#3D71D9', } = props; - console.log('shiftColor', shiftColor); + // console.log('shiftColor', shiftColor); const [isOpen, setIsOpen] = useState(false); @@ -100,9 +100,10 @@ const RotationForm: FC = 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 = observer((props) => { shiftId, layerPriority, shift, + endLess, ] ); diff --git a/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx b/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx index 31fd7c51..bb4d5b81 100644 --- a/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx +++ b/grafana-plugin/src/containers/RotationForm/ScheduleOverrideForm.tsx @@ -77,7 +77,7 @@ const ScheduleOverrideForm: FC = (props) => { const coords = getCoords(elm); - setOffsetTop(coords.top - modal?.offsetHeight - 10); + setOffsetTop(Math.max(coords.top - modal?.offsetHeight - 10, 10)); }); } }, [isOpen]); diff --git a/grafana-plugin/src/containers/Rotations/Rotations.helpers.ts b/grafana-plugin/src/containers/Rotations/Rotations.helpers.ts index b6b69c5e..91225e8b 100644 --- a/grafana-plugin/src/containers/Rotations/Rotations.helpers.ts +++ b/grafana-plugin/src/containers/Rotations/Rotations.helpers.ts @@ -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; diff --git a/grafana-plugin/src/models/schedule/schedule.helpers.ts b/grafana-plugin/src/models/schedule/schedule.helpers.ts index f6285217..d626d32e 100644 --- a/grafana-plugin/src/models/schedule/schedule.helpers.ts +++ b/grafana-plugin/src/models/schedule/schedule.helpers.ts @@ -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;