Skip to content

Update table of contents component to glimmer #809

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

Merged
merged 6 commits into from
Nov 18, 2022
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
44 changes: 44 additions & 0 deletions app/components/table-of-contents.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<ol class='toc-level-0'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note: this is not going to have the exact same DOM as we had before, in two ways:

  1. It won't accept ...attributes, which @ember/component implicitly did.
  2. It won't have a wrapping div.

In this case, that should be fine: the rendering doesn't depend on the wrapping element (I checked!), but I wanted to flag it up for anyone who reads this PR later.

<li class='toc-level-0'>
<a {{action 'toggle' 'modules'}} href='#' data-test-toc-title='packages'>Packages</a>
<ol class='toc-level-1 modules selected'>
{{#each @moduleIDs as |moduleID|}}

{{#if (not-eq moduleID '@ember/object/computed')}}
<li class='toc-level-1' data-test-module={{moduleID}}>
<LinkTo @route='project-version.modules.module' @models={{array @version moduleID}}>{{moduleID}}</LinkTo>
</li>
{{/if}}

{{/each}}
</ol>
</li>

{{#if @isShowingNamespaces}}
<li class='toc-level-0'>
<a {{action 'toggle' 'namespaces'}} href='#' data-test-toc-title='namespaces'>Namespaces</a>
<ol class='toc-level-1 namespaces selected'>
{{#each @namespaceIDs as |namespaceID|}}
<li class='toc-level-1' data-test-namespace={{namespaceID}}>
<LinkTo @route='project-version.namespaces.namespace' @models={{array @version namespaceID}}>{{namespaceID}}</LinkTo>
</li>
{{/each}}
</ol>
</li>
{{/if}}

<li class='toc-level-0'>
<a {{action 'toggle' 'classes'}} href='#' data-test-toc-title='classes'>Classes</a>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good that these didn't change in this case, but we'll definitely want to switch to {{on}} in a follow-up.

<ol class='toc-level-1 classes selected'>
{{#each @classesIDs as |classID|}}
<li class='toc-level-1' data-test-class={{classID}}>
<LinkTo @route='project-version.classes.class' @models={{array @version classID}}>{{classID}}</LinkTo>
</li>
{{/each}}
</ol>
</li>
</ol>
<label class='toc-private-toggle'>
<Input @type='checkbox' @checked={{@showPrivateClasses}} class='private-deprecated-toggle' />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is the two-way binding we'll want to replace.

Show Private / Deprecated
</label>
2 changes: 1 addition & 1 deletion app/components/table-of-contents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { action } from '@ember/object';
import Component from '@ember/component';
import Component from '@glimmer/component';

export default class TableOfContents extends Component {
@action
Expand Down
44 changes: 0 additions & 44 deletions app/templates/components/table-of-contents.hbs

This file was deleted.

2 changes: 1 addition & 1 deletion app/templates/project-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</PowerSelect>
</div>

<TableOfContents @projectId={{this.model.project.id}} @version={{this.urlVersion}} @classesIDs={{this.shownClassesIDs}} @moduleIDs={{this.shownModuleIDs}} @namespaceIDs={{this.shownNamespaceIDs}} @showPrivateClasses={{this.showPrivateClasses}} @isShowingNamespaces={{version-lt this.selectedProjectVersion.compactVersion "2.16"}} />
<TableOfContents @version={{this.urlVersion}} @classesIDs={{this.shownClassesIDs}} @moduleIDs={{this.shownModuleIDs}} @namespaceIDs={{this.shownNamespaceIDs}} @showPrivateClasses={{this.showPrivateClasses}} @isShowingNamespaces={{version-lt this.selectedProjectVersion.compactVersion "2.16"}} />
</aside>
<section class="content">
{{outlet}}
Expand Down
56 changes: 24 additions & 32 deletions tests/integration/components/table-of-contents-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ module('Integration | Component | table of contents', function (hooks) {

test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('classesIDs', CLASSES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
classesIDs=classesIDs
isShowingNamespaces=true
}}
<TableOfContents
@showPrivateClasses={{true}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for a follow-on: this currently uses two-way binding between an Input in the implementation and a property on a service very far away. As a follow-up, we'll want to update that to actually just use normal event handling.

@version={{this.emberVersion}}
@classesIDs={{this.classesIDs}}
@isShowingNamespaces={{true}}
/>
`);

const contentTitle = document.querySelector(
Expand All @@ -41,18 +39,16 @@ module('Integration | Component | table of contents', function (hooks) {

test('Starts with underlying content visible', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('moduleIDs', MODULES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
moduleIDs=moduleIDs
isShowingNamespaces=true
}}
<TableOfContents
@showPrivateClasses={{true}}
@version={{this.emberVersion}}
@moduleIDs={{this.moduleIDs}}
@isShowingNamespaces={{true}}
/>
`);

const contentReference = '.toc-level-1';
Expand All @@ -73,18 +69,16 @@ module('Integration | Component | table of contents', function (hooks) {

test('Underlying content hides once clicked', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('moduleIDs', MODULES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
moduleIDs=moduleIDs
isShowingNamespaces=true
}}
<TableOfContents
@showPrivateClasses={{true}}
@version={{this.emberVersion}}
@moduleIDs={{this.moduleIDs}}
@isShowingNamespaces={{true}}
/>
`);

const contentTitle = document.querySelector(
Expand All @@ -109,18 +103,16 @@ module('Integration | Component | table of contents', function (hooks) {

test('Underlying content should be visible after 2 clicks', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
this.set('projectId', 'Ember');
this.set('emberVersion', '2.4.3');
this.set('moduleIDs', MODULES);

await render(hbs`
{{
table-of-contents showPrivateClasses=true
projectid=projectId
version=emberVersion
moduleIDs=moduleIDs
isShowingNamespaces=true
}}
<TableOfContents
@showPrivateClasses={{true}}
@version={{this.emberVersion}}
@moduleIDs={{this.moduleIDs}}
@isShowingNamespaces={{true}}
/>
`);

const titleButton = document.querySelector(
Expand Down