Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

fix: LEAP-580: Display non-string values in Text #1675

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/tags/object/RichText/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const Model = types
// nodes count better be the same, so replace them with stubs
// we should not sanitize text tasks because we already have htmlEscape in view.js
if (isFF(FF_SAFE_TEXT) && self.type === 'text') {
self._value = val;
self._value = String(val);
} else {
self._value = sanitizeHtml(String(val));
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const parseValue = (value, task) => {

// value can refer to structures, not only texts, so just replace wouldn't be enough
if (value.match(reVar)?.[0] === value) {
return get(task, value.substr(1)) ?? '';
return get(task, value.slice(1)) ?? '';
}

return value.replace(reVar, (v) => get(task, v.substr(1) ?? ''));
return value.replace(reVar, (v) => get(task, v.slice(1) ?? ''));
};

/**
Expand Down
37 changes: 37 additions & 0 deletions tests/functional/specs/object_tags/text.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { LabelStudio } from '@heartexlabs/ls-test/helpers/LSF';

describe('<Text> tag', () => {
it('Display non-string values', () => {
const config = `
<View>
<Header>String — usual case</Header>
<Text name="string" value="$string"></Text>
<Header>Float number</Header>
<Text name="number" value="$number"></Text>
<Header>Boolean</Header>
<Text name="bool" value="$bool"></Text>
<Header>Array</Header>
<Text name="array" value="$array"></Text>
<Header value="Crazy header $string $number $bool $array" />
</View>
`;

const data = {
string: 'Simple text',
number: 123.45,
bool: false,
array: [1, 2, 3],
};

LabelStudio.params()
.config(config)
.data(data)
.withResult([])
.init();

cy.get('.lsf-object').contains('Simple text').should('be.visible');
cy.get('.lsf-object').contains('123.45').should('be.visible');
cy.get('.lsf-object').contains('false').should('be.visible');
cy.get('.lsf-object').contains('1,2,3').should('be.visible');
});
});
Loading