Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions src/elements/content-uploader/ContentUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface ContentUploaderProps {
isExpanded?: boolean;
onToggle?: (isExpanded: boolean) => void;
maxFileSize?: number;
modernizedDismissDelayMs?: number;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: it would be nice if these new props were added alphabetically into the existing list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: a better long term name would be to remove the "modernized" prefix. that way you don't need to change the name in the future once the modernized feature becomes the default behavior

}

type ModernizedPanelState = 'hidden' | 'shown' | 'dismissing';
Expand Down Expand Up @@ -203,6 +204,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
useUploadsManager: false,
enableModernizedUploads: false,
isUpgradeModalEnabled: false,
modernizedDismissDelayMs: HIDE_MODERNIZED_UPLOAD_MANAGER_DELAY_MS,
};

/**
Expand Down Expand Up @@ -893,7 +895,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
upload = () => {
const { enableModernizedUploads, isUpgradeModalEnabled, maxFileSize } = this.props;

if (this.isCancelAllPaused) {
if (this.isCancelAllPaused) {
return;
}

Expand Down Expand Up @@ -1637,6 +1639,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
startModernizedDismissTimer = (): void => {
this.clearModernizedDismissTimer();

const { modernizedDismissDelayMs } = this.props;
const { modernizedPanelState, items } = this.state;
const isUploadsBatchSuccessfullyComplete = items.every(
item => item.status === STATUS_COMPLETE || item.status === STATUS_CANCELED,
Expand All @@ -1654,7 +1657,7 @@ class ContentUploader extends Component<ContentUploaderProps, State> {
this.modernizedDismissTimer = setTimeout(() => {
this.setState({ modernizedPanelState: 'dismissing' });
this.modernizedDismissTimer = null;
}, HIDE_MODERNIZED_UPLOAD_MANAGER_DELAY_MS);
}, modernizedDismissDelayMs);
};

finalizeModernizedDismiss = (): void => {
Expand Down
16 changes: 16 additions & 0 deletions src/elements/content-uploader/__tests__/ContentUploader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,22 @@ describe('elements/content-uploader/ContentUploader', () => {
expect(wrapper.state('modernizedPanelState')).toBe('dismissing');
});

test('honors a custom modernizedDismissDelayMs', () => {
const CUSTOM_DELAY_MS = 3000;
const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
const wrapper = getWrapper({ enableModernizedUploads: true, modernizedDismissDelayMs: CUSTOM_DELAY_MS });
armDismissTimer(wrapper);

expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), CUSTOM_DELAY_MS);

jest.advanceTimersByTime(CUSTOM_DELAY_MS - 1);
expect(wrapper.state('modernizedPanelState')).toBe('shown');

jest.advanceTimersByTime(1);
expect(wrapper.state('modernizedPanelState')).toBe('dismissing');
setTimeoutSpy.mockRestore();
});

test('clears timer when a new in-progress item is added mid-wait', () => {
const wrapper = getWrapper({ enableModernizedUploads: true });
const instance = armDismissTimer(wrapper);
Expand Down
Loading