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

Improving experience with format and parse. #9045

Merged
merged 7 commits into from
Feb 14, 2024
Merged

Conversation

jdunkerley
Copy link
Member

@jdunkerley jdunkerley commented Feb 13, 2024

Pull Request Description

  • Add format dropdown to Number.format.
    image

  • Support case insensitive month names and abbreviations in dates.
    https://github.com/enso-org/enso/assets/4699705/4dbd8755-e1c2-4207-a8a1-65b427ca4fab

  • Improve locale dropdown for parse_date and parse_date_time.
    image

  • Added dropdown to Table.parse and amended so now doesn't accept Nothing (using empty string instead).
    image

  • Added dropdown to Table.format and amended so now doesn't accept Nothing (using empty string instead).

  • Altered Column.parse to not accept Nothing and added drop down for format.

  • Altered Column.format to not accept Nothing and added drop down for format conditional on type.

  • Improved the locale date/time format drop to have the suggested formats too.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@jdunkerley jdunkerley marked this pull request as ready for review February 14, 2024 10:01
@jdunkerley jdunkerley added the CI: No changelog needed Do not require a changelog entry for this PR. label Feb 14, 2024
@@ -124,7 +124,7 @@ type Date_Time_Formatter
Date.parse "1 Nov '95" "d MMM ''yy{2099}" == (Date.new 2095 11 01)
@locale Locale.default_widget
from_simple_pattern : Text -> Locale -> Date_Time_Formatter ! Date_Time_Format_Parse_Error
from_simple_pattern pattern:Text locale:Locale=Locale.default =
from_simple_pattern pattern:Text='' locale:Locale=Locale.default =
Copy link
Member

Choose a reason for hiding this comment

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

minor thing: I see above in Numbers.format we have "" and here '', shall we try to 'standardize' which one we prefer for empty strings? Or does this depend on the context?

How does the text input widget work? Does it always use '? Does it support escapes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to move to:

  • Use single quotes by default.
  • Use double quotes if it would avoid escaping.
  • Use escaped single quotes.

No the text input doesn't do that it just uses escaped single quotes.

format = Date_Time_Formatter.from_simple_pattern 'd MMMM yyyy' locale=Locale.france
label = 'd MMMM yyyy - with custom Locale (e.g. ' + date.format format + ')'
code = "(Date_Time_Formatter.from_simple_pattern 'd MMMM yyyy' locale=Locale.france)"
Option label code [["pattern", make_single_choice formats], ["locale", Locale.default_widget]]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these nested widgets be set automatically?

Or if we set the 'toplevel' widget, than all inner ones must also be set manually to work?

Asking mostly to understand and use the correct practice myself when adding any widgets.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes the top level ones will be set automatically (when a bug is fixed).
However in this case I am deliberately adding the inner ones so I can be consistent with outer one and be value type determining what is added.

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, I see! I did not guess that.

I think a comment like 'Overriding the widget for patterns to ensure that the provided formats are the same as on the top level' could clarify this then

formatter = make_value_formatter_for_value_type self.value_type locale format
Column_Ops.map_over_storage self formatter make_string_builder on_problems=Problem_Behavior.Report_Error
new_column
@format (make_format_chooser include_number=(self.value_type.is_numeric || self.value_type==Value_Type.Mixed) include_date=(self.value_type==Value_Type.Date || self.value_type==Value_Type.Mixed) include_date_time=(self.value_type.is_date_time || self.value_type==Value_Type.Mixed) include_time=(self.value_type==Value_Type.Time_Of_Day || self.value_type==Value_Type.Mixed) include_boolean=(self.value_type.is_boolean || self.value_type==Value_Type.Mixed))
Copy link
Member

Choose a reason for hiding this comment

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

I'm tempted to refactor this to take one argument type Typed_Format_Chooser_Settings and have a separate function that computes it based on the self.value_type.

It looks a little bit 'unhygienic' to have such a huge expression in the @ annotation.


Alternatively, we could skip the Typed_Format_Chooser_Settings type, but at least create a helper function make_format_chooser_for_typed_column self and move this logic into there.

(Probably a spurious optimization but I also don't feel as good about so many self.value_type references - while not exactly very expensive, they do more than just accessing a field)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think a method in table Widget_Helpers which took a value type and returned it makes sense.

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

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

Looks good, just some minor style comments.

@jdunkerley jdunkerley added the CI: Ready to merge This PR is eligible for automatic merge label Feb 14, 2024
@mergify mergify bot merged commit 08584b0 into develop Feb 14, 2024
26 of 27 checks passed
@mergify mergify bot deleted the wip/jd/format-parse branch February 14, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants