-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uplift and export
SeekApiResponse
(#812)
This now automatically removes `__typename`s.
- Loading branch information
Showing
10 changed files
with
163 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'wingman-fe': minor | ||
--- | ||
|
||
prettyPrintWithoutTypename: Export new function |
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,5 @@ | ||
--- | ||
'wingman-fe': minor | ||
--- | ||
|
||
SeekApiResponse: Export new component |
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
72 changes: 72 additions & 0 deletions
72
fe/lib/components/SeekApiResponse/SeekApiResponse.stories.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,72 @@ | ||
import 'braid-design-system/reset'; | ||
|
||
import { Heading, Stack } from 'braid-design-system'; | ||
import React, { ComponentProps } from 'react'; | ||
import { CodeBlock } from 'scoobie'; | ||
|
||
import { | ||
BraidArgs, | ||
defaultArgTypes, | ||
defaultArgs, | ||
} from '../../storybook/controls'; | ||
import { BraidStorybookProvider } from '../../storybook/decorators'; | ||
|
||
import { SeekApiResponse as Component } from './SeekApiResponse'; | ||
|
||
export default { | ||
args: { | ||
braidThemeName: defaultArgs.braidThemeName, | ||
}, | ||
argTypes: { | ||
braidThemeName: defaultArgTypes.braidThemeName, | ||
data: { | ||
control: false, | ||
}, | ||
}, | ||
component: Component, | ||
title: 'Utils/SeekApiResponse', | ||
}; | ||
|
||
type ComponentPropsWithoutData = Omit<ComponentProps<typeof Component>, 'data'>; | ||
|
||
type Args = ComponentPropsWithoutData & BraidArgs; | ||
|
||
export const SeekApiResponse = ({ braidThemeName, ...args }: Args) => ( | ||
<BraidStorybookProvider braidThemeName={braidThemeName}> | ||
<Stack dividers space="large"> | ||
{[ | ||
{ | ||
data: {}, | ||
heading: 'Empty object', | ||
}, | ||
{ | ||
data: { | ||
id: { | ||
value: 'abc', | ||
}, | ||
}, | ||
heading: 'Object without __typenames', | ||
}, | ||
{ | ||
data: { | ||
__typename: 'Event', | ||
id: { | ||
__typename: 'ObjectIdentifier', | ||
value: 'abc', | ||
}, | ||
}, | ||
heading: 'Object with nested __typenames', | ||
}, | ||
].map(({ data, heading }) => ( | ||
<Stack key={heading} space="large"> | ||
<Heading level="3">{heading}</Heading> | ||
|
||
<CodeBlock language="json">{JSON.stringify(data, null, 2)}</CodeBlock> | ||
|
||
<Component {...args} data={data} /> | ||
</Stack> | ||
))} | ||
</Stack> | ||
</BraidStorybookProvider> | ||
); | ||
SeekApiResponse.storyName = 'SeekApiResponse'; |
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
19 changes: 19 additions & 0 deletions
19
fe/lib/components/SeekApiResponse/__snapshots__/prettyPrintWithoutTypename.test.ts.snap
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,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`prettyPrintWithoutTypename empty object 1`] = `"{}"`; | ||
|
||
exports[`prettyPrintWithoutTypename object with nested __typenames 1`] = ` | ||
"{ | ||
\\"id\\": { | ||
\\"value\\": 123 | ||
} | ||
}" | ||
`; | ||
|
||
exports[`prettyPrintWithoutTypename object without __typenames 1`] = ` | ||
"{ | ||
\\"id\\": { | ||
\\"value\\": 123 | ||
} | ||
}" | ||
`; |
12 changes: 12 additions & 0 deletions
12
fe/lib/components/SeekApiResponse/prettyPrintWithoutTypename.test.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,12 @@ | ||
import { prettyPrintWithoutTypename } from './prettyPrintWithoutTypename'; | ||
|
||
describe('prettyPrintWithoutTypename', () => { | ||
it.each` | ||
description | input | ||
${'empty object'} | ${{}} | ||
${'object without __typenames'} | ${{ id: { value: 123 } }} | ||
${'object with nested __typenames'} | ${{ __typename: 'Event', id: { __typename: 'ObjectIdentifier', value: 123 } }} | ||
`('$description', ({ input }) => | ||
expect(prettyPrintWithoutTypename(input)).toMatchSnapshot(), | ||
); | ||
}); |
10 changes: 10 additions & 0 deletions
10
fe/lib/components/SeekApiResponse/prettyPrintWithoutTypename.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,10 @@ | ||
/** | ||
* Pretty prints a JSON value with recursively stripping of the GraphQL | ||
* `__typename` field. | ||
*/ | ||
export const prettyPrintWithoutTypename = (data: unknown) => | ||
JSON.stringify( | ||
data, | ||
(name, value) => (name === '__typename' ? undefined : value), | ||
2, | ||
); |
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