Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
teodosii committed Jun 14, 2024
1 parent d3f4647 commit 1131300
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
8 changes: 2 additions & 6 deletions grafana-plugin/src/containers/RotationForm/RotationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down Expand Up @@ -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[] }>({});
Expand All @@ -131,7 +129,7 @@ export const RotationForm = observer((props: RotationFormProps) => {
const [draggablePosition, setDraggablePosition] = useState<{ x: number; y: number }>(undefined);

const [shiftStart, setShiftStart] = useState<dayjs.Dayjs>(
getStartShift(propsShiftStart, store.timezoneStore.selectedTimezoneOffset, isNewRotationInit)
getStartShift(propsShiftStart, store.timezoneStore.selectedTimezoneOffset, shiftId === 'new')
);

const [shiftEnd, setShiftEnd] = useState<dayjs.Dayjs>(
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 1 addition & 7 deletions grafana-plugin/src/containers/Rotations/Rotations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ interface RotationsProps extends WithStoreProps {
interface RotationsState {
shiftStartToShowRotationForm?: dayjs.Dayjs;
shiftEndToShowRotationForm?: dayjs.Dayjs;
isNewRotation?: boolean;
}

@observer
class _Rotations extends Component<RotationsProps, RotationsState> {
state: RotationsState = {
shiftStartToShowRotationForm: undefined,
shiftEndToShowRotationForm: undefined,
isNewRotation: false,
};

render() {
Expand All @@ -77,7 +75,7 @@ class _Rotations extends Component<RotationsProps, RotationsState> {
theme,
} = this.props;

const { shiftStartToShowRotationForm, shiftEndToShowRotationForm, isNewRotation } = this.state;
const { shiftStartToShowRotationForm, shiftEndToShowRotationForm } = this.state;

const { selectedTimezoneOffset } = store.timezoneStore;

Expand Down Expand Up @@ -260,7 +258,6 @@ class _Rotations extends Component<RotationsProps, RotationsState> {
</div>
{shiftIdToShowRotationForm && (
<RotationForm
isNewRotation={isNewRotation}
shiftId={shiftIdToShowRotationForm}
shiftColor={findColor(shiftIdToShowRotationForm, layers)}
scheduleId={scheduleId}
Expand Down Expand Up @@ -310,7 +307,6 @@ class _Rotations extends Component<RotationsProps, RotationsState> {
layerPriority: number,
shiftStart?: dayjs.Dayjs,
shiftEnd?: dayjs.Dayjs,
isNewRotation?: boolean
) => {
const { disabled } = this.props;

Expand All @@ -322,7 +318,6 @@ class _Rotations extends Component<RotationsProps, RotationsState> {
{
shiftStartToShowRotationForm: shiftStart,
shiftEndToShowRotationForm: shiftEnd,
isNewRotation,
},
() => {
this.onShowRotationForm('new', layerPriority);
Expand Down Expand Up @@ -352,7 +347,6 @@ class _Rotations extends Component<RotationsProps, RotationsState> {
{
shiftStartToShowRotationForm: undefined,
shiftEndToShowRotationForm: undefined,
isNewRotation: false,
},
() => {
this.onShowRotationForm(undefined, undefined);
Expand Down

0 comments on commit 1131300

Please sign in to comment.