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

move Primer::LocalTime to Primer::Alpha::LocalTime #1675

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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/sharp-plants-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Move Primer::LocalTime to Primer::Alpha::LocalTime, and deprecate the original
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions app/components/primer/alpha/local_time.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

module Primer
module Alpha
# Use `LocalTime` to format a date and time in the user's preferred locale format. This component requires JavaScript.
class LocalTime < Primer::Component
DEFAULT_DIGIT_TYPE = :numeric
DIGIT_TYPE_OPTIONS = [DEFAULT_DIGIT_TYPE, :"2-digit"].freeze

DEFAULT_TEXT_TYPE = :short
TEXT_TYPE_OPTIONS = [DEFAULT_TEXT_TYPE, :long].freeze

# @example Default
# <%= render(Primer::Alpha::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"))) %>
#
# @example All the options
# <%= render(Primer::Alpha::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"), weekday: :long, year: :"2-digit", month: :long, day: :"2-digit", hour: :"2-digit", minute: :"2-digit", second: :"2-digit", time_zone_name: :long)) %>
#
# @example With initial content
# <%= render(Primer::Alpha::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"))) do %>
# <!-- This content will be replaced once the component connects -->
# 2014/06/01 13:05
# <% end %>
#
# @param datetime [DateTime] The date to parse
# @param initial_text [String] Text to render before component is initialized
# @param weekday [Symbol] <%= one_of(Primer::Alpha::LocalTime::TEXT_TYPE_OPTIONS) %>
# @param year [Symbol] <%= one_of(Primer::Alpha::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param month [Symbol] <%= one_of(Primer::Alpha::LocalTime::TEXT_TYPE_OPTIONS) %>
# @param day [Symbol] <%= one_of(Primer::Alpha::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param hour [Symbol] <%= one_of(Primer::Alpha::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param minute [Symbol] <%= one_of(Primer::Alpha::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param second [Symbol] <%= one_of(Primer::Alpha::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param time_zone_name [Symbol] <%= one_of(Primer::Alpha::LocalTime::TEXT_TYPE_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(datetime:, initial_text: nil, weekday: DEFAULT_TEXT_TYPE, year: DEFAULT_DIGIT_TYPE, month: DEFAULT_TEXT_TYPE, day: DEFAULT_DIGIT_TYPE, hour: DEFAULT_DIGIT_TYPE, minute: DEFAULT_DIGIT_TYPE, second: DEFAULT_DIGIT_TYPE, time_zone_name: DEFAULT_TEXT_TYPE, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)

@datetime = datetime

@system_arguments[:tag] = "relative-time"
@system_arguments[:threshold] = "PT0S"
@system_arguments[:prefix] = ""
@system_arguments[:datetime] = datetime

@initial_text = initial_text

@system_arguments[:weekday] = fetch_or_fallback(TEXT_TYPE_OPTIONS, weekday, DEFAULT_TEXT_TYPE)
@system_arguments[:year] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, year, DEFAULT_DIGIT_TYPE)
@system_arguments[:month] = fetch_or_fallback(TEXT_TYPE_OPTIONS, month, DEFAULT_TEXT_TYPE)
@system_arguments[:day] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, day, DEFAULT_DIGIT_TYPE)
@system_arguments[:hour] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, hour, DEFAULT_DIGIT_TYPE)
@system_arguments[:minute] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, minute, DEFAULT_DIGIT_TYPE)
@system_arguments[:second] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, second, DEFAULT_DIGIT_TYPE)
@system_arguments[:"time-zone-name"] = fetch_or_fallback(TEXT_TYPE_OPTIONS, time_zone_name, DEFAULT_TEXT_TYPE)
end

def call
render(Primer::BaseComponent.new(**@system_arguments).with_content(@initial_text || @datetime.strftime("%B %-d, %Y %H:%M %Z")))
end
end
end
end
58 changes: 2 additions & 56 deletions app/components/primer/local_time.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,7 @@
# frozen_string_literal: true

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
DEFAULT_DIGIT_TYPE = :numeric
DIGIT_TYPE_OPTIONS = [DEFAULT_DIGIT_TYPE, :"2-digit"].freeze

DEFAULT_TEXT_TYPE = :short
TEXT_TYPE_OPTIONS = [DEFAULT_TEXT_TYPE, :long].freeze

# @example Default
# <%= render(Primer::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"))) %>
#
# @example All the options
# <%= render(Primer::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"), weekday: :long, year: :"2-digit", month: :long, day: :"2-digit", hour: :"2-digit", minute: :"2-digit", second: :"2-digit", time_zone_name: :long)) %>
#
# @example With initial content
# <%= render(Primer::LocalTime.new(datetime: DateTime.parse("2014-06-01T13:05:07Z"))) do %>
# <!-- This content will be replaced once the component connects -->
# 2014/06/01 13:05
# <% end %>
#
# @param datetime [DateTime] The date to parse
# @param initial_text [String] Text to render before component is initialized
# @param weekday [Symbol] <%= one_of(Primer::LocalTime::TEXT_TYPE_OPTIONS) %>
# @param year [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param month [Symbol] <%= one_of(Primer::LocalTime::TEXT_TYPE_OPTIONS) %>
# @param day [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param hour [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param minute [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param second [Symbol] <%= one_of(Primer::LocalTime::DIGIT_TYPE_OPTIONS) %>
# @param time_zone_name [Symbol] <%= one_of(Primer::LocalTime::TEXT_TYPE_OPTIONS) %>
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(datetime:, initial_text: nil, weekday: DEFAULT_TEXT_TYPE, year: DEFAULT_DIGIT_TYPE, month: DEFAULT_TEXT_TYPE, day: DEFAULT_DIGIT_TYPE, hour: DEFAULT_DIGIT_TYPE, minute: DEFAULT_DIGIT_TYPE, second: DEFAULT_DIGIT_TYPE, time_zone_name: DEFAULT_TEXT_TYPE, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)

@datetime = datetime

@system_arguments[:tag] = "relative-time"
@system_arguments[:threshold] = "PT0S"
@system_arguments[:prefix] = ""
@system_arguments[:datetime] = datetime

@initial_text = initial_text

@system_arguments[:weekday] = fetch_or_fallback(TEXT_TYPE_OPTIONS, weekday, DEFAULT_TEXT_TYPE)
@system_arguments[:year] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, year, DEFAULT_DIGIT_TYPE)
@system_arguments[:month] = fetch_or_fallback(TEXT_TYPE_OPTIONS, month, DEFAULT_TEXT_TYPE)
@system_arguments[:day] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, day, DEFAULT_DIGIT_TYPE)
@system_arguments[:hour] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, hour, DEFAULT_DIGIT_TYPE)
@system_arguments[:minute] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, minute, DEFAULT_DIGIT_TYPE)
@system_arguments[:second] = fetch_or_fallback(DIGIT_TYPE_OPTIONS, second, DEFAULT_DIGIT_TYPE)
@system_arguments[:"time-zone-name"] = fetch_or_fallback(TEXT_TYPE_OPTIONS, time_zone_name, DEFAULT_TEXT_TYPE)
end

def call
render(Primer::BaseComponent.new(**@system_arguments).with_content(@initial_text || @datetime.strftime("%B %-d, %Y %H:%M %Z")))
end
class LocalTime < Primer::Alpha::LocalTime
status :deprecated
end
end
2 changes: 1 addition & 1 deletion app/components/primer/primer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import './alpha/tool_tip'
import './alpha/x_banner'
import './beta/auto_complete/auto_complete'
import './beta/clipboard_copy'
import './local_time'
import './alpha/local_time'
import './tab_container_component'
import './time_ago_component'
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
2 changes: 1 addition & 1 deletion docs/src/@primer/gatsby-theme-doctocat/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
- title: Link
url: "/components/beta/link"
- title: LocalTime
url: "/components/localtime"
url: "/components/alpha/localtime"
- title: Markdown
url: "/components/markdown"
- title: Menu
Expand Down
4 changes: 4 additions & 0 deletions lib/primer/deprecations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ deprecations:
autocorrect: true
replacement: "Primer::Beta::Link"

- component: "Primer::LocalTime"
autocorrect: true
replacement: "Primer::Alpha::LocalTime"

- component: "Primer::PopoverComponent"
autocorrect: true
replacement: "Primer::Beta::Popover"
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/docs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace :docs do
Primer::Alpha::Layout,
Primer::HellipButton,
Primer::Alpha::Image,
Primer::LocalTime,
Primer::Alpha::LocalTime,
Primer::OcticonSymbolsComponent,
Primer::Alpha::ImageCrop,
Primer::IconButton,
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace :docs do

js_components = [
Primer::Alpha::Dropdown,
Primer::LocalTime,
Primer::Alpha::LocalTime,
Primer::Alpha::ImageCrop,
Primer::Beta::AutoComplete,
Primer::Alpha::Banner,
Expand Down
56 changes: 56 additions & 0 deletions previews/primer/alpha/local_time_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

module Primer
module Alpha
# @label LocalTime
class LocalTimePreview < ViewComponent::Preview
# @param datetime datetime-local
# @param weekday [Symbol] select [long, short]
# @param month [Symbol] select [long, short]
# @param year [Symbol] select [numeric, "2-digit"]
# @param day [Symbol] select [numeric, "2-digit"]
# @param hour [Symbol] select [numeric, "2-digit"]
# @param minute [Symbol] select [numeric, "2-digit"]
# @param second [Symbol] select [numeric, "2-digit"]
# @param time_zone_name [Symbol] select [long, short]
def playground(datetime: "2014-04-01T16:30:00-08:00", weekday: :short, month: :short, year: :numeric, day: :numeric, hour: :numeric, minute: :numeric, second: :numeric, time_zone_name: :short)
render(Primer::Alpha::LocalTime.new(datetime: DateTime.parse(datetime), weekday: weekday, month: month, year: year, day: day, hour: hour, minute: minute, second: second, time_zone_name: time_zone_name))
end

# @param datetime datetime-local
# @param weekday [Symbol] select [long, short]
# @param month [Symbol] select [long, short]
# @param year [Symbol] select [numeric, "2-digit"]
# @param day [Symbol] select [numeric, "2-digit"]
# @param hour [Symbol] select [numeric, "2-digit"]
# @param minute [Symbol] select [numeric, "2-digit"]
# @param second [Symbol] select [numeric, "2-digit"]
# @param time_zone_name [Symbol] select [long, short]
def default(datetime: "2014-04-01T16:30:00-08:00", weekday: :short, month: :short, year: :numeric, day: :numeric, hour: :numeric, minute: :numeric, second: :numeric, time_zone_name: :short)
render(Primer::Alpha::LocalTime.new(datetime: DateTime.parse(datetime), weekday: weekday, month: month, year: year, day: day, hour: hour, minute: minute, second: second, time_zone_name: time_zone_name))
end

# @hidden
def with_all_the_options
render(Primer::Alpha::LocalTime.new(
datetime: DateTime.parse("2016-06-01T13:05:07Z"),
weekday: :long,
year: :"2-digit",
month: :long,
day: :"2-digit",
hour: :"2-digit",
minute: :"2-digit",
second: :"2-digit",
time_zone_name: :long
))
end

# @label With replaceable content
#
# @param initial_text [String] textarea
def with_contents(initial_text: "This will be replaced")
render Primer::Alpha::LocalTime.new(datetime: DateTime.parse("2014-04-01T16:30:00-08:00"), initial_text: initial_text)
end
end
end
end
54 changes: 0 additions & 54 deletions previews/primer/local_time_component_preview.rb

This file was deleted.

Loading