Skip to content

Commit

Permalink
fix: removed NameValidations to properly show default values (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Domagoj Kriskovic authored Nov 30, 2021
1 parent 2bab691 commit 686400b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
5 changes: 4 additions & 1 deletion src/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,10 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
</div>
</div>
</div>
<div><span>examples</span></div>
<div>
<span>Example value:</span>
<span>true</span>
</div>
</div>
<div></div>
</div>
Expand Down
23 changes: 1 addition & 22 deletions src/components/shared/Validations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import capitalize from 'lodash/capitalize.js';
import keys from 'lodash/keys.js';
import omit from 'lodash/omit.js';
import pick from 'lodash/pick.js';
import pickBy from 'lodash/pickBy.js';
import uniq from 'lodash/uniq.js';
import * as React from 'react';

Expand Down Expand Up @@ -108,13 +107,8 @@ function filterOutOasFormatValidations(format: string, values: Dictionary<unknow

export const Validations: React.FunctionComponent<IValidations> = ({ validations, hideExamples }) => {
const numberValidations = pick(validations, numberValidationNames);
const booleanValidations = omit(
pickBy(validations, v => ['true', 'false'].includes(String(v))),
excludedValidations,
);
const keyValueValidations = omit(validations, [
...keys(numberValidations),
...keys(booleanValidations),
...excludedValidations,
...(hideExamples ? exampleValidationNames : []),
]);
Expand All @@ -123,7 +117,6 @@ export const Validations: React.FunctionComponent<IValidations> = ({ validations
<>
<NumberValidations validations={numberValidations} />
<KeyValueValidations validations={keyValueValidations} />
<NameValidations validations={booleanValidations} />
</>
);
};
Expand Down Expand Up @@ -176,20 +169,6 @@ const KeyValueValidation = ({ name, values }: { name: string; values: string[] }
);
};

const NameValidations = ({ validations }: { validations: Dictionary<unknown> }) => (
<>
{keys(validations).length ? (
<Flex flexWrap maxW="full">
{keys(validations)
.filter(key => validations[key])
.map(key => (
<Value key={key} name={key} className="sl-text-muted sl-capitalize" />
))}
</Flex>
) : null}
</>
);

const Value = ({ name, className }: { name: string; className?: string }) => (
<Text
px={1}
Expand Down Expand Up @@ -226,7 +205,7 @@ export function getValidationsFromSchema(schemaNode: RegularNode) {
: null),
...('annotations' in schemaNode
? {
...(schemaNode.annotations.default ? { default: schemaNode.annotations.default } : null),
...(schemaNode.annotations.default !== void 0 ? { default: schemaNode.annotations.default } : null),
...(schemaNode.annotations.examples ? { examples: schemaNode.annotations.examples } : null),
}
: null),
Expand Down

0 comments on commit 686400b

Please sign in to comment.