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

Add parent relationship to deprecations to allow grouping in the UI, especially in the index #1383

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@

This is the app that serves https://deprecations.emberjs.com/

## Linking to deprecations

You can link to a specific deprecation by using the ID of the deprecation. For example, to link to the deprecation with the ID `my-old-api`, you can use the following URL:
`https://deprecations.emberjs.com/id/my-old-api`. These URLs can be generated in advance of adding the deprecation guide, when the deprecation lands in the code.
When adding a deprecation the filename should match the ID of the deprecation, or the `displayId` should be specified in the frontmatter.

## Adding new deprecations

The [content](https://github.com/ember-learn/deprecation-app/tree/main/content/) folder contains all the deprecations that are listed by the website. To add a new deprecation, add it to the appropriate folder by creating a new file. The content of the file needs to follow a specific format for the app to work. You can see [this sample](https://raw.githubusercontent.com/ember-learn/deprecation-app/main/content/ember/v3/getting-the-each-property.md) for reference.

### Frontmatter

#### Grouping deprecations

```markdown
parent: deprecation-id
```

Can be used to nest deprecations under a parent grouping for the purpose of the UI. The deprecations will still be available via the direct ID URLs.


## Prerequisites

You will need the following things properly installed on your computer.
Expand Down
9 changes: 9 additions & 0 deletions app/components/deprecation-article.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class DeprecationArticle extends Component {
@tracked showChildDeprecations = false;

get idForTitle() {
return `toc_${this.args.model.title}`;
}

get idForUntil() {
return `toc_until-${this.args.model.until}`;
}

@action
toggleChildDeprecations() {
this.showChildDeprecations = !this.showChildDeprecations;
}
}
4 changes: 3 additions & 1 deletion app/models/content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Model, { attr } from '@ember-data/model';
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default class ContentModel extends Model {
@attr content;
Expand All @@ -7,6 +7,8 @@ export default class ContentModel extends Model {
@attr since;
@attr anchor;
@attr displayId;
@belongsTo('content', { inverse: 'children', async: false }) parent;
@hasMany('content', { inverse: 'parent', async: false }) children;

// v1 has different meta, so conditionally render it
get renderUntil() {
Expand Down
24 changes: 22 additions & 2 deletions app/templates/components/deprecation-article.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@
<div class="my-2">
{{#if @model.renderUntil}}
<div><span class="bold">until: </span>{{@model.until}}</div>
<div><span class="bold">id: </span>{{or @model.displayId @model.id}}</div>
<div><span class="bold">since: </span>{{@model.since}}</div>
<div><span class="bold">id: </span><LinkTo @route="id" @model={{@model.id}}>{{or @model.displayId @model.id}}</LinkTo></div>
{{/if}}
{{#if @model.parent}}
<div><span class="bold">included in: </span><LinkTo @route="id" @model={{@model.parent.id}}>{{or @model.parent.displayId @model.parent.id}}</LinkTo> </div>
{{/if}}
{{#if @model.children.length}}
<div><span class="bold">includes: </span> {{@model.children.length}} deprecations <button type="button" {{on "click" this.toggleChildDeprecations}}>{{(if this.showChildDeprecations 'Collapse all' 'Expand all')}}</button></div>
{{/if}}
</div>
{{#if this.showChildDeprecations}}
{{#each @model.children as |child|}}
<DeprecationArticle @model={{child}}>
<h3>
{{markdown-to-html
child.title
extensions="no-wrapper"
tagName=""
}}
</h3>
</DeprecationArticle>
{{/each}}
{{/if}}
<section>
{{markdown-to-html @model.content}}
</section>
</div>
</div>
3 changes: 3 additions & 0 deletions app/utils/process-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const GLIMMER = 'Glimmer Internals';

export default function processResults(query) {
let results = query.toArray().reduce((results, item) => {
if (item.parent) {
return results;
}
let since = results.find((result) => result.since === item.since);
if (!since) {
since = { since: item.since, contents: [] };
Expand Down
1 change: 1 addition & 0 deletions lib/content-docs-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const jsonTrees = contentFolders.map(
(type) =>
new StaticSiteJson(`content/${type}`, {
attributes: ['title', 'since', 'until', 'anchor', 'displayId'],
references: [{ name: 'parent', type: 'content' }],
type: 'contents',
collate: true,
collationFileName: `${type.replace(/\//, '-')}.x.json`,
Expand Down
Loading