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

Code Quality: Improved UserControls codebase #13492

Closed

Conversation

0x5bfa
Copy link
Member

@0x5bfa 0x5bfa commented Oct 9, 2023

Summary

This namespace was one of the places where there were leftovers from UWP.

Re-organized codebase in UserControls to enhance maintainability and removed some XAML files(OpacityIcon and DataGridHeader), so it must be little but the app should be faster a bit.

Task Checklist

  • Rename IAddressToolBar to IAddressToolbarViewModel
  • Rename ISearchBox to ISearchBoxViewModel
  • Rename ISearchBox to ISearchBoxViewModel
  • Rename Views.LayoutModes to Views.ContentLayouts
  • Rename ViewModels.LayoutModes to ViewModels.ContentLayouts
  • Move IAddressToolbarViewModel from UserControls to ViewModels.UserControls
  • Move ISearchBoxViewModel from UserControls to ViewModels.UserControls
  • Move ViewModels.Previews to ViewModel.UserControls.Previews
  • Move ViewModels.Widgets to ViewModel.UserControls.Widgets
  • Change base class of DataGridHeader from UserControl to ButtonBase
  • Ensure we folllow our codebase guideline
  • Clean up
  • Apply requested changes

Known Issues

Following issues would be fixed in the upcoming PR.

N/A

PR Checklist

Steps To Validate Changes

There're some classes that were changed codebase largely. Please have look at:

  • See that DataGridHeader is working well
  • See that OpacityIcon is working well

Screenshots

N/A

Footnotes

  1. If the request hasn't been agreed by the team, this work might be rejected. Make sure that you get approval from the team before opening any PR related the request.

  2. If you removed any en-US string resources, make sure that there are no references of those resources. When you add a new en-US string resources, do not make any changes on other languages' resources; Crowdin will do, instead.

@0x5bfa 0x5bfa changed the title Code Quality: Clean up UserControls Code Quality: Improved UserControls codebase Oct 16, 2023
@0x5bfa
Copy link
Member Author

0x5bfa commented Oct 16, 2023

This is ready for review.

Copy link
Contributor

@QuaintMako QuaintMako left a comment

Choose a reason for hiding this comment

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

Small feedback, I cannot test it.
LGTM overall.

Comment on lines +160 to +163
//protected override AutomationPeer OnCreateAutomationPeer()
//{
// return new DataGridHeaderAutomationPeer(this);
//}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

To remind devs that this control should have AutomationPeer. I will add a TODO.

Comment on lines 193 to 199
{
return FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement;
}
else
{
return FocusManager.GetFocusedElement() as FrameworkElement;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be turned into a ternary return.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

InitializeComponent();
PreviewPaneViewModel = Ioc.Default.GetRequiredService<PreviewPaneViewModel>();
}
private readonly IAddItemService _addItemService = Ioc.Default.GetRequiredService<IAddItemService>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be named AddItemService.

Copy link
Member Author

Choose a reason for hiding this comment

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

How come?

Runtime Code Style Conventions Itme 3:

We use _camelCase for internal and private fields and use readonly where possible.

Our Code Stlye Guideline Section 2, Item 4:

Use camelCase prefixed with _ for private fields

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, the two services below are not named properly.

Copy link
Member Author

@0x5bfa 0x5bfa Oct 16, 2023

Choose a reason for hiding this comment

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

But as my policy ones that are referenced from XAML should be named with PascalCase; Commands & ModifiableCommands because when accessing in XAML, the code will be like as follows if CommandManager is defines in code-behind.

<Button Command="Commands.OpenInNewTab" />
not
<Button Command="_commands.OpenInNewTab" /> <!--  This looks odd  -->

Is that not bad practice? I wanna hear from you.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is something off with the second format indeed, it looks really off. Yet at the same time, if we're making an exception to our coding rules, than I believe the coding rules are not good enough.

On a first read, one can be confused as to why some private fields are marked with an underscore and why others are not.

Maybe we can mark the fields used in xmal with a letter (bad idea in my opinion). Maybe we can add a rule in the coding rules about having them capitalized as a way to mark their use in XMAL (will work for a while, but give it a year or two and the whole thing gonna be a real mess).

I need to think about it a little bit to see if anything clever can be made. Maybe we can find some inputs online for good practice.

Either way, that is something minor here. We can open an issue about that to keep track of it.

Tagging @d2dyno1 since I believe he wrote the coding rules, he might have some good input about it?

Copy link
Member

Choose a reason for hiding this comment

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

Why not just use a private property in this case?

@yaira2
Copy link
Member

yaira2 commented Oct 22, 2023

I'm not so sure about renaming LayoutModes to ContentLayouts, can you clarify where this is coming from?

@yaira2
Copy link
Member

yaira2 commented Oct 22, 2023

Which steps were used to verify this changes?

<ResourceDictionary Source="ms-appx:///ResourceDictionaries/App.Theme.TextBlockStyles.xaml" />
<ResourceDictionary Source="ms-appx:///ResourceDictionaries/PathIcons.xaml" />
<ResourceDictionary Source="ms-appx:///UserControls/SideBar/SideBarControls.xaml" />
<ResourceDictionary Source="ms-appx:///ResourceDictionaries/TextBlockStyles.xaml" />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ResourceDictionary Source="ms-appx:///ResourceDictionaries/TextBlockStyles.xaml" />
<ResourceDictionary Source="ms-appx:///ResourceDictionaries/App.Theme.TextBlockStyles.xaml" />

The . makes the code more readable.

Copy link
Member

Choose a reason for hiding this comment

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

Can you revert this change?

@@ -149,7 +150,7 @@
</Setter>
</Style>

<Style TargetType="uc:DataGridHeader">
<Style BasedOn="{StaticResource DefaultDataGridHeaderStyle}" TargetType="uc:DataGridHeader">
Copy link
Member

Choose a reason for hiding this comment

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

It might be better to do this in a separate PR so we can review the change on it's own.

@0x5bfa 0x5bfa closed this Oct 26, 2023
@0x5bfa 0x5bfa deleted the 5bfa/Enable-StoragePropsSecurityEdit branch October 31, 2023 04:02
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