Skip to content

Commit

Permalink
refactor: remove unused departures NoticeSection
Browse files Browse the repository at this point in the history
This type of section is unused and unsupported on any screen type.
  • Loading branch information
digitalcora committed Dec 2, 2024
1 parent e6a2a20 commit b0eb1b6
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 71 deletions.
9 changes: 1 addition & 8 deletions assets/src/components/v2/departures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React, {
import weakKey from "weak-key";

import NormalSection from "./departures/normal_section";
import NoticeSection from "./departures/notice_section";
import { Section, trimSections, toFoldedSection } from "./departures/section";

import { warn } from "Util/sentry";
Expand Down Expand Up @@ -45,13 +44,7 @@ const Departures: ComponentType<Departures> = ({ sections }) => {
return (
<div className="departures-container" ref={ref}>
{foldedSections.map((section) => {
const key = weakKey(section);

if (section.type === "folded_section") {
return <NormalSection {...section} key={key} />;
} else {
return <NoticeSection {...section} key={key} />;
}
return <NormalSection {...section} key={weakKey(section)} />;
})}
</div>
);
Expand Down
13 changes: 0 additions & 13 deletions assets/src/components/v2/departures/notice_section.tsx

This file was deleted.

12 changes: 2 additions & 10 deletions assets/src/components/v2/departures/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ import type {
NormalSection,
FoldedNormalSection,
} from "./normal_section";
import NoticeSection from "./notice_section";

export type Section =
| (NormalSection & { type: "normal_section" })
| (NoticeSection & { type: "notice_section" });
export type Section = NormalSection & { type: "normal_section" };

export type FoldedSection =
| (FoldedNormalSection & { type: "folded_section" })
| (NoticeSection & { type: "notice_section" });
export type FoldedSection = FoldedNormalSection & { type: "folded_section" };

export const toFoldedSection = (section: Section): FoldedSection => {
switch (section.type) {
Expand All @@ -36,9 +31,6 @@ export const toFoldedSection = (section: Section): FoldedSection => {

return foldedSection;
}

case "notice_section":
return section;
}
};

Expand Down
3 changes: 0 additions & 3 deletions assets/src/components/v2/dup/departures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { ComponentType } from "react";

import { type Section as SectionBase } from "Components/v2/departures/section";
import NormalSection from "./departures/normal_section";
import NoticeSection from "Components/v2/departures/notice_section";
import HeadwaySection from "./departures/headway_section";
import NoDataSection from "./departures/no_data_section";
import OvernightSection from "./departures/overnight_section";
Expand All @@ -25,8 +24,6 @@ const Departures: ComponentType<Props> = ({ sections }) => {
switch (section.type) {
case "normal_section":
return <NormalSection {...section} key={i} />;
case "notice_section":
return <NoticeSection {...section} key={i} />;
case "headway_section":
return <HeadwaySection {...section} key={i} />;
case "no_data_section":
Expand Down
12 changes: 0 additions & 12 deletions assets/tests/components/v2/departures/section.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import _ from "lodash/fp";
import {
toFoldedSection,
trimSections,
type FoldedSection,
} from "Components/v2/departures/section";

import { departureRow, normalSection, timeWithCrowding } from "./factories";
Expand All @@ -31,17 +30,6 @@ describe("trimSections", () => {
const buildFoldedSection = (attrs) =>
toFoldedSection(normalSection.build(attrs));

test("does nothing with notice sections", () => {
const sections: FoldedSection[] = [
{
type: "notice_section",
text: { text: [{ text: "text" }] },
},
];

expect(trimSections(sections)).toBe(sections);
});

test("trims one departure from the largest section above its `base`", () => {
const rowsB = departureRow.buildList(5);
const [rowB1, rowB2, rowB3, rowB4, ...trimmedB] = rowsB;
Expand Down
14 changes: 0 additions & 14 deletions lib/screens/v2/widget_instance/departures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ defmodule Screens.V2.WidgetInstance.Departures do
header: Header.t()
}

@type notice_section :: %{
type: :notice_section,
text: FreeTextLine.t()
}

@type headway_section :: %{
type: :headway_section,
route: :red | :orange | :green | :blue,
Expand All @@ -55,7 +50,6 @@ defmodule Screens.V2.WidgetInstance.Departures do
section_data:
list(
normal_section()
| notice_section()
| headway_section()
| overnight_section()
| no_data_section()
Expand Down Expand Up @@ -103,10 +97,6 @@ defmodule Screens.V2.WidgetInstance.Departures do

def serialize_section(section, screen, now, is_only_section \\ false)

def serialize_section(%{type: :notice_section, text: text}, _screen, _now, _) do
%{type: :notice_section, text: text}
end

def serialize_section(%{type: :no_data_section, route: route}, _screen, _now, _) do
text = %FreeTextLine{
icon: Route.icon(route),
Expand Down Expand Up @@ -200,10 +190,6 @@ defmodule Screens.V2.WidgetInstance.Departures do
%{type: :overnight_section, text: FreeTextLine.to_json(text)}
end

def audio_serialize_section(%{type: :notice_section, text: text}, _screen, _now) do
%{type: :notice_section, text: FreeTextLine.to_plaintext(text)}
end

def audio_serialize_section(
%{type: :normal_section, rows: departures, header: header},
screen,
Expand Down
4 changes: 0 additions & 4 deletions lib/screens_web/views/v2/audio/departures_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ defmodule ScreensWeb.V2.Audio.DeparturesView do
end
end

defp render_section(%{type: :notice_section, text: text}) do
~E|<p><%= text %></p>|
end

defp render_section(%{type: :normal_section, header: header, departure_groups: departure_groups})
when is_binary(header) do
~E|<p><%= header %></p><%= Enum.map(departure_groups, &render_departure_group/1) %>|
Expand Down
7 changes: 0 additions & 7 deletions test/screens/v2/widget_instance/departures_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ defmodule Screens.V2.WidgetInstance.DeparturesTest do
} = Departures.serialize_section(section, bus_shelter_screen, now)
end

test "returns serialized notice_section", %{bus_shelter_screen: bus_shelter_screen, now: now} do
section = %{type: :notice_section, text: %{icon: :warning, text: []}}

assert %{type: :notice_section, text: %{icon: :warning, text: []}} ==
Departures.serialize_section(section, bus_shelter_screen, now)
end

test "returns serialized normal_section with notice", %{
bus_shelter_screen: bus_shelter_screen,
now: now
Expand Down

0 comments on commit b0eb1b6

Please sign in to comment.