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

Deprecated Primer::LocalTime in favor of Primer::Beta::RelativeTime #1687

Merged
merged 20 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
02e14be
correcting the component status migrator to handle misc files for a c…
mxriverlynn Dec 7, 2022
e772762
deprecate LocalTime in favor of Beta::RelativeTime
mxriverlynn Dec 7, 2022
1d4dee1
added changeset
mxriverlynn Dec 7, 2022
bead9b6
rebuild arguments file
mxriverlynn Dec 7, 2022
ae09242
update status json file
mxriverlynn Dec 7, 2022
495d3b4
move localtime to deprecated list, in site menu
mxriverlynn Dec 7, 2022
8e62589
added shell of guide to migrate from localtime to relativetime
mxriverlynn Dec 7, 2022
f3afccc
fixed the order of deprecated components
mxriverlynn Dec 7, 2022
696063c
finished first draft of local time to relative time guide
mxriverlynn Dec 7, 2022
25f78da
Merge remote-tracking branch 'origin/main' into mxriverlynn/deprecate…
mxriverlynn Dec 7, 2022
cea996c
added p tag with nonbreaking space to fix spacing issue
mxriverlynn Dec 7, 2022
797e064
added example of basic migration, with explanation of what a threshol…
mxriverlynn Dec 8, 2022
c523173
rebuild arguments.json
mxriverlynn Dec 8, 2022
aebb79f
small adjustment to language in migration example
mxriverlynn Dec 8, 2022
9b1fc9a
Update docs/content/guides/primer_local_time.md
mxriverlynn Dec 8, 2022
6c0aff7
clean up trailing spaces
mxriverlynn Dec 8, 2022
aeddcf0
Merge remote-tracking branch 'origin/mxriverlynn/deprecate-localtime'…
mxriverlynn Dec 8, 2022
dccd915
Update docs/content/guides/primer_local_time.md
mxriverlynn Dec 8, 2022
db146c6
Update docs/content/guides/primer_local_time.md
mxriverlynn Dec 8, 2022
8e5153a
minor language adjustment
mxriverlynn Dec 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/long-ears-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Deprecate Primer::LocalTime in favor of Primer::RelativeTime
2 changes: 2 additions & 0 deletions app/components/primer/local_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Primer
# Use `LocalTime` to format a date and time in the user's preferred locale format. This component requires JavaScript.
class LocalTime < Primer::Component
status :deprecated

DEFAULT_DIGIT_TYPE = :numeric
DIGIT_TYPE_OPTIONS = [DEFAULT_DIGIT_TYPE, :"2-digit"].freeze

Expand Down
31 changes: 29 additions & 2 deletions component_status_migrator.thor
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class ComponentStatusMigrator < Thor::Group
move_file("template", template_path, template_path_with_status)
end

def move_reamining_files
Dir["app/components/primer/#{name.underscore}.*"].each do |file_path|
file_name = File.basename(file_path)
new_path = "#{status_full_path}#{file_name}"
move_file("misc", file_path, new_path)
end
end

def move_test
move_file("test", test_path, test_path_with_status)
end
Expand Down Expand Up @@ -69,7 +77,11 @@ class ComponentStatusMigrator < Thor::Group
end

def remove_suffix_from_preview_class
if name == name_without_suffix
if preview_path.include?("_component") && !name.include?("Component") # rubocop:disable Rails/NegateInclude
# if the class name does not include 'Component', but the file name does include '_component',
# this line will correct it by removing the incosistency with the word 'Component'
gsub_file(preview_path_with_status, "class #{name}Component", "class #{name_without_suffix}")
elsif name == name_without_suffix
puts "No change needed - component suffix not removed from lookbook preview class name"
else
gsub_file(preview_path_with_status, "class #{name}", "class #{name_without_suffix}")
Expand All @@ -90,6 +102,13 @@ class ComponentStatusMigrator < Thor::Group
gsub_file(nav_file, "url: \"/components/#{name_without_suffix.downcase}\"", "url: \"/components/#{status_url}#{name_without_suffix.downcase}\"")
end

def update_primer_js_imports
primer_js = "app/components/primer/primer.ts"
original_content = "import './#{name.underscore}'"
updated_content = "import './#{status_folder_name}#{name_without_suffix.underscore}'"
gsub_file(primer_js, original_content, updated_content)
end

def update_all_references
exclude_files = [
".overmind.sock",
Expand Down Expand Up @@ -202,7 +221,11 @@ class ComponentStatusMigrator < Thor::Group
end

def preview_path
@preview_path ||= "previews/primer/#{name.underscore}_preview.rb"
@preview_path ||= begin
path = "previews/primer/#{name.underscore}_preview.rb"
path_with_component = "previews/primer/#{name.underscore}_component_preview.rb"
File.exist?(path_with_component) ? path_with_component : path
end
end

def preview_path_with_status
Expand All @@ -221,6 +244,10 @@ class ComponentStatusMigrator < Thor::Group
@status_module ||= "#{class_status}::" unless stable?
end

def status_full_path
@status_full_path ||= "app/components/primer/#{status_folder_name}"
end

def template_path
@template_path ||= "app/components/primer/#{name.underscore}.html.erb"
end
Expand Down
35 changes: 35 additions & 0 deletions docs/content/guides/primer_local_time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Moving Away From `Primer::LocalTime`
---

This guide will show you how to upgrade from the now deprecated
[`Primer::LocalTime`](https://primer.style/view-components/components/localtime)
to the latest [`Primer::Beta::RelativeTime`](https://primer.style/view-components/components/beta/relativetime)
component.

## Arguments

The following arguments are different between `LocalTime` and `RelativeTime`.

| From `Primer::LocalTime` | To `Primer::Beta::RelativeTime` | Notes |
|--------------------------|---------------------------------|-------|
| `initial_text` | n/a | No longer used. |
| n/a | `tense` | Which tense to use. One of `:auto`, `:future`, or `:past`. |
| n/a | `prefix` | What to prefix the relative ime display with. |
| n/a | `threshold` | The threshold at which relative time displays become absolute. |
| n/a | `precision` | The precision elapsed time should display. One of nil, `:day`, `:hour`, `:minute`, `:month`, `:second`, or `:year`. |
| n/a | `format` | The format the display should take. One of `:auto`, `:elapsed`, or `:micro`. |
| n/a | `lang` | The language to use. |
| n/a | `title` | Provide a custom title to the element. |

The remaining arguments stayed the same.

Please see the following documentation for complete descriptions and examples.

* [Deprecated `Primer::LocalTime`](https://primer.style/view-components/components/localtime)
* [`Primer::Beta::RelativeTime` component](https://primer.style/view-components/components/beta/relativetime)
* [`Primer::Beta::RelativeTime` Lookbook examples](https://primer.style/view-components/lookbook/inspect/primer/beta/relativetime/default)
mxriverlynn marked this conversation as resolved.
Show resolved Hide resolved

<p>&nbsp;</p>

[&larr; Back to migration guides](https://primer.style/view-components/migration)
Comment on lines +57 to +63
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i ran into a styling issue here, with the bullet list and the following link being right up against each other. the backing css for the <ul> with the bullet list doesn't have any padding or margin at the bottom of it, and it ends up looking like this:

image

the hard coded p tag and nonbreaking space are here as a workaround until the styling can be fixed

1 change: 1 addition & 0 deletions docs/content/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ components.
|----------------------|-----------------------|-------|
| [`Primer::ButtonComponent`](https://primer.style/view-components/components/button) | [`Primer::Beta::Button`](https://primer.style/view-components/components/beta/button) | [Upgrade to Primer::Beta::Button](https://primer.style/view-components/guides/primer_button_component) |
| [`Primer::DropdownMenuComponent`](https://primer.style/view-components/components/dropdownmenu) | [`Primer::Alpha::Dropdown`](https://primer.style/view-components/components/alpha/dropdown) | [Upgrade to Primer::Alpha::Dropdown](https://primer.style/view-components/guides/primer_dropdown_menu_component) |
| [`Primer::LocalTime`](https://primer.style/view-components/components/localtime) | [`Primer::Beta::RelativeTime`](https://primer.style/view-components/components/beta/relativetime) | [Upgrade to Primer::Beta::RelativeTime](https://primer.style/view-components/guides/primer_local_time) |
4 changes: 2 additions & 2 deletions docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
url: "/components/alpha/layout"
- title: Link
url: "/components/beta/link"
- title: LocalTime
url: "/components/localtime"
- title: Markdown
url: "/components/beta/markdown"
- title: Menu
Expand Down Expand Up @@ -131,6 +129,8 @@
url: "/components/dropdownmenu"
- title: IconButton
url: "/components/iconbutton"
- title: LocalTime
url: "/components/localtime"
- title: Tooltip
url: "/components/tooltip"
- title: Architecture decisions
Expand Down
5 changes: 5 additions & 0 deletions lib/primer/deprecations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ deprecations:
autocorrect: true
replacement: "Primer::Beta::Label"

- component: "Primer::LocalTime"
autocorrect: false
replacement: "Primer::Beta::RelativeTime"
guide: "https://primer.style/view-components/guides/primer_local_time"

- component: "Primer::LinkComponent"
autocorrect: true
replacement: "Primer::Beta::Link"
Expand Down
2 changes: 1 addition & 1 deletion static/arguments.json
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@
},
{
"component": "LocalTime",
"status": "alpha",
"status": "deprecated",
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/local_time.rb",
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/local_time/default/",
"parameters": [
Expand Down
2 changes: 1 addition & 1 deletion static/statuses.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"Primer::LabelComponent": "deprecated",
"Primer::LayoutComponent": "alpha",
"Primer::LinkComponent": "deprecated",
"Primer::LocalTime": "alpha",
"Primer::LocalTime": "deprecated",
"Primer::Markdown": "deprecated",
"Primer::MenuComponent": "deprecated",
"Primer::Navigation::TabComponent": "alpha",
Expand Down