Skip to content

Commit 361f97c

Browse files
authored
Merge pull request #810 from geneukum/update-class-field-description-to-glimmer
Update class field description component to glimmer
2 parents 9184318 + 66e3476 commit 361f97c

File tree

4 files changed

+98
-88
lines changed

4 files changed

+98
-88
lines changed

Diff for: app/components/class-field-description.hbs

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<section class='{{@type}}'>
2+
{{!-- TODO: Fix this link for a11y --}}
3+
<h3 class='class-field-description--link' data-anchor='{{@field.name}}' role='link' {{on 'click' (fn this.updateAnchor @field.name)}}>
4+
<a class='anchor' {{!-- template-lint-disable link-href-attributes --}}>
5+
{{svg-jar 'fa-link' class='class-field-description--link-hover' width='20px' height='20px'}}
6+
</a>
7+
<span class='{{@type}}-name'>{{@field.name}}</span>
8+
{{#if @field.params}}
9+
<span class='args'>
10+
({{join ', ' (map-by 'name' @field.params)}})
11+
</span>
12+
{{/if}}
13+
{{#if @field.return}}
14+
<span class='return-type'>{{@field.return.type}}</span>
15+
{{/if}}
16+
{{#if @field.access}}
17+
<span class='access'>{{@field.access}}</span>
18+
{{/if}}
19+
{{#if @field.deprecated}}
20+
<span class='access'>deprecated</span>
21+
{{/if}}
22+
</h3>
23+
{{#if @model.module}}
24+
<div class='attributes'>
25+
<div class='attribute'>
26+
<span class='attribute-label'>Module:</span>
27+
<span class='attribute-value'><LinkTo @route='project-version.modules.module' @models={{array @model.projectVersion.compactVersion @model.module}}>{{@model.module}}</LinkTo></span>
28+
</div>
29+
</div>
30+
{{/if}}
31+
<p class='github-link' data-test-file={{@field.file}}>
32+
{{#if @field.inherited}}
33+
Inherited from
34+
<a href='{{github-link @model.project.id @model.projectVersion.version @field.file @field.line}}' target='_blank' rel='noopener noreferrer'>
35+
{{@field.inheritedFrom}} {{@field.file}}:{{@field.line}}
36+
</a>
37+
{{else}}
38+
Defined in
39+
<a href='{{github-link @model.project.id @model.projectVersion.version @field.file @field.line}}' target='_blank' rel='noopener noreferrer'>
40+
{{@field.file}}:{{@field.line}}
41+
</a>
42+
{{/if}}
43+
</p>
44+
{{#if @field.since}}
45+
<p class='field-since'>
46+
Available since v{{@field.since}}
47+
</p>
48+
{{/if}}
49+
{{#if (and (eq @field.static 1) (eq @field.itemtype 'method') this.hasImportExample)}}
50+
<ImportExample @item={{concat '{ ' @field.name ' }'}} @package={{@field.class}}/>
51+
{{/if}}
52+
<dl class='parameters'>
53+
{{#each @field.params as |param|}}
54+
<div class='parameter'>
55+
<dt>{{param.name}}</dt>
56+
<dd class='parameter-type'>{{param.type}}</dd>
57+
<dd>{{param.description}}</dd>
58+
{{#if param.props}}
59+
<dl class='parameters'>
60+
{{#each param.props as |prop|}}
61+
<div class='prop'>
62+
<dt>{{prop.name}}</dt>
63+
<dd class='parameter-type'>{{prop.type}}</dd>
64+
<dd>{{prop.description}}</dd>
65+
</div>
66+
{{/each}}
67+
</dl>
68+
{{/if}}
69+
</div>
70+
{{/each}}
71+
{{#if @field.return}}
72+
<div class='return'>
73+
<dt>returns</dt>
74+
<dd class='return-type'>{{@field.return.type}}</dd>
75+
<dd>{{@field.return.description}}</dd>
76+
</div>
77+
{{/if}}
78+
</dl>
79+
{{html-safe @field.description}}
80+
</section>

Diff for: app/components/class-field-description.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { inject as service } from '@ember/service';
2-
import Component from '@ember/component';
2+
import Component from '@glimmer/component';
3+
import { action } from '@ember/object';
34

45
export default class ClassFieldDescription extends Component {
56
@service
67
legacyModuleMappings;
78

89
get hasImportExample() {
910
return this.legacyModuleMappings.hasFunctionMapping(
10-
this.field.name,
11-
this.field.class
11+
this.args.field.name,
12+
this.args.field.class
1213
);
1314
}
1415

@@ -18,5 +19,8 @@ export default class ClassFieldDescription extends Component {
1819
* @method updateAnchor
1920
* @method fieldName String The name representing the field that was clicked.
2021
*/
21-
updateAnchor() {}
22+
@action
23+
updateAnchor(fieldName) {
24+
this.args.updateAnchor?.(fieldName);
25+
}
2226
}

Diff for: app/templates/components/class-field-description.hbs

-80
This file was deleted.

Diff for: tests/integration/components/class-field-description-test.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ module('Integration | Component | class field description', function (hooks) {
2626
})
2727
);
2828

29-
await render(hbs`{{class-field-description type=type field=field}}`);
29+
await render(
30+
hbs`<ClassFieldDescription @type={{this.type}} @field={{this.field}}/>`
31+
);
3032

3133
assert.dom('.method-name').hasText('concat');
3234
assert.dom(findAll('.access')[0]).hasText('public');
@@ -47,7 +49,9 @@ module('Integration | Component | class field description', function (hooks) {
4749
})
4850
);
4951

50-
await render(hbs`{{class-field-description type=type field=field}}`);
52+
await render(
53+
hbs`<ClassFieldDescription @type={{this.type}} @field={{this.field}}/>`
54+
);
5155

5256
await triggerEvent('.class-field-description--link', 'mouseenter');
5357
assert
@@ -73,7 +77,7 @@ module('Integration | Component | class field description', function (hooks) {
7377
);
7478

7579
await render(
76-
hbs`{{class-field-description field=field updateAnchor=updateAnchor}}`
80+
hbs`<ClassFieldDescription @field={{this.field}} @updateAnchor={{this.updateAnchor}}/>`
7781
);
7882

7983
await click('.class-field-description--link');
@@ -98,7 +102,9 @@ module('Integration | Component | class field description', function (hooks) {
98102
})
99103
);
100104

101-
await render(hbs`{{class-field-description type=type field=field}}`);
105+
await render(
106+
hbs`<ClassFieldDescription @type={{this.type}} @field={{this.field}}/>`
107+
);
102108

103109
assert.dom(find('.prop:nth-child(1) dt')).hasText('prop1');
104110
assert.dom(find('.prop:nth-child(2) dt')).hasText('prop2');

0 commit comments

Comments
 (0)