Skip to content

Commit

Permalink
fix: long validations (#166)
Browse files Browse the repository at this point in the history
* fix: long validations

* fix: linter errors

* fix: snapshot tests
  • Loading branch information
Mateusz Podlasin authored Sep 3, 2021
1 parent d9a67b4 commit 39ad9e6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/__fixtures__/default-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": {
"type": "string",
"const": "Constant name",
"examples": ["Example name", "Different name"],
"examples": ["Example name", "Different name", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],
"description": "The user's full name. This description can be long and should truncate once it reaches the end of the row. If it's not truncating then theres and issue that needs to be fixed. Help!"
},
"age": {
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2693,6 +2693,9 @@ exports[`HTML Output should match default-schema.json 1`] = `
<span>Example values:</span>
<span>Example name</span>
<span>Different name</span>
<span>
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</span>
</div>
</div>
<div></div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/SchemaRow/SchemaRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export const SchemaRow: React.FunctionComponent<SchemaRowProps> = ({ schemaNode,
const childNodes = React.useMemo(() => calculateChildrenToShow(typeToShow), [typeToShow]);
return (
<div className="sl-relative">
<div className="sl-flex">
<div className="sl-min-w-0 sl-flex-grow">
<div className="sl-flex sl-max-w-full">
<div className="sl-min-w-0 sl-flex-grow sl-max-w-full">
<div
onClick={childNodes.length > 0 ? () => setExpanded(!isExpanded) : undefined}
className={cn({ 'sl-cursor-pointer': childNodes.length > 0 })}
>
<div className="sl-flex sl-items-center sl-my-2">
<div className="sl-flex sl-items-center sl-my-2 sl-max-w-full">
{childNodes.length > 0 ? <Caret isExpanded={isExpanded} /> : null}

<div className="sl-flex sl-items-baseline sl-text-base sl-flex-1">
Expand Down
29 changes: 21 additions & 8 deletions src/components/shared/Validations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ const NumberValidations = ({
return null;
}
return (
<Flex my={2} color="muted">
<Flex color="muted" maxW="full">
{entries
.map(([key, value]) => numberValidationFormatters[key](value))
.map((value, i) => (
<Value key={i} name={value} className="sl-mr-2" />
<Value key={i} name={value} />
))}
</Flex>
);
Expand All @@ -165,10 +165,12 @@ const KeyValueValidations = ({ validations }: { validations: Dictionary<unknown>

const KeyValueValidation = ({ name, values }: { name: string; values: string[] }) => {
return (
<Flex flexWrap color="muted" my={2}>
<Text color="light">{capitalize(name)}:</Text>
<Flex flexWrap color="muted">
<Text color="light" mr={1} mb={2}>
{capitalize(name)}:
</Text>
{uniq(values).map(value => (
<Value key={value} name={value} className="sl-ml-2" />
<Value key={value} name={value} />
))}
</Flex>
);
Expand All @@ -177,19 +179,30 @@ const KeyValueValidation = ({ name, values }: { name: string; values: string[] }
const NameValidations = ({ validations }: { validations: Dictionary<unknown> }) => (
<>
{keys(validations).length ? (
<Flex flexWrap my={2}>
<Flex flexWrap maxW="full">
{keys(validations)
.filter(key => validations[key])
.map(key => (
<Value key={key} name={key} className="sl-mr-2 sl-text-muted sl-capitalize" />
<Value key={key} name={key} className="sl-text-muted sl-capitalize" />
))}
</Flex>
) : null}
</>
);

const Value = ({ name, className }: { name: string; className?: string }) => (
<Text px={1} fontFamily="mono" bg="canvas-100" border rounded="lg" className={className}>
<Text
px={1}
fontFamily="mono"
bg="canvas-100"
border
rounded="lg"
wordBreak="words"
maxW="full"
mr={2}
mb={2}
className={className}
>
{name}
</Text>
);
Expand Down
Loading

0 comments on commit 39ad9e6

Please sign in to comment.