Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Likhith/76893/ts migrate linear progress label #38

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './linear-progress.scss';
import LinearProgressContainer from './linear-progress-container.jsx';
import LinearProgressContainer from './linear-progress-container';

export default LinearProgressContainer;
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import React from 'react';
import PropTypes from 'prop-types';
import { LinearProgress } from './linear-progress.jsx';
import { LinearProgress } from './linear-progress';

type TLinearProgressContainer = {
timeout: number;
action: () => void;
render: (prop: number) => number;
className?: string;
should_store_in_session?: boolean;
session_id: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just check whether all these props are required. Rest is LGTM

};

const LinearProgressContainer = React.forwardRef(
({ timeout, action, render, className, should_store_in_session, session_id }, ref) => {
const current_progress_timeout = sessionStorage.getItem(`linear_progress_timeout_${session_id}`);
({ timeout, action, render, className, should_store_in_session, session_id }: TLinearProgressContainer, ref) => {
const current_progress_timeout = Number(sessionStorage.getItem(`linear_progress_timeout_${session_id}`));

const popup_timeout = !current_progress_timeout ? timeout / 1000 : current_progress_timeout;
const popup_timeout = !current_progress_timeout ? timeout / 1000 : Number(current_progress_timeout);
const [timeout_state, setTimeoutState] = React.useState(popup_timeout);
const time_past = 100 - (timeout_state / (timeout / 1000)) * 100;

Expand All @@ -26,7 +34,7 @@ const LinearProgressContainer = React.forwardRef(

React.useEffect(() => {
if (should_store_in_session) {
sessionStorage.setItem(`linear_progress_timeout_${session_id}`, timeout_state);
sessionStorage.setItem(`linear_progress_timeout_${session_id}`, String(timeout_state));
}
}, [timeout_state, should_store_in_session, session_id]);

Expand All @@ -46,7 +54,7 @@ const LinearProgressContainer = React.forwardRef(
if (current_progress_timeout <= 0) {
sessionStorage.removeItem(`linear_progress_timeout_${session_id}`);
} else if (current_progress_timeout > 0) {
sessionStorage.setItem(`linear_progress_timeout_${session_id}`, timeout_state);
sessionStorage.setItem(`linear_progress_timeout_${session_id}`, String(timeout_state));
} else {
return null;
}
Expand All @@ -62,15 +70,6 @@ const LinearProgressContainer = React.forwardRef(
}
);

LinearProgressContainer.propTypes = {
timeout: PropTypes.number,
action: PropTypes.func,
render: PropTypes.func.isRequired,
className: PropTypes.string,
should_store_in_session: PropTypes.bool,
session_id: PropTypes.string,
};

LinearProgressContainer.displayName = 'LinearProgressContainer';

export default LinearProgressContainer;
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import classNames from 'classnames';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not adding any dynamic classnames here.is this import required?

import React from 'react';

export const LinearProgress = ({ progress }) => (
type TLinearProgress = {
progress: number;
className: string;
height: number;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need className and height in this component? I couldn't find using them in the component.


export const LinearProgress = ({ progress }: Partial<TLinearProgress>) => (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems only progress param is used in the component. If so, can we remove this Partial typing?

<div className={classNames('dc-linear-progress')}>
<div className={classNames('dc-linear-progress__bar')} style={{ width: `${progress}%` }} />
Copy link

@amina-deriv amina-deriv Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this classNames required? <div className='dc-linear-progress__bar' style={{ width: ${progress}% }} />

</div>
Expand Down