-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ChangeView component to bulk update preview (#5209)
* plug ChangeView component into bulk update preview * tests for unifyDocuments() * leave space for expand/collapse buttons * css tweaks * toBSON fixes * address TODOs * factor out expand button * fix bulk update e2e test * depcheck * unit tests for ChangeView component * address TODO * don't promote values when loading before&after preview docs * remove TODO * ignore the generated expected results * maybe without the leading slash * consistently use getValueShape() * live with horizontal scrolling rather than weird wrapping * wider preview, remove extra spacing, format the default update text * sans only * sans only * json formatting seems to not be entirely deterministic.. * update e2e expected result * larger modal for bulk update
- Loading branch information
Showing
50 changed files
with
9,028 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
* text=auto eol=lf | ||
/packages/bson-transpilers/lib/**/* linguist-generated=true | ||
packages/compass-crud/test/fixture-results/* linguist-generated=true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
36 changes: 36 additions & 0 deletions
36
packages/compass-crud/src/components/change-view/bson-utils.ts
This file contains 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,36 @@ | ||
import { EJSON } from 'bson'; | ||
|
||
import { getValueShape } from './shape-utils'; | ||
|
||
export function stringifyBSON(value: any) { | ||
if (value?.inspect) { | ||
return value.inspect(); | ||
} | ||
if (value?.toISOString) { | ||
return value.toISOString(); | ||
} | ||
return EJSON.stringify(value); | ||
} | ||
|
||
export function unBSON(value: any | any[]): any | any[] { | ||
const shape = getValueShape(value); | ||
if (shape === 'array') { | ||
return value.map(unBSON); | ||
} else if (shape === 'object') { | ||
const mapped: Record<string, any | any[]> = {}; | ||
for (const [k, v] of Object.entries(value)) { | ||
mapped[k] = unBSON(v); | ||
} | ||
return mapped; | ||
} else if (value?._bsontype) { | ||
return stringifyBSON(value); | ||
} else if (Object.prototype.toString.call(value) === '[object RegExp]') { | ||
// make sure these match when diffing | ||
return value.toString(); | ||
} else if (Object.prototype.toString.call(value) === '[object Date]') { | ||
// make sure dates are consistently strings when diffing | ||
return value.toISOString(); | ||
} else { | ||
return value; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/compass-crud/src/components/change-view/change-view.spec.tsx
This file contains 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,45 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { render, screen, cleanup } from '@testing-library/react'; | ||
import { ChangeView } from './change-view'; | ||
import { fixtureGroups } from '../../../test/before-after-fixtures'; | ||
|
||
function renderChangeView( | ||
props?: Partial<React.ComponentProps<typeof ChangeView>> | ||
) { | ||
return render(<ChangeView name="test" before={{}} after={{}} {...props} />); | ||
} | ||
|
||
describe('ChangeView Component', function () { | ||
afterEach(function () { | ||
cleanup(); | ||
}); | ||
|
||
it('renders', function () { | ||
renderChangeView({ | ||
before: { a: 1 }, | ||
after: { b: 2 }, | ||
}); | ||
|
||
expect(screen.getByTestId('change-view-test')).to.exist; | ||
}); | ||
|
||
for (const group of fixtureGroups) { | ||
context(group.name, function () { | ||
for (const { name, before, after } of group.fixtures) { | ||
it(name, function () { | ||
renderChangeView({ | ||
name, | ||
before, | ||
after, | ||
}); | ||
|
||
// A bit primitive. Just trying to see if there are any errors as a | ||
// sort of regression test. Not sure how to write an assertion that | ||
// would workfor each one. | ||
expect(screen.getByTestId(`change-view-${name}`)).to.exist; | ||
}); | ||
} | ||
}); | ||
} | ||
}); |
Oops, something went wrong.