`useEntityYear`: make the year limits overridable, defaulting to the business's years (initialAccounterYear → current year)

オープン
#5,296 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
graphql, typescript
領域
frontend, web-dev

調査の方向性

Start with packages/client/src/components/financial-entity/use-entity-year.ts and entity-year-filter.tsx, then trace their use in LedgerSection and BalanceSection. Check whether #5228 has introduced the shared year-range helper before implementing the defaults from adminContext.initialAccounterYear, dateEstablished, and the current year. Update the hook, filter, section, and related tests; done means the overrides work, defaults are clamped, and the chosen behavior for valid out-of-range ?year= values is tested.

索引モデルが issue の本文から書いたものです。

説明

Problem

useEntityYear (packages/client/src/components/financial-entity/use-entity-year.ts, from #5277, merged)
validates ?year= against two hard-coded limits, and EntityYearFilter reuses them as the picker's
minDate / maxDate:

  • MIN_ENTITY_YEAR = 1900, MAX_ENTITY_YEAR = 2999: "anything outside is a typo", not a business
    rule. The picker therefore offers ~1100 years, almost all of them meaningless for the active
    business.
  • The "All years" toggle, when released, goes to new Date().getFullYear(), unrelated to any bound.

Callers cannot narrow or widen the range. The first need to widen it is already known: a future
depreciation tax report view has to look past the current year.

The same hook and filter are already used by two sections, LedgerSection and BalanceSection
(#5279), on both the business and the tax category pages, so the limits should be fixed once, in
the shared place.

Related

  • #5228: report year selectors should offer the business's years (initialAccounterYear → current
    year). Same lower/upper bound, for the report screens. This issue should reuse that issue's
    shared year-range hook/helper, not add a second one.
    Whichever lands first introduces it.
  • #5229: merges user_context into businesses_admin. initial_accounter_year moves unchanged,
    and the business start date is collapsed into one column. The client must read the years through
    the GraphQL adminContext fields, never the tables, so the merge doesn't affect it.
  • #5277 (merged): introduced useEntityYear and EntityYearFilter. #5279 (merged): BalanceSection is the second consumer.

Where the years come from

Bound Default Source
min the year the business started using Accounter adminContext.initialAccounterYear (user_context.initial_accounter_year)
min, fallback the year the business was established adminContext.dateEstablished (user_context.date_established) → its year
min, last fallback today's lower bound existing constant
max the current calendar year new Date().getFullYear()

Both adminContext fields are already exposed (AdminContextInfo.initialAccounterYear: Int,
dateEstablished: TimelessDate) but are nullable, and the client boot UserContext query
(providers/user-provider.tsx) doesn't load them. The businesses_admin start-date columns are
not used: they disagree with each other (see #5229, item 3).

Desired behaviour

  1. Defaults. With no override, the range is initialAccounterYear (or the fallbacks above) →
    current year.
  2. Overrides. The hook takes { minYear?, maxYear? }, and EntityYearFilter takes the same two
    props, so a section can narrow or widen the range, e.g. maxYear = currentYear + 5 for a
    future depreciation view. A section component (LedgerSection and BalanceSection, which already take a defaultYear prop) passes
    them through as minYear? / maxYear? props.
  3. The default year stays inside the range. defaultYear and the year the "All years" toggle
    returns to are clamped to [minYear, maxYear].
  4. A ?year= outside the range. Decide and test one behaviour. Recommended: the range limits
    what the picker offers; a ?year= that is a valid 4-digit year is still honoured and stays
    listed, so a linked view never silently changes and a ledger with records from before
    initialAccounterYear (imported history) stays reachable. Keep 1900–2999 only as the "typo"
    guard in parseYear, as today. (Same "years in use stay listed" rule as #5228.)
  5. Return the effective bounds from the hook, { year, setYear, range, minYear, maxYear }, so
    the filter doesn't recompute them.

Suggested approach

  • A small hook that reads adminContext { initialAccounterYear dateEstablished } once for the
    active admin business and returns { minYear, maxYear } with the fallback chain above
    (shared with #5228; unit-tested for null initialAccounterYear, null dateEstablished, both
    set).
  • useEntityYear(defaultYear, options?): options override the hook's defaults; the URL parsing
    stays as is.
  • EntityYearFilter: minYear? / maxYear? props, passed to YearPickerInput minDate /
    maxDate. Drop the exported MIN_ENTITY_YEAR / MAX_ENTITY_YEAR as picker bounds.
  • Compute "current year" at call time, not at module load (see the annual-audit picker below).

Other year inputs with hard-coded limits

All of these can take the same default range, and the future-view case also needs an override.

Site File Min Max
Entity year filter (#5277; used by the ledger and balance sections) financial-entity/entity-year-filter.tsx 1900 2999
Tax report (year + reference years) reports/tax-report/tax-report-filters.tsx 2010 now
Profit & loss (year + reference years) reports/profit-and-loss-report/profit-and-loss-report-filters.tsx 2010 now
Corporate-tax-ruling compliance reports/corporate-tax-ruling-compliance-report/…-filters.tsx 2010 now
Yearly ledger reports/yearly-ledger/index.tsx 2010 now
Annual revenue screens/reports/annual-revenue/index.tsx 2010 now
Depreciation report (free text, validated) screens/reports/depreciation-report/depreciation-report-filters.tsx 2000 2100
Annual audit year picker screens/operations/annual-audit/year-picker.tsx 2000 current year, computed at module load (goes stale in a tab left open over New Year)
SHAAM 6111 screens/reports/shaam-6111-report/years.ts 2020 last year
Form 1214 screens/reports/form-1214-report/years.ts generator's supported years –
Charge spread common/inputs/charge-spread-input.tsx none none (spread years are legitimately in the future; leave unbounded)

The report-screen rows are tracked by #5228; they are listed here only so the shared range has one
definition. This issue covers the entity-page hook and filter, and defines the override API that
the depreciation report (future view) will use.

Scope / checklist

  • Shared { minYear, maxYear } hook from adminContext with fallbacks and tests (reuse #5228's if it exists)
  • useEntityYear(defaultYear, { minYear?, maxYear? }) returns the effective bounds, clamps the default
  • EntityYearFilter minYear? / maxYear? props; remove the 1900/2999 picker bounds
  • LedgerSection and BalanceSection take minYear? / maxYear? and pass them to useEntityYear and EntityYearFilter
  • Decide and test the out-of-range ?year= behaviour (item 4)
  • Update the hook, filter and section tests; add a story with a widened maxYear
  • Depreciation report: use the override for the future-year view (can be a separate PR)

Open questions

  • Out-of-range ?year=: keep and list it (recommended), or clamp it to the range?
  • Entity pages under a multi-owner read scope (activeReadScope): use the active admin business
    (as the depreciation report does with userContext.context.adminBusinessId), or the earliest
    initialAccounterYear across the scope?
  • Should the fallback for a business with neither initialAccounterYear nor dateEstablished be
    the old 1900 or the 2010 used by the report screens?

🤖 Generated with Claude Code


Generated by Claude Code

主要言語
TypeScript
スター
30
フォーク
10
平均マージ
2日 12時間
マージ済み PR(30日)
276

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Urigo/accounter-fullstack のほかの issue

Urigo/accounter-fullstack の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。