Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: unknown image and string number for count #119

Merged
merged 3 commits into from
Jul 10, 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
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [Unreleased]

### Fixed

- Register missing icon for unknown component.
- Fix string as number for count attribute.

## [0.9.0] - 2024/07/09

### Added
Expand Down
7 changes: 4 additions & 3 deletions src/drawer/render/TerraformComponentRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class TerraformComponentRenderer extends ComponentRenderer {
*/
getTemplateData(component) {
const countAttribute = component.getAttributeByName('count');
const hasCount = !!countAttribute && countAttribute.value !== 1;
const countValue = parseInt(countAttribute?.value, 10);
const hasCount = !!countAttribute && countValue !== 1;
let count = '?';

if (hasCount && countAttribute.type === 'Number') {
count = countAttribute.value;
if (hasCount && Number.isInteger(countValue)) {
count = countValue;
}

return {
Expand Down
3 changes: 3 additions & 0 deletions src/models/TerraformConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class TerraformConfiguration extends DefaultConfiguration {
}, {
type: 'icons',
name: 'resize',
}, {
type: 'icons',
name: 'unknown',
}],
container: {
margin: 15,
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/drawer/render/TerraformComponentRenderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ describe('Test class: TerraformComponentRenderer', () => {
definition: new TerraformComponentDefinition(),
attributes: [new TerraformComponentAttribute({
name: 'count',
type: 'Number',
value: 2,
type: 'String',
value: '2',
})],
});
const result = renderer.getTemplateData(component);

expect(result.hasCount).toEqual(true);
expect(result.count).toBe(2);
});

Expand Down
Loading