question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

toPlatformCase component helper

See original GitHub issue

toPlatformCase

In #5744 we added toPlatformCase, a helper function to change this pattern:

https://github.com/desktop/desktop/blob/3feeaac7ba184aacdeb21aadc85587b29e3f36f6/app/src/ui/merge-conflicts/merge-conflicts-warning.tsx#L31

to this:

https://github.com/desktop/desktop/blob/3feeaac7ba184aacdeb21aadc85587b29e3f36f6/app/src/ui/discard-changes/discard-changes-dialog.tsx#L69

The idea is that toPlatformCase will case the string properly depending on the current platform. macOS is title case and windows is sentence case generally.

The original pattern appears in about 85 places in Desktop’s React components, according to a quick search of the codebase. (Currently toPlatformCase is only used in one component.)

Limitations

There are limitations to this approach because there are a number of edge cases that extend beyond simply title casing or sentence casing a string.

  1. Prepositions (https://github.com/desktop/desktop/pull/5841#pullrequestreview-162478757), which are lower case, even in title case.
  2. Platform-specific terminology (#2103), like trash or recycling bin
  3. Key shortcuts (#2103), which differ on platforms

The Question

Options:

  • keep toPlatformCase and spread in the codebase (where applicable)
  • remove toPlatformCase and continue using string literals in our components
  • refactor toPlatformCase to cover more edge cases
  • something else?

cc @Daniel-McCarthy @j-f1 @say25 @iAmWillShepherd

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
j-f1commented, Oct 8, 2018

IMO all the text should be written in sentence case and we should use something like title to convert the text to title case on macOS.

2reactions
j-f1commented, Oct 8, 2018

Yep @say25! We could even define toPlatformCase as:

export const toPlatformCase = __DARWIN__ ? title : (s: string) => s
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sharing JavaScript Code in a Component Bundle
A helper function can be called from any JavaScript code in a component's bundle, such as from a client-side controller or renderer. Helper...
Read more >
{{component helper}} - DockYard
A helpful helper that became available pre-Ember 2.0 is the {{component}} . With its help, we can clean up our template logic.
Read more >
components-helper - npm
Start using components-helper in your project by running `npm i components-helper`. There is 1 other project in the npm registry using ...
Read more >
In a helper function, is there a way to reference the component ...
controller.js ({ doSth: function(component, event, helper) { helper.helperFunction(component, event, helper); } }). helper.js
Read more >
Understand helper components - Oracle Help Center
Widgets can reference helper components exposed by the application, such as those provided in the /react-components directory, or custom components that are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found