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

Modal components refactoring #2515

Merged
merged 16 commits into from
Jul 7, 2020
Merged

Conversation

guilhermemntt
Copy link
Contributor

@guilhermemntt guilhermemntt commented Jun 5, 2020

This PR is part of the effort to update Decrediton to modern React code using hooks and functional components (#2438) and to increase modularity using specific CSS modules also (#2439). Generally, modals have no or few dynamic controls, so some of them have been moved directly to app/components/modals/ without the need for a specific subdirectory. The latest modals implemented as class components have been refactored to functional components. The style rules will be located in Modals.modules.css in the same directory. I am totally open to suggestions, especially regarding the organization of the files inner app/components/modals/.

Before:

image

After:

image

@guilhermemntt
Copy link
Contributor Author

Branch's history has been dated to make it easier to gradual review and merge. Working is still in progress on trezor modals.

@guilhermemntt guilhermemntt marked this pull request as ready for review June 7, 2020 23:24
@guilhermemntt guilhermemntt marked this pull request as draft June 8, 2020 01:06
Copy link
Member

@amass01 amass01 left a comment

Choose a reason for hiding this comment

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

@guilhermemntt Code look good, thanks.
Added some inline comments.

import Modal from "./AddAccountModalContent";
import useAddAccountModal from "./hooks";

function AddAccountModal({ onCancelModal, onSubmit, ...props }) {
Copy link
Member

@amass01 amass01 Jun 8, 2020

Choose a reason for hiding this comment

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

I would recommend using const with arrow function here and for all other modals

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

updatePrivatePassphrase,
updateConfirmPrivatePassphrase,
onTriggerPassphraseModalSubmit,
...state
Copy link
Member

Choose a reason for hiding this comment

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

Where is this statedefined?

Copy link
Member

Choose a reason for hiding this comment

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

This is repeating in all modals, is it needed? the hooks seem to return all the values, so not sure if this needed.

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 state variables are the hook states used in ***Content.jsx components and/or their children. The unused states in their children components aren't being returned from hooks.js. It can be changed if returned values from hooks are declared and passed as props explicitly as well. I'm open to suggestions here.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer declare and explicit call them, because it makes it easier to know what props a component is using. Also, with hooks there are no more states declaration, so I think it may be confunsing.

setConfirmPrivPassError(privPass !== confirmPrivPass);
}, [privPass, confirmPrivPass]);

const isValid = useCallback(() => {
Copy link
Member

Choose a reason for hiding this comment

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

use useMemo here as it returns an object and not a function, same for all hooks, some of them include variables which should be wrapped with useMemo instead of useCallback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, as the old Modals.js no longer depends on it as a function.

@guilhermemntt
Copy link
Contributor Author

Modals not yet refactored may have some layout bugs since Modals.modules.css is gradually being built , the same can happen with those shown on the GetStarted page due to Settings.less CSS rules. Modals.less will be removed after all the process.

@guilhermemntt
Copy link
Contributor Author

I'm opening this PR to merge as tests with Trezor require previous corrections due to #2539. Some points here:

  • There are some changes in Settings.less.
  • Modals.module.css has been imported in:
    • app/components/views/AccountsPage/Accounts/Page.js
    • app/components/views/SettingsPage/MiscSettings.js
    • app/components/views/TicketsPage/PurchaseTab/Tickets.js
      These CSS rules can be moved to the equivalent CSS files during their refactoring. Doing that, these imports will no longer be needed.
  • I'll open an issue regarding Trezor modals refactoring and I intend to close it after the fix in Authentication with Trezor fails when sending transaction #2539, as I already have the code, though it was not tested yet.

@guilhermemntt guilhermemntt marked this pull request as ready for review June 18, 2020 03:24
Copy link
Member

@amass01 amass01 left a comment

Choose a reason for hiding this comment

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

I noticed you import modal.module.css in many views and component which aren't really related to the modals (left inline comments but I guess there are more in other components).

Please create local css modules for all these files and move the styling away from modal.module.css, actually this is one of the main reasons why css modules exists and they are much predictable & encapsulated approach.

Will do another review cycle when done.

Edit: just saw your comment about that, let's just create a module css without fully migrating the components, just copy over the ones you already have in modal.module.css and all the rest migration work will come later.

@@ -7,11 +7,12 @@ import { ShowWarning, Subtitle } from "shared";
import "style/PurchaseTickets.less";
import { InfoDocModalButton } from "buttons";
import UnsignedTickets from "./UnsignedTickets";
import modalStyle from "../../../modals/Modals.module.css";
Copy link
Member

@amass01 amass01 Jun 18, 2020

Choose a reason for hiding this comment

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

Please create a module for TicketsPage and use it here, this import doesn't make sense here

@@ -1,6 +1,7 @@
import { FormattedMessage as T } from "react-intl";
import { SettingsInput, NumericInput } from "inputs";
import { InfoDocFieldModalButton } from "buttons";
import modalStyle from "../../modals/Modals.module.css";
Copy link
Member

Choose a reason for hiding this comment

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

same here, but as i'm already refactoring this part please leave a TODO and I could handle it later

@guilhermemntt
Copy link
Contributor Author

I've implemented the changes. It seems to be ok now.

Copy link
Member

@vctt94 vctt94 left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! Good job on it. I have some small nits, but looks really good overall.

Looks like there are some modals which are not properly working.

  • Ticket auto buyer
  • VSP remove confirmation

Keep in mind in decrediton we have a right alignment design #1940, Keep that on our modals. I noticed some of them are with the button aligned at the left. Also the import redeem script modal is a bit off alignment as well:

image

Also I think we could have a copy to clipboard button at the confirm redeem script modal, but not really related to this PR:

image

The copy seed modal looks too wide:
image

Here is its spec: #2223

updatePrivatePassphrase,
updateConfirmPrivatePassphrase,
onTriggerPassphraseModalSubmit,
...state
Copy link
Member

Choose a reason for hiding this comment

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

I prefer declare and explicit call them, because it makes it easier to know what props a component is using. Also, with hooks there are no more states declaration, so I think it may be confunsing.

@guilhermemntt
Copy link
Contributor Author

@vctt94, I've created a remove VSP confirmation modal:

image

and opened the issue #2547.

To keep the standard, some lines have been added in DecredConstitution.md and ScriptNotRedeemable.md files by adding modal titles to these files. For now, these changes can produce some visual inconsistencies when using other translations.

In general, other GUI changes have been implemented in Info modals, according to #1940.
The example below shows the result of what have been done:

image

/>{" "}
<a
onClick={() =>
shell.openExternal("https://decred.org/contributors/")
Copy link
Member

Choose a reason for hiding this comment

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

Given this wasn't a pure file move, I think you should go ahead and replace these inline links for the ExternalLink component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced.

)}
</div>
<div className={style.aboutBottomAreaMiddle}>
Copyright &copy; 2019{" "}
Copy link
Member

Choose a reason for hiding this comment

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

2020

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Add useAboutModal custom hook
Copy link
Member

@vctt94 vctt94 left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

@alexlyp alexlyp merged commit 25191eb into decred:master Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants