-
Notifications
You must be signed in to change notification settings - Fork 25
Rework org status: remove program status, merged affiliated-since, 3-value status #1993
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
Open
maebeale
wants to merge
3
commits into
main
Choose a base branch
from
maebeale/remove-org-status-columns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Formats an organization's affiliation history as merged, year-based periods for | ||
| # the "Affiliated since" display. Each affiliation is a [start_date, end_date] | ||
| # interval (a nil end = ongoing); overlapping or touching intervals collapse into | ||
| # one period, and a real gap starts a new one. | ||
| # | ||
| # Formatting: | ||
| # * A lone ongoing period (a fresh org) shows "Mon YYYY" when it began this year | ||
| # (e.g. "Jul 2026"), otherwise just its start year — no end. | ||
| # * In any multi-period list, every period is year-only for consistency: an | ||
| # ongoing period is its start year, a closed period is "YYYY" (same-year) or | ||
| # "YYYY-YYYY". Periods join chronologically with ", " (e.g. "2010-2012, 2026"). | ||
| # | ||
| # Returns nil when no affiliation carries a start date, so callers can fall back | ||
| # to the organization's own start_date. | ||
| class AffiliationPeriods | ||
| def self.label(affiliations, today: Date.current) | ||
| new(affiliations, today: today).label | ||
| end | ||
|
|
||
| def initialize(affiliations, today: Date.current) | ||
| @today = today | ||
| @intervals = affiliations | ||
| .filter_map { |affiliation| interval_for(affiliation) } | ||
| .sort_by { |start, _finish| start } | ||
| end | ||
|
|
||
| def label | ||
| return nil if @intervals.empty? | ||
|
|
||
| periods = merged | ||
| # A single ongoing period is a fresh org — worth the month's precision. | ||
| if periods.one? && ongoing?(periods.first[1]) | ||
| return year_or_month(periods.first[0]) | ||
| end | ||
|
|
||
| periods.map { |period| format_period(period) }.join(", ") | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Affiliations without a start date can't be placed on the timeline. | ||
| def interval_for(affiliation) | ||
| return nil if affiliation.start_date.blank? | ||
|
|
||
| [ affiliation.start_date.to_date, affiliation.end_date&.to_date ] | ||
| end | ||
|
|
||
| def merged | ||
| @intervals.each_with_object([]) do |(start, finish), periods| | ||
| last = periods.last | ||
| if last && overlaps?(last, start) | ||
| last[1] = later_end(last[1], finish) | ||
| else | ||
| periods << [ start, finish ] | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # A nil end is ongoing and swallows every later interval. | ||
| def overlaps?(period, next_start) | ||
| period[1].nil? || next_start <= period[1] | ||
| end | ||
|
|
||
| def later_end(current, other) | ||
| return nil if current.nil? || other.nil? | ||
|
|
||
| [ current, other ].max | ||
| end | ||
|
|
||
| def ongoing?(finish) | ||
| finish.nil? || finish >= @today | ||
| end | ||
|
|
||
| def format_period((start, finish)) | ||
| return start.year.to_s if ongoing?(finish) || start.year == finish.year | ||
|
|
||
| "#{start.year}-#{finish.year}" | ||
| end | ||
|
|
||
| def year_or_month(date) | ||
| date.year == @today.year ? date.strftime("%b %Y") : date.year.to_s | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 From Claude: This is a hand-kept mirror of
AffiliationPeriods(app/services/affiliation_periods.rb) so the edit-form live preview matches the server render. If the Ruby formatting rules change, change both.