Skip to content

Extract CrateSidebar component #3215

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 1 commit into from
Feb 1, 2021
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
154 changes: 154 additions & 0 deletions app/components/crate-sidebar.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<section
local-class='authorship'
aria-label="Crate metadata"
...attributes
>
<div local-class='top'>
<div>
<div local-class='last-update'>Last Updated</div>
<div local-class='{{if @version.crate_size 'date-with-small-margin-bot' 'date'}}'>
{{date-format-distance-to-now @crate.updated_at addSuffix=true}}
</div>
</div>

{{#if @version.crate_size}}
<div>
<div local-class='crate-size'>Crate Size</div>
<div local-class='size'>{{pretty-bytes @version.crate_size}}</div>
</div>
{{/if}}

<div>
<h3>Owners</h3>

{{#if this.isOwner}}
<p>
<LinkTo @route="crate.owners" @model={{@crate}} data-test-manage-owners-link>
Manage owners
</LinkTo>
</p>
{{/if}}

<ul local-class='owners' data-test-owners>
{{#each @crate.owner_team as |team|}}
<li>
<LinkTo @route={{team.kind}} @model={{team.login}} data-test-team-link={{team.login}}>
<UserAvatar @user={{team}} @size="medium-small" />
</LinkTo>
</li>
{{/each}}

{{#each @crate.owner_user as |user|}}
<li>
<LinkTo @route={{user.kind}} @model={{user.login}} data-test-user-link={{user.login}}>
<UserAvatar @user={{user}} @size="medium-small" />
</LinkTo>
</li>
{{/each}}
</ul>
</div>

<div>
<h3>Authors</h3>
<ul>
{{#each @version.authorNames as |author|}}
<li>{{ format-email author }}</li>
{{/each}}
</ul>
</div>
</div>

<div local-class='bottom'>
{{#if @version.license}}
<div>
<h3>License</h3>
<p data-test-license>{{ @version.license }}</p>
</div>
{{/if}}

{{#unless @crate.keywords.isPending}}
{{#if @crate.keywords}}
<div>
<h3>Keywords</h3>
<ul local-class='keywords'>
{{#each @crate.keywords as |keyword|}}
<li><LinkTo @route="keyword" @model={{keyword}}>{{keyword.id}}</LinkTo></li>
{{/each}}
</ul>
</div>
{{/if}}
{{/unless}}

{{#unless @crate.categories.isPending}}
{{#if @crate.categories}}
<div>
<h3>Categories</h3>
<ul>
{{#each @crate.categories as |category|}}
<li><LinkTo @route="category" @model={{category.slug}}>{{category.category}}</LinkTo></li>
{{/each}}
</ul>
</div>
{{/if}}
{{/unless}}

<div data-test-versions>
<h3>Versions</h3>
<ul>
{{#each this.smallSortedVersions as |version|}}
<li>
<LinkTo @route="crate.version" @model={{version.num}} data-test-version-link={{version.num}}>
{{ version.num }}
</LinkTo>
{{date-format version.created_at "PP"}}
{{#if version.yanked}}
<span local-class='yanked'>yanked</span>
{{/if}}
</li>
{{/each}}
</ul>
{{#if this.hasMoreVersions}}
<LinkTo @route="crate.versions" @model={{@crate}} local-class="more-versions-link" data-test-all-versions-link>
show all {{ @crate.versions.length }} versions
</LinkTo>
{{/if}}
</div>

<div>
<h3>Dependencies</h3>
<ul data-test-dependencies>
{{#each @version.normalDependencies as |dep|}}
<li><LinkToDep @dep={{dep}} /></li>
{{else}}
{{#if @version.loadDepsTask.isRunning}}
<li>Loading…</li>
{{else}}
<li>None</li>
{{/if}}
{{/each}}
</ul>
</div>

{{#if @version.buildDependencies}}
<div>
<h3>Build-Dependencies</h3>
<ul data-test-build-dependencies>
{{#each @version.buildDependencies as |dep|}}
<li><LinkToDep @dep={{dep}} /></li>
{{/each}}
</ul>
</div>
{{/if}}

{{#if @version.devDependencies}}
<div>
<h3>Dev-Dependencies</h3>
<ul data-test-dev-dependencies>
{{#each @version.devDependencies as |dep|}}
<li><LinkToDep @dep={{dep}} /></li>
{{/each}}
</ul>
</div>
{{/if}}
</div>
</section>
24 changes: 24 additions & 0 deletions app/components/crate-sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { computed } from '@ember/object';
import { gt, readOnly } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';

const NUM_VERSIONS = 5;

export default class DownloadGraph extends Component {
@service session;

@computed('args.crate.owner_user', 'session.currentUser.id')
get isOwner() {
return this.args.crate.owner_user.findBy('id', this.session.currentUser?.id);
}

@readOnly('args.crate.versions') sortedVersions;

@computed('sortedVersions')
get smallSortedVersions() {
return this.sortedVersions.slice(0, NUM_VERSIONS);
}

@gt('sortedVersions.length', NUM_VERSIONS) hasMoreVersions;
}
76 changes: 76 additions & 0 deletions app/components/crate-sidebar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.authorship {
.top, .bottom {
display: flex;
flex-wrap: wrap;

> * { margin-right: 1em; }
}

.top > * { flex: 1 }

@media only screen and (min-width: 890px) {
flex: 3;
border-left: 2px solid var(--gray-border);
padding-left: 20px;

.top, .bottom {
flex-direction: column;
}

ul {
padding-left: 20px;
}
}

@media only screen and (max-width: 480px) {
.top, .bottom {
flex-direction: column;
}
}
}

.last-update,
.crate-size {
composes: small from '../styles/shared/typography.module.css';
line-height: 25px;
}

.date {
font-weight: bold;
margin-bottom: 40px;
}

/*
Since crate_size is a new field, older crates won't have it.
Preserve behaviour for older crates. For newer ones, keep
`Crate Size` closer to last updated.
*/
.date-with-small-margin-bot {
font-weight: bold;
margin-bottom: 20px;
}

.size {
font-weight: bold;
margin-bottom: 40px;
}

ul.owners, ul.keywords {
display: flex;
flex-wrap: wrap;
list-style: none;
padding: 0;
margin: 0;

li {
margin: 0 7px 7px 0;
}
}

.yanked {
composes: yanked from '../styles/shared/typography.module.css';
}

.more-versions-link {
composes: small from '../styles/shared/typography.module.css';
}
8 changes: 1 addition & 7 deletions app/controllers/crate/version.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { alias, gt, readOnly } from '@ember/object/computed';
import { alias, readOnly } from '@ember/object/computed';
import { inject as service } from '@ember/service';

import subDays from 'date-fns/subDays';
Expand All @@ -21,8 +21,6 @@ export default class CrateVersionController extends Controller {
@alias('model.crate') crate;
@alias('model.requestedVersion') requestedVersion;
@alias('model.version') currentVersion;
@alias('crate.keywords') keywords;
@alias('crate.categories') categories;

@computed('crate.owner_user', 'session.currentUser.id')
get isOwner() {
Expand All @@ -36,10 +34,6 @@ export default class CrateVersionController extends Controller {
return this.sortedVersions.slice(0, NUM_VERSIONS);
}

@gt('sortedVersions.length', NUM_VERSIONS) hasMoreVersions;
@gt('keywords.length', 0) anyKeywords;
@gt('categories.length', 0) anyCategories;

@computed('downloads', 'extraDownloads', 'requestedVersion')
get downloadData() {
let downloads = this.downloads;
Expand Down
80 changes: 0 additions & 80 deletions app/styles/crate/version.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,82 +113,6 @@ div.header {
}
}

.last-update,
.crate-size {
composes: small from '../shared/typography.module.css';
line-height: 25px;
}

.date {
font-weight: bold;
margin-bottom: 40px;
}

/*
Since crate_size is a new field, older crates won't have it.
Preserve behaviour for older crates. For newer ones, keep
`Crate Size` closer to last updated.
*/
.date-with-small-margin-bot {
font-weight: bold;
margin-bottom: 20px;
}

.size {
font-weight: bold;
margin-bottom: 40px;
}

.crate-info .authorship {
ul.owners, ul.keywords {
display: flex;
flex-wrap: wrap;
list-style: none;
padding: 0;
margin: 0;

li {
margin: 0 7px 7px 0;
}
}
}

.more-versions-link {
composes: small from '../shared/typography.module.css';
}

.authorship {
.top, .bottom {
display: flex;
flex-wrap: wrap;

> * { margin-right: 1em; }
}

.top > * { flex: 1 }

@media only screen and (min-width: 890px) {
flex: 3;
border-left: 2px solid var(--gray-border);
padding-left: 20px;

.top, .bottom {
flex-direction: column;
}

ul {
padding-left: 20px;
}
}

@media only screen and (max-width: 480px) {
.top, .bottom {
flex-direction: column;
}
}
}


.about {
line-height: 180%;
margin-bottom: 40px;
Expand Down Expand Up @@ -250,7 +174,3 @@ div.header {
display: none;
}
}

.yanked {
composes: yanked from '../shared/typography.module.css';
}
Loading