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

Moves upload component to mobX #1732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bipuladh
Copy link
Contributor

No description provided.

Copy link
Contributor

openshift-ci bot commented Nov 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bipuladh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

const { t } = useCustomTranslation();
const [isModalOpen, setModalOpen] = React.useState(false);
export const AbortUploadsModal: React.FC<AbortUploadsModalProps> = observer(
({ abortAll }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +78 to +81
// eslint-disable-next-line guard-for-in
for (const key in this.uploads) {
delete this.uploads[key];
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if ??

Suggested change
// eslint-disable-next-line guard-for-in
for (const key in this.uploads) {
delete this.uploads[key];
}
this.uploads = {};

Copy link
Collaborator

Choose a reason for hiding this comment

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

missed this comment @bipuladh.

@bipuladh bipuladh force-pushed the mobx-switch branch 2 times, most recently from fb4e862 to 749f591 Compare December 3, 2024 08:32
@bipuladh bipuladh changed the title [WIP] Moves upload component to mobX Moves upload component to mobX Dec 3, 2024
Signed-off-by: Bipul Adhikari <badhikar@redhat.com>
showSidebar={showUploadSidebar}
abortAll={abortAll}
hideSidebar={hideUploadSidebar}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can't we simply use closeUploadSidebar ??

Suggested change
hideSidebar={hideUploadSidebar}
hideSidebar={closeUploadSidebar}

</Drawer>
);
};
export const UploadSidebar: React.FC<UploadSidebarProps> = observer(
Copy link
Collaborator

Choose a reason for hiding this comment

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

is observer needed here ?? I don't see store being used ??

Comment on lines +78 to +81
// eslint-disable-next-line guard-for-in
for (const key in this.uploads) {
delete this.uploads[key];
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

missed this comment @bipuladh.

Comment on lines +11 to +21
setAborter(key: string, aborter: UploadProgress['abort']) {
this.uploads[key]['abort'] = aborter;
}

// Add a file to the map
addFile(file: UploadProgress, key: string) {
this.uploads[key] = {
...file,
uploadState: UploadStatus.INIT_STATE,
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

just a question @bipuladh, why are we not using set keyword here with these functions ?? these also update observable state, so don't we need set keyword here too ?? what's is the criteria of using set ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

set keyword is essentially a JS class concept and it doesn't support multiple parameters.

foldersPath,
uploadStore
);
setCompletionTime(completionTime);
Copy link
Collaborator

Choose a reason for hiding this comment

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

earlier we were calling processFiles once, but now we are doing so in batches, so setCompletionTime(completionTime) will be called multiple times...

Copy link
Collaborator

Choose a reason for hiding this comment

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

ideally it should only be called once after all batches are complete...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The value is used only when the total upload is completed but I can remove it from the loop. Thanks.

loaded: 0,
uploadState: UploadStatus.INIT_STATE,
abort: null,
name: file.name,
filePath: file.webkitRelativePath,
startTime: undefined,
lastModified: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

lastModified is not used anywhere, right ??


const getProgressVariant = (
state: UploadStatus,
// For cases whjen it's complete but user presses cancel(edge case)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// For cases whjen it's complete but user presses cancel(edge case)
// For cases when it's complete but user presses cancel(edge case)

isComplete: boolean
): Progress['props']['variant'] => {
if (isComplete) {
return undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

if upload is complete shouldn't we show success ??

Suggested change
return undefined;
return ProgressVariant.success;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. Thanks!

const existingData = this.uploads[fileId];

const update =
existingData.uploadState === UploadStatus.UPLOAD_COMPLETE
Copy link
Collaborator

Choose a reason for hiding this comment

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

??

Suggested change
existingData.uploadState === UploadStatus.UPLOAD_COMPLETE
existingData.uploadState !== UploadStatus.UPLOAD_COMPLETE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants