diff --git a/grafana-plugin/src/containers/RotationForm/RotationForm.tsx b/grafana-plugin/src/containers/RotationForm/RotationForm.tsx index d3db84643f..3e60880da3 100644 --- a/grafana-plugin/src/containers/RotationForm/RotationForm.tsx +++ b/grafana-plugin/src/containers/RotationForm/RotationForm.tsx @@ -72,7 +72,6 @@ const cx = cn.bind(styles); interface RotationFormProps { layerPriority: number; onHide: () => void; - isNewRotation?: boolean; scheduleId: Schedule['id']; shiftId: Shift['id'] | 'new'; shiftStart?: dayjs.Dayjs; @@ -86,6 +85,7 @@ interface RotationFormProps { const getStartShift = (start: dayjs.Dayjs, timezoneOffset: number, isNewRotation = false) => { if (isNewRotation) { + // all new rotations default to midnight in selected timezone offset return toDateWithTimezoneOffset(start, timezoneOffset) .set('date', 1) .set('year', start.year()) @@ -114,10 +114,8 @@ export const RotationForm = observer((props: RotationFormProps) => { shiftEnd: propsShiftEnd, shiftColor = '#3D71D9', onShowRotationForm, - isNewRotation, } = props; - const [isNewRotationInit, setIsNewRotationInit] = useState(isNewRotation); const shift = store.scheduleStore.shifts[shiftId]; const [errors, setErrors] = useState<{ [key: string]: string[] }>({}); @@ -131,7 +129,7 @@ export const RotationForm = observer((props: RotationFormProps) => { const [draggablePosition, setDraggablePosition] = useState<{ x: number; y: number }>(undefined); const [shiftStart, setShiftStart] = useState( - getStartShift(propsShiftStart, store.timezoneStore.selectedTimezoneOffset, isNewRotationInit) + getStartShift(propsShiftStart, store.timezoneStore.selectedTimezoneOffset, shiftId === 'new') ); const [shiftEnd, setShiftEnd] = useState( @@ -159,8 +157,6 @@ export const RotationForm = observer((props: RotationFormProps) => { const debouncedOnResize = useDebouncedCallback(onResize, 250); useEffect(() => { - setIsNewRotationInit(false); - window.addEventListener('resize', debouncedOnResize); return () => { window.removeEventListener('resize', debouncedOnResize); diff --git a/grafana-plugin/src/containers/Rotations/Rotations.tsx b/grafana-plugin/src/containers/Rotations/Rotations.tsx index 8abb13d21e..18f56566bf 100644 --- a/grafana-plugin/src/containers/Rotations/Rotations.tsx +++ b/grafana-plugin/src/containers/Rotations/Rotations.tsx @@ -50,7 +50,6 @@ interface RotationsProps extends WithStoreProps { interface RotationsState { shiftStartToShowRotationForm?: dayjs.Dayjs; shiftEndToShowRotationForm?: dayjs.Dayjs; - isNewRotation?: boolean; } @observer @@ -58,7 +57,6 @@ class _Rotations extends Component { state: RotationsState = { shiftStartToShowRotationForm: undefined, shiftEndToShowRotationForm: undefined, - isNewRotation: false, }; render() { @@ -77,7 +75,7 @@ class _Rotations extends Component { theme, } = this.props; - const { shiftStartToShowRotationForm, shiftEndToShowRotationForm, isNewRotation } = this.state; + const { shiftStartToShowRotationForm, shiftEndToShowRotationForm } = this.state; const { selectedTimezoneOffset } = store.timezoneStore; @@ -260,7 +258,6 @@ class _Rotations extends Component { {shiftIdToShowRotationForm && ( { layerPriority: number, shiftStart?: dayjs.Dayjs, shiftEnd?: dayjs.Dayjs, - isNewRotation?: boolean ) => { const { disabled } = this.props; @@ -322,7 +318,6 @@ class _Rotations extends Component { { shiftStartToShowRotationForm: shiftStart, shiftEndToShowRotationForm: shiftEnd, - isNewRotation, }, () => { this.onShowRotationForm('new', layerPriority); @@ -352,7 +347,6 @@ class _Rotations extends Component { { shiftStartToShowRotationForm: undefined, shiftEndToShowRotationForm: undefined, - isNewRotation: false, }, () => { this.onShowRotationForm(undefined, undefined);