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

[WIP] 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.

Signed-off-by: Bipul Adhikari <[email protected]>
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

if (fileId in this.uploads) {
const existingData = this.uploads[fileId];
if (existingData?.abort) {
existingData?.abort?.();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
existingData?.abort?.();
existingData.abort();

is this optional check required here?

Object.values(uploadProgress).forEach((upload) => upload?.abort?.());
}, [uploadProgress]);
export const ObjectListWithSidebar: React.FC<ObjectListWithSidebarProps> =
observer(({ obj: { refresh, triggerRefresh } }) => {
Copy link
Contributor

@GowthamShanmugam GowthamShanmugam Nov 27, 2024

Choose a reason for hiding this comment

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

Why do we need an observer here, i am assuming obj has only two props refresh and triggerRefresh and both are used here and refresh is nothing but boolean only. so what exactly it is going to optimize?

failedUploads,
totalUploads,
closeAlert,
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

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 +21 to +27
configure({
enforceActions: 'always',
computedRequiresReaction: true,
reactionRequiresObservable: true,
observableRequiresReaction: true,
disableErrorBoundaries: true,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we move it to store.ts ?

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 = {};

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

Choose a reason for hiding this comment

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

https://mobx.js.org/react-integration.html#tip-grab-values-from-objects-as-late-as-possible

In the above example, the TimerView component would not react to future changes if it was defined as follows, because the .secondsPassed is not read inside the observer component, but outside, and is hence not tracked:

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should dereference abortAll during render of AbortUploadsModal IMO.

uploadStore.addFile(convertFileToUploadProgress(file, key), key);
});
setUploadStatus(UploadStatus.UPLOAD_START);
const batches = _.chunk(acceptedFiles, 8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we make it 6 instead ?? given that's the typical browser limit per domain: https://medium.com/@hnasr/chromes-6-tcp-connections-limit-c199fe550af6

Suggested change
const batches = _.chunk(acceptedFiles, 8);
const batches = _.chunk(acceptedFiles, 6);

Copy link
Collaborator

Choose a reason for hiding this comment

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

8 is also fine, but just asking...

);
const [completionTime, setCompletionTime] = React.useState<number>();
configure({
enforceActions: 'always',
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is also eslint-plugin-mobx that we can add to ensure healthy code.

@@ -1,6 +1,8 @@
import * as React from 'react';
import { DrawerHead, Status, useCustomTranslation } from '@odf/shared';
import { ResourceStatus } from '@openshift-console/dynamic-plugin-sdk';
// eslint-disable-next-line import/no-extraneous-dependencies
Copy link
Collaborator

Choose a reason for hiding this comment

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

The dependency is already added...

Suggested change
// eslint-disable-next-line import/no-extraneous-dependencies

@@ -0,0 +1,93 @@
// eslint-disable-next-line import/no-extraneous-dependencies
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
// eslint-disable-next-line import/no-extraneous-dependencies

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

Successfully merging this pull request may close these issues.

4 participants