Skip to content

Commit

Permalink
Merge pull request #119 from ditrit/bugfix/unknown_image
Browse files Browse the repository at this point in the history
Bugfix: unknown image and string number for count
  • Loading branch information
Zorin95670 authored Jul 10, 2024
2 parents 4f2ab29 + 8ed7407 commit 41010c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
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

0 comments on commit 41010c8

Please sign in to comment.