Skip to content

Commit

Permalink
Fix/scheduled request UI (#5318)
Browse files Browse the repository at this point in the history
Change timezone format
Fixes a bug where the Edit button on hover being elongated

Before:
<img width="755" alt="Screenshot 2023-11-09 at 21 36 01"
src="https://github.com/Unleash/unleash/assets/104830839/189f21d5-8a68-4d6b-b094-b518749a9b2f">

After:
<img width="812" alt="Screenshot 2023-11-09 at 22 09 26"
src="https://github.com/Unleash/unleash/assets/104830839/9056f995-bd2b-4353-8526-77160e49e990">

Adds the missed onClick to the edit button to show the dialog

Fixes a bug with ScheduleChangesDialog onClose

---------

Signed-off-by: andreas-unleash <[email protected]>
  • Loading branch information
andreas-unleash authored Nov 10, 2023
1 parent 0b9e116 commit 180c0dc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const ChangeRequestOverview: FC = () => {
const onCancelAbort = () => setShowCancelDialog(false);
const onCancelReject = () => setShowRejectDialog(false);
const onApplyScheduledAbort = () => setShowApplyScheduledDialog(false);
const onScheduleChangeAbort = () => setShowApplyScheduledDialog(false);
const onScheduleChangeAbort = () => setShowScheduleChangeDialog(false);
const onRejectScheduledAbort = () => setShowRejectScheduledDialog(false);

const isSelfReview =
Expand Down Expand Up @@ -286,6 +286,9 @@ export const ChangeRequestOverview: FC = () => {
/>
<ChangeRequestReviewStatus
changeRequest={changeRequest}
onEditClick={() =>
setShowScheduleChangeDialog(true)
}
/>
<StyledButtonBox>
<ConditionallyRender
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React, { FC } from 'react';
import { Box, IconButton, Theme, Typography, useTheme } from '@mui/material';
import {
Box,
IconButton,
styled,
Theme,
Typography,
useTheme,
} from '@mui/material';
import { ReactComponent as ChangesAppliedIcon } from 'assets/icons/merge.svg';
import {
StyledOuterContainer,
Expand All @@ -19,10 +26,11 @@ import {
ChangeRequestState,
IChangeRequest,
} from 'component/changeRequest/changeRequest.types';
import { getBrowserTimezoneInHumanReadableUTCOffset } from './utils';
import { getBrowserTimezone } from './utils';

interface ISuggestChangeReviewsStatusProps {
changeRequest: IChangeRequest;
onEditClick?: () => void;
}
const resolveBorder = (state: ChangeRequestState, theme: Theme) => {
if (state === 'Approved' || state === 'Scheduled') {
Expand Down Expand Up @@ -58,7 +66,7 @@ const resolveIconColors = (state: ChangeRequestState, theme: Theme) => {
};

export const ChangeRequestReviewStatus: FC<ISuggestChangeReviewsStatusProps> =
({ changeRequest }) => {
({ changeRequest, onEditClick }) => {
const theme = useTheme();
return (
<StyledOuterContainer>
Expand All @@ -80,17 +88,24 @@ export const ChangeRequestReviewStatus: FC<ISuggestChangeReviewsStatusProps> =
}}
border={resolveBorder(changeRequest.state, theme)}
>
<ResolveComponent changeRequest={changeRequest} />
<ResolveComponent
changeRequest={changeRequest}
onEditClick={onEditClick}
/>
</StyledReviewStatusContainer>
</StyledOuterContainer>
);
};

interface IResolveComponentProps {
changeRequest: IChangeRequest;
onEditClick?: () => void;
}

const ResolveComponent = ({ changeRequest }: IResolveComponentProps) => {
const ResolveComponent = ({
changeRequest,
onEditClick,
}: IResolveComponentProps) => {
const { state } = changeRequest;

if (!state) {
Expand All @@ -115,7 +130,10 @@ const ResolveComponent = ({ changeRequest }: IResolveComponentProps) => {

if (state === 'Scheduled') {
return (
<Scheduled scheduledDate={changeRequest.schedule?.scheduledAt} />
<Scheduled
scheduledDate={changeRequest.schedule?.scheduledAt}
onEditClick={onEditClick}
/>
);
}

Expand Down Expand Up @@ -204,17 +222,23 @@ const Applied = () => {
);
};

const StyledIconButton = styled(IconButton)({
maxWidth: '32px',
maxHeight: '32px',
});

interface IScheduledProps {
scheduledDate?: string;
onEditClick?: () => any;
}
const Scheduled = ({ scheduledDate }: IScheduledProps) => {
const Scheduled = ({ scheduledDate, onEditClick }: IScheduledProps) => {
const theme = useTheme();

if (!scheduledDate) {
return null;
}

const timezone = getBrowserTimezoneInHumanReadableUTCOffset();
const timezone = getBrowserTimezone();

return (
<>
Expand Down Expand Up @@ -243,9 +267,9 @@ const Scheduled = ({ scheduledDate }: IScheduledProps) => {
<Typography>Your timezone is {timezone}</Typography>
</Box>
</StyledFlexAlignCenterBox>
<IconButton>
<StyledIconButton onClick={onEditClick}>
<StyledEditIcon />
</IconButton>
</StyledIconButton>
</StyledScheduledBox>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export const getBrowserTimezoneInHumanReadableUTCOffset = (

return `UTC${sign}${zeroPaddedHours}:${zeroPaddedMinutes}`;
};

export const getBrowserTimezone = (): string => {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { APPLY_CHANGE_REQUEST } from 'component/providers/AccessProvider/permissions';
import PermissionButton from 'component/common/PermissionButton/PermissionButton';
import { DateTimePicker } from 'component/common/DateTimePicker/DateTimePicker';
import { getBrowserTimezoneInHumanReadableUTCOffset } from '../ChangeRequestReviewStatus/utils';
import { getBrowserTimezone } from '../ChangeRequestReviewStatus/utils';

export interface ScheduleChangeRequestDialogProps {
title: string;
Expand Down Expand Up @@ -42,15 +42,15 @@ export const ScheduleChangeRequestDialog: FC<ScheduleChangeRequestDialogProps> =
);
const [error, setError] = useState<string | undefined>(undefined);

const timezone = getBrowserTimezoneInHumanReadableUTCOffset();
const timezone = getBrowserTimezone();

return (
<Dialogue
title={title}
primaryButtonText={primaryButtonText}
secondaryButtonText='Cancel'
open={open}
onClose={onClose}
onClose={() => onClose()}
onClick={() => onConfirm(selectedDate)}
permissionButton={
<PermissionButton
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export const CHANGE_REQUEST_CANCELLED = 'change-request-cancelled' as const;
export const CHANGE_REQUEST_SENT_TO_REVIEW =
'change-request-sent-to-review' as const;
export const CHANGE_REQUEST_APPLIED = 'change-request-applied' as const;
export const SCHEDULED_CHANGE_REQUEST_APPLIED =
'scheduled-change-request-applied' as const;
export const CHANGE_REQUEST_SCHEDULED = 'change-request-scheduled' as const;

export const API_TOKEN_CREATED = 'api-token-created' as const;
Expand Down Expand Up @@ -248,6 +250,7 @@ export const IEventTypes = [
CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_APPLIED,
SCHEDULED_CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_SCHEDULED,
API_TOKEN_CREATED,
API_TOKEN_UPDATED,
Expand Down

0 comments on commit 180c0dc

Please sign in to comment.