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

chore(content-explorer): migrate renameDialog #3666

Merged
merged 5 commits into from
Sep 25, 2024

Conversation

tjiang-box
Copy link
Contributor

@tjiang-box tjiang-box commented Sep 18, 2024

Replaced Modal Component by Blueprint Modal

Basic Example

Before
Screenshot 2024-09-18 at 4 04 12 PM

After
Screenshot 2024-09-23 at 3 45 12 PM

Error Example

Before
Screenshot 2024-09-18 at 4 07 09 PM

After
Screenshot 2024-09-23 at 3 45 46 PM

@tjiang-box tjiang-box requested a review from a team as a code owner September 18, 2024 20:51
@tjiang-box tjiang-box force-pushed the migrate_rename_dialog branch 2 times, most recently from b77d9e2 to 5a8960d Compare September 18, 2024 21:11
dispatchEvent: jest.fn(),
})),
});

Copy link
Contributor Author

@tjiang-box tjiang-box Sep 23, 2024

Choose a reason for hiding this comment

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

resolve issue TypeError: window.matchMedia is not a function when running tests
https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom

Copy link
Contributor

Choose a reason for hiding this comment

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

if i recall this occurs when using fireEvent, can you try using userEvent for tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think he has to use fireEvent.change, I didnt see a way around it when I was doing something similar in the other PR, for everything else he could probably swap out with userEvent

Copy link
Contributor Author

@tjiang-box tjiang-box Sep 24, 2024

Choose a reason for hiding this comment

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

I swap out all fireEvent with userEvents now but still face this error. The matchMedia function might be wrapped internally somewhere.

@greg-in-a-box for fireEvent.change(), we could use userEvent.clear(textInput) + userEvent.type(textInput, 'xxx') to replace.

id: 'be.webLinkRenameHeading',
description: 'Heading for rename web link dialog',
defaultMessage: 'Rename Web Link',
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are 4 types of BoxItem in total ("folder", "file", "hubs", "web_link").

type ItemType = typeof ITEM_TYPE_FOLDER | typeof ITEM_TYPE_FILE | typeof ITEM_TYPE_HUBS | typeof ITEM_TYPE_WEBLINK;

const ITEM_TYPE_FILE: 'file' = 'file';
const ITEM_TYPE_FOLDER: 'folder' = 'folder';
const ITEM_TYPE_HUBS: 'hubs' = 'hubs';
const ITEM_TYPE_WEBLINK: 'web_link' = 'web_link';

Copy link
Contributor

Choose a reason for hiding this comment

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

are all these flows possible within ContentExplorer? could you check the behavior of this vs EUA?

dispatchEvent: jest.fn(),
})),
});

Copy link
Contributor

Choose a reason for hiding this comment

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

if i recall this occurs when using fireEvent, can you try using userEvent for tests?

@@ -0,0 +1,5 @@
@import '../common/variables';
Copy link
Contributor

Choose a reason for hiding this comment

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

this import isn't used

parentElement: HTMLElement;
}

/* eslint-disable jsx-a11y/label-has-for */
Copy link
Contributor

Choose a reason for hiding this comment

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

is this still needed? if so, could you use next-line instead of disabling the entire component

Copy link
Contributor Author

@tjiang-box tjiang-box Sep 24, 2024

Choose a reason for hiding this comment

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

good catch! it is not needed since <label> and <input> are replaced by <TextInput>.

{formatMessage(messages.rename)}
</Modal.Footer.PrimaryButton>
</Modal.Footer>
<Modal.Close aria-label="Close" />
Copy link
Contributor

Choose a reason for hiding this comment

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

this should use formatMessage

@import '../common/variables';

.be-modal-rename {
width: 400px;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed if the size prop is used in Modal.Content?

Copy link
Contributor Author

@tjiang-box tjiang-box Sep 24, 2024

Choose a reason for hiding this comment

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

I checked the max-width for small size is 460px which seems close to what we have before (400 px). I think it is better to remove this style file and set the size to small instead of overriding the width. wdyt @tjuanitas

Copy link
Contributor

Choose a reason for hiding this comment

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

can renameDialogText be removed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good question! renameDialogText is still used inside of the renameDialog.js.flow file, so simply removing this message will cause flow check error. I believe those .flow file will be removed eventually after we finish migration? If so, should I leave it here since I believe we will also remove things used in this file such as messages or styles when we do it.

@@ -317,6 +317,26 @@ const messages = defineMessages({
description: 'Error text for rename dialog when name is too long',
defaultMessage: 'This name is too long.',
},
fileRenameHeading: {
Copy link
Contributor

Choose a reason for hiding this comment

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

to keep with the pattern of the other ids, maybe renameDialogFileHeader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is my initial thought. however the itemType are all set as all lowercase such as file and folder. I was think about two approaches

  1. name message id like above and wrote <FormattedMessage {...messages[${itemType}RenameHeading]} />
  2. name message id like renameDialogFileHeading and wrote <FormattedMessage {...(type === 'file' ? messages.renameDialogFileHeading : messages.renameDialogFolderHeading)} />
  3. update first letter in type to upperCase

I didn't like the second approach because it doesn't give good clarity and readability. Also it lacks extensibility if we want to support more itemTypes in contentExplorer. Nor third approach either because I feel like it is extra implantation just for making messages id aligned. Let me know what you think or any suggestions. @tjuanitas

Copy link
Contributor

Choose a reason for hiding this comment

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

it's probably just more readable and cleaner to use a switch statement or a map:

const headerMessages = {
    [ITEM_TYPE_FILE]: ...,
    [ITEM_TYPE_FOLDER]: ...,
    [ITEM_TYPE_WEBLINK]: ...,
};

<Modal.Header>
  {formatMessage(headerMessages[type])}
</Modal.Header>

or

let header;

switch (type) {
  case "file":
    header = ...
    break;
  case "folder":
    header = ...
    break;
  case "web_link":
    header = ...
    break;
  default:
    break;
}

<Modal onOpenChange={onCancel} open={isOpen}>
<Modal.Content
aria-label={formatMessage(messages.renameDialogLabel)}
className="be-modal-rename"
Copy link
Contributor

Choose a reason for hiding this comment

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

probably use suit naming: bce-RenameDialog
bce = box-content-explorer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed this classname since we gonna use size="small"

import RenameDialog from '../RenameDialog';

// need to import this into the story because it's usually in ContentExplorer
import '../../common/modal.scss';
Copy link
Contributor

Choose a reason for hiding this comment

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

do we still need this since we are using blueprint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, ill remove it

import * as React from 'react';
import { useArgs } from '@storybook/preview-api';

import PrimaryButton from '../../../components/primary-button/PrimaryButton';
Copy link
Contributor

Choose a reason for hiding this comment

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

can we replace this with a blueprint button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure! sounds good!

Copy link
Contributor

Choose a reason for hiding this comment

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

can this be a ts/tsx file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this can be changed to tsx file. if we want to do this, we should update the stories in contentUploader as well.

description: 'Header for rename web link dialog',
defaultMessage: 'Rename Link',
},
fileRenameHeading: {
Copy link
Contributor

Choose a reason for hiding this comment

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

this id's are no longer needed anymore since we have the ones above

tjuanitas
tjuanitas previously approved these changes Sep 25, 2024
@greg-in-a-box greg-in-a-box merged commit f5f1bac into box:master Sep 25, 2024
4 checks passed
tjiang-box added a commit to tjiang-box/box-ui-elements that referenced this pull request Oct 8, 2024
greg-in-a-box pushed a commit that referenced this pull request Oct 8, 2024
* Revert "chore(content-explorer): migrate renameDialog (#3666)"

This reverts commit f5f1bac.

* chore(content-explorer): keep changes depended by other elements
greg-in-a-box pushed a commit to DanilaRubleuski/box-ui-elements that referenced this pull request Oct 9, 2024
* Revert "chore(content-explorer): migrate renameDialog (box#3666)"

This reverts commit f5f1bac.

* chore(content-explorer): keep changes depended by other elements
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.

3 participants