Repository navigation
feat(core): DiffViewer moves to Core #13700
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
ernestt
wants to merge
5
commits into
main
Choose a base branch
from
feat/diffviewer-core
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 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
707933d
feat(core): DiffViewer moves to Core
ernestt 14e9088
fix(DiffViewer): Core's slot name, no data-attribute test hooks, and …
ernestt 822f712
docs(CodeBlock): the record names DiffViewer without Lab in FR13 and …
ernestt 60d2826
docs(DiffViewer): the changeset and the record's summary bound the fi…
ernestt aee7438
docs(DiffViewer): the changeset and FR1 say when the status token and…
ernestt 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/cli': patch | ||
| --- | ||
|
|
||
| [docs] `astryx template` lists DiffViewer's blocks among Core's component blocks: the "Unified diff from a patch" showcase, and a new "DiffViewer — Viewed files" example, the file list of a review page, where a "Viewed" checkbox folds each file through `collapsible`. | ||
|
|
||
| @ernestt |
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,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [component] Promote `DiffViewer` to Core, imported from `@astryxdesign/core/DiffViewer` or the package root together with `parseUnifiedDiff`, `createDiffFile`, and the diff model types. DiffViewer shows a read-only, syntax-highlighted diff of one file in unified or split view, with review annotation rows under any line, optional line-number buttons, and folds for a change too large to show line by line. Every changed line reads as added or removed without colour, also under forced colors. When the file has a path, a file header above the hunks shows the path, status, and line counts, and is a disclosure that starts open; `collapsible` takes the same `CollapsibleConfig` as Banner and Collapsible (`{defaultIsOpen: false}` starts it collapsed, `{isOpen, onOpenChange}` controls it, and `false` turns it off). | ||
|
|
||
| @ernestt | ||
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
2 changes: 1 addition & 1 deletion
2
apps/sandbox/src/app/(fullscreen)/pages/diffviewer-perf/benchmark.test.ts
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...ges/lab/blocks/DiffViewerShowcase.doc.mjs → ...nts/DiffViewer/DiffViewerShowcase.doc.mjs
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
14 changes: 14 additions & 0 deletions
14
packages/cli/assets/templates/blocks/components/DiffViewer/DiffViewerViewedFiles.doc.mjs
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,14 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */ | ||
| export const doc = { | ||
| type: 'block', | ||
| exampleFor: 'DiffViewer', | ||
| name: 'DiffViewer — Viewed files', | ||
| displayName: 'Diff Viewer — Viewed files', | ||
| description: | ||
| 'The file list of a review page: one DiffViewer per file in a patch, each with a "Viewed" checkbox in endContent. Checking it folds the file through a controlled collapsible, and the file header still opens and closes the file on its own.', | ||
| isReady: true, | ||
| aspectRatio: 4 / 3, | ||
| componentsUsed: ['DiffViewer', 'CheckboxInput', 'VStack'], | ||
| }; |
74 changes: 74 additions & 0 deletions
74
packages/cli/assets/templates/blocks/components/DiffViewer/DiffViewerViewedFiles.tsx
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,74 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| 'use client'; | ||
|
|
||
| /** | ||
| * @input A two-file patch parsed with parseUnifiedDiff | ||
| * @output One DiffViewer per file, each with a "Viewed" checkbox that folds it | ||
| * @position DiffViewer example block: the file list of a review page | ||
| */ | ||
|
|
||
| import {useState} from 'react'; | ||
| import { | ||
| DiffViewer, | ||
| parseUnifiedDiff, | ||
| type DiffViewerFile, | ||
| } from '@astryxdesign/core/DiffViewer'; | ||
| import {CheckboxInput} from '@astryxdesign/core/CheckboxInput'; | ||
| import {VStack} from '@astryxdesign/core/Stack'; | ||
|
|
||
| const PATCH = `diff --git a/src/cart/total.ts b/src/cart/total.ts | ||
| --- a/src/cart/total.ts | ||
| +++ b/src/cart/total.ts | ||
| @@ -1,6 +1,7 @@ | ||
| import type {CartItem} from './types'; | ||
| +import {roundCurrency} from '../money'; | ||
|
|
||
| export function cartTotal(items: CartItem[], discount = 0) { | ||
| - return items.reduce((sum, item) => sum + item.price, 0) * (1 - discount); | ||
| + const subtotal = items.reduce((sum, item) => sum + item.price, 0); | ||
| + return roundCurrency(subtotal * (1 - discount)); | ||
| } | ||
| diff --git a/src/money.ts b/src/money.ts | ||
| new file mode 100644 | ||
| --- /dev/null | ||
| +++ b/src/money.ts | ||
| @@ -0,0 +1,4 @@ | ||
| +/** Round to whole cents. */ | ||
| +export function roundCurrency(value: number): number { | ||
| + return Math.round(value * 100) / 100; | ||
| +} | ||
| `; | ||
|
|
||
| const FILES = parseUnifiedDiff(PATCH); | ||
|
|
||
| function ReviewFile({file}: {file: DiffViewerFile}) { | ||
| const [isViewed, setIsViewed] = useState(false); | ||
| const [isOpen, setIsOpen] = useState(true); | ||
| return ( | ||
| <DiffViewer | ||
| file={file} | ||
| collapsible={{isOpen, onOpenChange: setIsOpen}} | ||
| endContent={ | ||
| <CheckboxInput | ||
| label="Viewed" | ||
| value={isViewed} | ||
| onChange={checked => { | ||
| setIsViewed(checked); | ||
| setIsOpen(!checked); | ||
| }} | ||
| /> | ||
| } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default function DiffViewerViewedFiles() { | ||
| return ( | ||
| <VStack gap={3}> | ||
| {FILES.map(file => ( | ||
| <ReviewFile key={file.newPath ?? file.oldPath} file={file} /> | ||
| ))} | ||
| </VStack> | ||
| ); | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.