From 6257533bead9c0f7391f240c2e5bacc801a90af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Garc=C3=ADa=20Seco?= Date: Mon, 23 Oct 2023 11:55:02 +0200 Subject: [PATCH] feat(description) - Remove extra span in description, extra and statement (#27) * chore(jsf) - remove span description field * chore(jsf) - remove span statements * Release 0.5.0-dev.20230705093926 * docs(helpers) - remove statement wrap * Release 0.5.0-dev.20230705114115 * fix tests * make ci pass * Release 0.5.0-dev.20230810172154 * Release 0.7.0-dev.20230928101050 * remove yarn --------- Co-authored-by: Gabriel --- .gitignore | 4 +++- src/helpers.js | 16 ++++------------ src/tests/createHeadlessForm.test.js | 13 ++++--------- src/utils.js | 22 ---------------------- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 4833ec11..15fa5d8a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,6 @@ coverage dist *.tgz # from unzipping .tgz -package \ No newline at end of file +package + +yarn.lock \ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js index b7d52e8a..4ba02c59 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -9,7 +9,7 @@ import { checkIfConditionMatchesProperties } from './checkIfConditionMatches'; import { supportedTypes, getInputType } from './internals/fields'; import { pickXKey } from './internals/helpers'; import { processJSONLogicNode } from './jsonLogic'; -import { containsHTML, hasProperty, wrapWithSpan } from './utils'; +import { hasProperty } from './utils'; import { buildCompleteYupSchema, buildYupSchema } from './yupSchema'; /** @@ -490,9 +490,7 @@ export function extractParametersFromNode(schemaNode) { const node = omit(schemaNode, ['x-jsf-presentation', 'presentation']); const description = presentation?.description || node.description; - const statementDescription = containsHTML(presentation.statement?.description) - ? wrapWithSpan(presentation.statement.description, { class: 'jsf-statement' }) - : presentation.statement?.description; + const statementDescription = presentation.statement?.description; const value = typeof node.const !== 'undefined' && typeof node.default !== 'undefined' @@ -540,14 +538,8 @@ export function extractParametersFromNode(schemaNode) { ...presentation, jsonLogicValidations, computedAttributes: decoratedComputedAttributes, - description: containsHTML(description) - ? wrapWithSpan(description, { - class: 'jsf-description', - }) - : description, - extra: containsHTML(presentation.extra) - ? wrapWithSpan(presentation.extra, { class: 'jsf-extra' }) - : presentation.extra, + description, + extra: presentation.extra, statement: presentation.statement && { ...presentation.statement, description: statementDescription, diff --git a/src/tests/createHeadlessForm.test.js b/src/tests/createHeadlessForm.test.js index 09e57e9a..1c175f89 100644 --- a/src/tests/createHeadlessForm.test.js +++ b/src/tests/createHeadlessForm.test.js @@ -2040,10 +2040,7 @@ describe('createHeadlessForm', () => { }); expect(result).toMatchObject({ - fields: [ - { description: 'I am regular' }, - { description: 'I am bold.' }, - ], + fields: [{ description: 'I am regular' }, { description: 'I am bold.' }], }); }); @@ -2502,7 +2499,7 @@ describe('createHeadlessForm', () => { }); describe('when a field has conditional presentation properties', () => { - it('adds .jsf-statement to nested statement markup when visible', () => { + it('returns the nested properties when the conditional matches', () => { const { fields } = createHeadlessForm(schemaWithConditionalPresentationProperties, { initialValues: { // show the hidden statement @@ -2510,9 +2507,7 @@ describe('createHeadlessForm', () => { }, }); - expect(fields[0].statement.description).toBe( - `conditional statement markup` - ); + expect(fields[0].statement.description).toBe(`conditional statement markup`); }); }); @@ -3710,7 +3705,7 @@ describe('createHeadlessForm', () => { expect(fields).toMatchObject([ { name: 'time', - description: 'Write in hh:ss format', // from presentation + description: 'Write in hh:ss format', // from presentation inputType: 'clock', // arbitrary type from presentation deprecated: { description: 'In favor of X', // from presentation diff --git a/src/utils.js b/src/utils.js index d6476e99..83cdbdfd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -22,28 +22,6 @@ export function convertDiskSizeFromTo(from, to) { }; } -/** - * Check if a string contains HTML tags - * @param {string} str - * @returns {boolean} - */ -export function containsHTML(str = '') { - return /<[a-z][\s\S]*>/i.test(str); -} - -/** - * Wraps a string with a span with attributes, if any. - * @param {string} html Content to be wrapped - * @param {Object.} properties Object to be converted to HTML attributes - * @returns {string} - */ -export function wrapWithSpan(html, properties = {}) { - const attributes = Object.entries(properties) - .reduce((acc, [key, value]) => `${acc}${key}="${value}" `, '') - .trim(); - return `${html}`; -} - /** * Checks if an object contains a property with a given name. * This util is needed because sometimes a condition coming from the schema could be something like