From 730b0a8d70a9e5bc42856c3f30779ebf0d2b9ac9 Mon Sep 17 00:00:00 2001 From: Jon Rohan Date: Thu, 2 Feb 2023 08:13:31 -0800 Subject: [PATCH] Removing the deprecated Primer::TimeAgoComponent (#1792) --- .changeset/strong-kangaroos-speak.md | 5 ++ .../relative_time.ts} | 0 app/components/primer/primer.ts | 2 +- app/components/primer/time_ago_component.rb | 51 ---------------- app/lib/primer/view_helper.rb | 1 - .../src/@primer/gatsby-theme-doctocat/nav.yml | 2 - lib/primer/deprecations.yml | 5 -- lib/primer/yard/component_manifest.rb | 1 - previews/primer/time_ago_component_preview.rb | 27 --------- static/arguments.json | 26 -------- static/audited_at.json | 1 - static/constants.json | 2 - static/statuses.json | 1 - test/components/component_test.rb | 1 - test/components/time_ago_component_test.rb | 60 ------------------- test/lib/primer/view_helper_test.rb | 6 -- test/system/time_ago_component_test.rb | 17 ------ 17 files changed, 6 insertions(+), 202 deletions(-) create mode 100644 .changeset/strong-kangaroos-speak.md rename app/components/primer/{time_ago_component.ts => beta/relative_time.ts} (100%) delete mode 100644 app/components/primer/time_ago_component.rb delete mode 100644 previews/primer/time_ago_component_preview.rb delete mode 100644 test/components/time_ago_component_test.rb delete mode 100644 test/system/time_ago_component_test.rb diff --git a/.changeset/strong-kangaroos-speak.md b/.changeset/strong-kangaroos-speak.md new file mode 100644 index 0000000000..e15bb6479f --- /dev/null +++ b/.changeset/strong-kangaroos-speak.md @@ -0,0 +1,5 @@ +--- +"@primer/view-components": patch +--- + +Removing the deprecated Primer::TimeAgoComponent diff --git a/app/components/primer/time_ago_component.ts b/app/components/primer/beta/relative_time.ts similarity index 100% rename from app/components/primer/time_ago_component.ts rename to app/components/primer/beta/relative_time.ts diff --git a/app/components/primer/primer.ts b/app/components/primer/primer.ts index f2f0722837..5b5f775efc 100644 --- a/app/components/primer/primer.ts +++ b/app/components/primer/primer.ts @@ -8,8 +8,8 @@ import './alpha/tool_tip' import './alpha/x_banner' import './beta/auto_complete/auto_complete' import './beta/clipboard_copy' +import './beta/relative_time' import './alpha/tab_container' -import './time_ago_component' import '../../../lib/primer/forms/primer_multi_input' import '../../../lib/primer/forms/primer_text_field' import '../../../lib/primer/forms/toggle_switch_input' diff --git a/app/components/primer/time_ago_component.rb b/app/components/primer/time_ago_component.rb deleted file mode 100644 index f13d66ff4f..0000000000 --- a/app/components/primer/time_ago_component.rb +++ /dev/null @@ -1,51 +0,0 @@ -# frozen_string_literal: true - -module Primer - # Use `TimeAgo` to display a time relative to how long ago it was. This component requires JavaScript. - class TimeAgoComponent < Primer::Component - status :deprecated - - # @example Default - # <%= render(Primer::TimeAgoComponent.new(time: Time.at(628232400))) %> - # - # @param time [Time] The time to be formatted - # @param micro [Boolean] If true then the text will be formatted in "micro" mode, using as few characters as possible - # @param system_arguments [Hash] <%= link_to_system_arguments_docs %> - def initialize(time:, micro: false, **system_arguments) - @system_arguments = deny_tag_argument(**system_arguments) - @system_arguments[:datetime] = time.utc.iso8601 - @system_arguments[:classes] = class_names("no-wrap", @system_arguments[:classes]) - @system_arguments[:tag] = "relative-time" - @system_arguments[:tense] = "past" - @system_arguments[:format] = "micro" if micro - @time = time - @micro = micro - end - - def call - render(Primer::BaseComponent.new(**@system_arguments)) { time_in_words } - end - - private - - def time_in_words - return @time.in_time_zone.strftime("%b %-d, %Y") unless @micro - - seconds_ago = Time.current - @time - - if seconds_ago < 1.minute - # :nocov: - "1m" - # :nocov: - elsif seconds_ago >= 1.minute && seconds_ago < 1.hour - "#{(seconds_ago / 60).floor}m" - elsif seconds_ago >= 1.hour && seconds_ago < 1.day - "#{(seconds_ago / 60 / 60).floor}h" - elsif seconds_ago >= 1.day && seconds_ago < 1.year - "#{(seconds_ago / 60 / 60 / 24).floor}d" - elsif seconds_ago >= 1.year - "#{(seconds_ago / 60 / 60 / 24 / 365).floor}y" - end - end - end -end diff --git a/app/lib/primer/view_helper.rb b/app/lib/primer/view_helper.rb index 96959aeb2e..483c151671 100644 --- a/app/lib/primer/view_helper.rb +++ b/app/lib/primer/view_helper.rb @@ -9,7 +9,6 @@ class ViewHelperNotFound < StandardError; end HELPERS = { octicon: "Primer::Beta::Octicon", heading: "Primer::Beta::Heading", - time_ago: "Primer::TimeAgoComponent", image: "Primer::Alpha::Image" }.freeze diff --git a/docs/src/@primer/gatsby-theme-doctocat/nav.yml b/docs/src/@primer/gatsby-theme-doctocat/nav.yml index d7a7cce7ea..73ed630eb7 100644 --- a/docs/src/@primer/gatsby-theme-doctocat/nav.yml +++ b/docs/src/@primer/gatsby-theme-doctocat/nav.yml @@ -123,8 +123,6 @@ url: "/components/button" - title: IconButton url: "/components/iconbutton" - - title: TimeAgo - url: "/components/timeago" - title: Tooltip url: "/components/tooltip" - title: Architecture decisions diff --git a/lib/primer/deprecations.yml b/lib/primer/deprecations.yml index 3c8e9a1b2b..4a40b71435 100644 --- a/lib/primer/deprecations.yml +++ b/lib/primer/deprecations.yml @@ -26,11 +26,6 @@ deprecations: autocorrect: true replacement: "Primer::Beta::IconButton" - - component: "Primer::TimeAgoComponent" - autocorrect: false - replacement: "Primer::Beta::RelativeTime" - guide: "https://primer.style/view-components/guides/primer_time_ago" - - component: "Primer::Tooltip" autocorrect: true replacement: "Primer::Alpha::Tooltip" diff --git a/lib/primer/yard/component_manifest.rb b/lib/primer/yard/component_manifest.rb index f3d3ebd3c4..cdb5c48f50 100644 --- a/lib/primer/yard/component_manifest.rb +++ b/lib/primer/yard/component_manifest.rb @@ -53,7 +53,6 @@ class ComponentManifest Primer::Beta::Subhead => {}, Primer::Alpha::TabContainer => { js: true }, Primer::Beta::Text => {}, - Primer::TimeAgoComponent => { js: true }, Primer::Beta::TimelineItem => {}, Primer::Tooltip => {}, Primer::Truncate => {}, diff --git a/previews/primer/time_ago_component_preview.rb b/previews/primer/time_ago_component_preview.rb deleted file mode 100644 index 1d6fcddf26..0000000000 --- a/previews/primer/time_ago_component_preview.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -# rubocop:disable Primer/ComponentNameMigration - -module Primer - # @label TimeAgoComponent - class TimeAgoComponentPreview < ViewComponent::Preview - # @label Playground - # - # @param time datetime-local - # @param micro [Boolean] toggle - def playground(time: Time.zone.now.to_s, micro: false) - render(Primer::TimeAgoComponent.new(time: DateTime.parse(time), micro: micro)) - end - - # @param time datetime-local - # @param micro [Boolean] toggle - def default(time: Time.zone.now.to_s, micro: false) - render(Primer::TimeAgoComponent.new(time: DateTime.parse(time), micro: micro)) - end - - def micro - render(Primer::TimeAgoComponent.new(time: Time.zone.now, micro: true)) - end - end -end -# rubocop:enable Primer/ComponentNameMigration diff --git a/static/arguments.json b/static/arguments.json index 04806282ec..ec7dcf17a0 100644 --- a/static/arguments.json +++ b/static/arguments.json @@ -2381,32 +2381,6 @@ } ] }, - { - "component": "TimeAgo", - "status": "deprecated", - "source": "https://github.com/primer/view_components/tree/main/app/components/primer/time_ago_component.rb", - "lookbook": "https://primer.style/view-components/lookbook/inspect/primer/time_ago/default/", - "parameters": [ - { - "name": "time", - "type": "Time", - "default": "N/A", - "description": "The time to be formatted" - }, - { - "name": "micro", - "type": "Boolean", - "default": "`false`", - "description": "If true then the text will be formatted in \"micro\" mode, using as few characters as possible" - }, - { - "name": "system_arguments", - "type": "Hash", - "default": "N/A", - "description": "[System arguments](/system-arguments)" - } - ] - }, { "component": "Tooltip", "status": "deprecated", diff --git a/static/audited_at.json b/static/audited_at.json index c2bcdcb7cc..010d012712 100644 --- a/static/audited_at.json +++ b/static/audited_at.json @@ -79,7 +79,6 @@ "Primer::IconButton": "", "Primer::LayoutComponent": "", "Primer::Navigation::TabComponent": "", - "Primer::TimeAgoComponent": "", "Primer::Tooltip": "", "Primer::Truncate": "" } diff --git a/static/constants.json b/static/constants.json index 59822bd94e..630e45b0fe 100644 --- a/static/constants.json +++ b/static/constants.json @@ -1073,8 +1073,6 @@ ], "DEFAULT_ARIA_CURRENT_FOR_ANCHOR": "page" }, - "Primer::TimeAgoComponent": { - }, "Primer::Tooltip": { "ALIGN_DEFAULT": "default", "ALIGN_MAPPING": { diff --git a/static/statuses.json b/static/statuses.json index 49f4340928..88085fe6e5 100644 --- a/static/statuses.json +++ b/static/statuses.json @@ -79,7 +79,6 @@ "Primer::IconButton": "deprecated", "Primer::LayoutComponent": "alpha", "Primer::Navigation::TabComponent": "alpha", - "Primer::TimeAgoComponent": "deprecated", "Primer::Tooltip": "deprecated", "Primer::Truncate": "beta" } diff --git a/test/components/component_test.rb b/test/components/component_test.rb index 0a97fd30ac..4e26e612c2 100644 --- a/test/components/component_test.rb +++ b/test/components/component_test.rb @@ -98,7 +98,6 @@ class PrimerComponentTest < Minitest::Test [Primer::Beta::Text, {}], [Primer::Truncate, {}], [Primer::Beta::Truncate, {}, proc { |component| component.with_item { "Foo" } }], - [Primer::TimeAgoComponent, { time: Time.zone.now }], [Primer::Beta::TimelineItem, {}, proc { |component| component.with_body { "Foo" } }], [Primer::Tooltip, { label: "More" }], [Primer::Alpha::UnderlineNav, { label: "aria label" }, proc { |component| component.with_tab(selected: true) { "Foo" } }], diff --git a/test/components/time_ago_component_test.rb b/test/components/time_ago_component_test.rb deleted file mode 100644 index 718f80f956..0000000000 --- a/test/components/time_ago_component_test.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -require "components/test_helper" -require "timecop" - -class PrimerTimeAgoComponentTest < Minitest::Test - include Primer::ComponentTestHelpers - - def test_renders_time_ago_element - render_inline(Primer::TimeAgoComponent.new(time: Time.zone.now)) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime][class]", count: 1) - end - - def test_reflects_datetime_attr_and_contents_based_on_date - render_inline(Primer::TimeAgoComponent.new(time: Time.utc(2021, 1, 1, 9, 10))) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime=\"2021-01-01T09:10:00Z\"]", count: 1, text: "Jan 1, 2021") - end - - def test_sets_contents_to_short_representation_with_micro_eq_true - Timecop.freeze("2021-01-30T15:00:00Z") do - render_inline(Primer::TimeAgoComponent.new(time: Time.utc(2021, 1, 1, 9, 10), micro: true)) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime=\"2021-01-01T09:10:00Z\"]", count: 1, text: "29d") - end - end - - def test_returns_number_of_mins_ago_in_micro_format - Timecop.freeze("2021-01-01T09:50:00Z") do - render_inline(Primer::TimeAgoComponent.new(time: Time.utc(2021, 1, 1, 9, 10), micro: true)) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime=\"2021-01-01T09:10:00Z\"]", count: 1, text: "40m") - end - end - - def test_returns_number_of_hours_ago_in_micro_format - Timecop.freeze("2021-01-01T15:00:00Z") do - render_inline(Primer::TimeAgoComponent.new(time: Time.utc(2021, 1, 1, 9, 10), micro: true)) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime=\"2021-01-01T09:10:00Z\"]", count: 1, text: "5h") - end - end - - def test_returns_number_of_days_ago_in_micro_format - Timecop.freeze("2021-09-30T15:00:00Z") do - render_inline(Primer::TimeAgoComponent.new(time: Time.utc(2021, 1, 1, 9, 10), micro: true)) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime=\"2021-01-01T09:10:00Z\"]", count: 1, text: "d") - end - end - - def test_returns_number_of_years_ago_in_micro_format - Timecop.freeze("2037-09-30T15:00:00Z") do - render_inline(Primer::TimeAgoComponent.new(time: Time.utc(2021, 1, 1, 9, 10), micro: true)) - - assert_selector("relative-time[tense=\"past\"][data-view-component][datetime=\"2021-01-01T09:10:00Z\"]", count: 1, text: "16y") - end - end -end diff --git a/test/lib/primer/view_helper_test.rb b/test/lib/primer/view_helper_test.rb index 96a0278ffd..1dccb32103 100644 --- a/test/lib/primer/view_helper_test.rb +++ b/test/lib/primer/view_helper_test.rb @@ -16,12 +16,6 @@ def test_renders_heading_using_shorthand assert_selector("h2", text: "My Heading") end - def test_renders_time_ago_using_shorthand - primer_time_ago(time: Time.at(1_615_490_863).utc) - - assert_selector("relative-time", text: "Mar 11, 2021") - end - def test_renders_octicon_using_shorthand primer_octicon icon: :star diff --git a/test/system/time_ago_component_test.rb b/test/system/time_ago_component_test.rb deleted file mode 100644 index 4879a434a8..0000000000 --- a/test/system/time_ago_component_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require "system/test_case" - -class IntegrationTimeAgoComponentTest < System::TestCase - def test_render - visit_preview(:default) - - assert_selector("relative-time[data-view-component][tense='past']") - end - - def test_render_micro - visit_preview(:micro) - - assert_selector("relative-time[data-view-component][tense='past'][format='micro']") - end -end