Skip to content

♻️ refactor(cattool): assign over core's objects instead of patching prototypes - #124

Open
riccio82 wants to merge 1 commit into
masterfrom
extension-point-registry
Open

♻️ refactor(cattool): assign over core's objects instead of patching prototypes#124
riccio82 wants to merge 1 commit into
masterfrom
extension-point-registry

Conversation

@riccio82

@riccio82 riccio82 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Stops this plugin extending the Matecat frontend by patching React component prototypes, and assigns
over the members of core's plain helper objects instead.

The class-to-function migration in core removed the prototypes this plugin used to patch, so the
segment notes tab stopped being overridden at all. Core now keeps the overridable behaviour on
ordinary exported objects — globalFunctions, segmentNotes, catToolInterface,
useProjectTemplateInterface — and this plugin replaces the members it cares about. There is no
registry, no manifest and no extension-point vocabulary in core: the call sites read as ordinary
code.

Depends on matecat/MateCat#4768 and must land with it. Those objects do not exist on a core
without that PR, and that PR removes the prototypes this plugin used to patch.

Changes

Commit Change
a71dcb4 Replace every prototype patch with an assignment over a member of one of core's helper objects

What each assignment now targets:

Member Was
SegmentActions.addGlossaryItem unchanged — still the same module property, byte for byte
globalFunctions.registerFooterTabs same object
globalFunctions.getContextBefore / getContextAfter / getIdBefore / getIdAfter same object
segmentNotes.getNotes a patch on the notes-tab component prototype
SegmentUtils.segmentHasNote same module property, but now captures whatever is installed and calls it
catToolInterface.getCharacterCounterMode mutation of a core constant
useProjectTemplateInterface.getCharacterCounterMode mutation of a core constant

The note-row builder is now taken from core (segmentNotes.getNote) instead of being copied, so the
override only supplies the grouping this deployment wants.

Rebased onto master after #123 landed, keeping its config.target_code rename inside the block this
branch moves off this.props.

Two behaviour-neutral drops: the setDefaultTabOpen override (core no longer calls it) and the
this.props reads inside the overrides — every member is now a plain function of an explicit context
object, so a wrapper can call the previously installed one unbound.

segmentHasNote uses capture-then-replace rather than a reference to core's original, so a second
plugin wrapping the same member chains instead of one silently discarding the other.

One small consequence to note

Core now filters the size-restriction key out of a segment's metadata before handing it to an
override, so no override repeats that decision. This plugin's "is there any metadata" check therefore
sees the filtered list: a segment whose only metadata key is the size restriction no longer pushes an
empty metadata block into the notes tab. That block rendered nothing visible, so this should be
invisible in the UI.

Testing

Core's frontend suite passes in full on the paired branch — 427 suites / 4444 tests / 2 snapshots,
with every coverage threshold met. This repo has no frontend test suite of its own; eslint reports
no errors on the changed files, where it previously failed to parse them at all. Every relative
import in the changed files was resolved and every assigned member checked to exist on its core
object.

Manual QA outstanding. Needs a live pass on the segment notes tab, the glossary (still read-only
here), the footer tabs and the character counter.

AI Disclosure

AI tools were used: Claude Code (Sonnet 5, Opus 5).

@riccio82 riccio82 changed the title Extension point registry ♻️ refactor(cattool): extend core through the extension-point registry Aug 20, 2026
@riccio82
riccio82 force-pushed the extension-point-registry branch from 54377a3 to 18dc315 Compare August 21, 2026 09:42
@riccio82 riccio82 changed the title ♻️ refactor(cattool): extend core through the extension-point registry ♻️ refactor(cattool): assign over core's objects instead of patching prototypes Aug 21, 2026
…prototypes

The notes tab and the character counter preset were methods on React class
components, so overriding them meant patching a prototype and reading
`this.props`. Core renders with function components now: those members live on
plain objects it exports, and each takes an explicit context object, so they are
replaced by assignment like the segment context functions already were.

Register the extra footer tab on top of whatever is installed at that moment
rather than on core's own implementation, so a tab added elsewhere survives
alongside this one.

Drop the setDefaultTabOpen override — the method it patched no longer exists.
@riccio82
riccio82 force-pushed the extension-point-registry branch from 18dc315 to a71dcb4 Compare August 21, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant