-
Notifications
You must be signed in to change notification settings - Fork 305
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
Conversation
b77d9e2
to
5a8960d
Compare
5a8960d
to
1bbf408
Compare
1bbf408
to
97c1867
Compare
dispatchEvent: jest.fn(), | ||
})), | ||
}); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', | ||
}, |
There was a problem hiding this comment.
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"
).
box-ui-elements/src/common/types/core.js
Line 86 in f6abd4e
type ItemType = typeof ITEM_TYPE_FOLDER | typeof ITEM_TYPE_FILE | typeof ITEM_TYPE_HUBS | typeof ITEM_TYPE_WEBLINK; |
box-ui-elements/src/common/constants.js
Lines 2 to 5 in f6abd4e
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'; |
There was a problem hiding this comment.
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(), | ||
})), | ||
}); | ||
|
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" /> |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/elements/common/messages.js
Outdated
@@ -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: { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
- name message id like above and wrote
<FormattedMessage {...messages[
${itemType}RenameHeading]} />
- name message id like
renameDialogFileHeading
and wrote<FormattedMessage {...(type === 'file' ? messages.renameDialogFileHeading : messages.renameDialogFolderHeading)} />
- 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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure! sounds good!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/elements/common/messages.js
Outdated
description: 'Header for rename web link dialog', | ||
defaultMessage: 'Rename Link', | ||
}, | ||
fileRenameHeading: { |
There was a problem hiding this comment.
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
36c5586
to
2fdf109
Compare
This reverts commit f5f1bac.
Replaced Modal Component by Blueprint Modal
Basic Example
Before
After
Error Example
Before
After