-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 scope picker component (#2646)
* feat: 🎸 scope picker component --------- Co-authored-by: lisbet-alvarez <[email protected]> Co-authored-by: Zhihe Li <[email protected]>
- Loading branch information
1 parent
f941179
commit 00c9381
Showing
10 changed files
with
791 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{{! | ||
Copyright (c) HashiCorp, Inc. | ||
SPDX-License-Identifier: BUSL-1.1 | ||
}} | ||
|
||
<Hds::Dropdown | ||
@enableCollisionDetection={{true}} | ||
@matchToggleWidth={{true}} | ||
{{! HDS provided class to automatically fade in/out }} | ||
class='hds-side-nav-hide-when-minimized scope-picker' | ||
as |D| | ||
> | ||
{{#let this.currentScope as |scope|}} | ||
<D.ToggleButton | ||
@text={{scope.name}} | ||
@icon={{scope.icon}} | ||
class='scope-picker__toggle-button' | ||
/> | ||
{{/let}} | ||
|
||
<D.Checkmark | ||
@icon='globe' | ||
@route='scopes.scope' | ||
@model='global' | ||
@selected={{this.scope.org.isGlobal}} | ||
> | ||
{{t 'titles.global'}} | ||
</D.Checkmark> | ||
|
||
{{#if this.scope.orgsList}} | ||
<D.Separator /> | ||
|
||
<D.Title @text={{t 'resources.org.title_plural'}} /> | ||
{{/if}} | ||
|
||
{{#each this.truncatedOrgsList as |org|}} | ||
<D.Checkmark | ||
@icon='org' | ||
@route='scopes.scope' | ||
@model={{org.id}} | ||
@selected={{and (eq this.scope.org.id org.id) (not this.scope.project)}} | ||
data-test-scope-picker-org-item | ||
> | ||
{{org.displayName}} | ||
</D.Checkmark> | ||
{{/each}} | ||
|
||
{{#if (gt this.scope.orgsList.length 5)}} | ||
<D.Description | ||
@text={{t 'descriptions.and-more'}} | ||
data-test-scope-picker-org-and-more-text | ||
/> | ||
|
||
<D.Interactive | ||
@route='scopes.scope.scopes' | ||
@model='global' | ||
data-test-scope-picker-org-count | ||
>{{t | ||
'descriptions.view-all-orgs' | ||
total=this.scope.orgsList.length | ||
}}</D.Interactive> | ||
{{/if}} | ||
|
||
{{! All project scopes in org are only loaded when current scope is of project type. }} | ||
{{#if this.scope.project}} | ||
<D.Title @text={{t 'resources.project.title_plural'}} class='indentation' /> | ||
|
||
{{#each this.truncatedProjectsList as |project|}} | ||
<D.Checkmark | ||
@icon='grid' | ||
@route='scopes.scope' | ||
@model={{project.id}} | ||
@selected={{eq this.scope.project.id project.id}} | ||
class='indentation' | ||
data-test-scope-picker-project-item | ||
> | ||
{{project.displayName}} | ||
</D.Checkmark> | ||
{{/each}} | ||
|
||
{{#if (gt this.scope.projectsList.length 5)}} | ||
<D.Description | ||
@text={{t 'descriptions.and-more'}} | ||
class='indentation' | ||
data-test-scope-picker-project-and-more-text | ||
/> | ||
|
||
<D.Interactive | ||
@route='scopes.scope.scopes' | ||
@model={{this.scope.org.id}} | ||
class='indentation' | ||
data-test-scope-picker-project-count | ||
>{{t | ||
'descriptions.view-all-projects' | ||
total=this.scope.projectsList.length | ||
}}</D.Interactive> | ||
{{/if}} | ||
{{/if}} | ||
</Hds::Dropdown> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { inject as service } from '@ember/service'; | ||
import orderBy from 'lodash/orderBy'; | ||
|
||
export default class ScopePickerIndexComponent extends Component { | ||
// =services | ||
|
||
@service intl; | ||
@service scope; | ||
@service session; | ||
|
||
// =attributes | ||
|
||
/** | ||
* Returns display name and icon for current scope. | ||
* @type {object} | ||
*/ | ||
get currentScope() { | ||
if (this.scope.project) { | ||
return { name: this.scope.project.displayName, icon: 'grid' }; | ||
} else if (this.scope.org.isOrg) { | ||
return { name: this.scope.org.displayName, icon: 'org' }; | ||
} else { | ||
return { name: this.intl.t('titles.global'), icon: 'globe' }; | ||
} | ||
} | ||
|
||
/** | ||
* Returns first five orgs ordered by most recently updated. | ||
* @type {[ScopeModel]} | ||
*/ | ||
get truncatedOrgsList() { | ||
return orderBy(this.scope.orgsList, 'updated_time', 'desc').slice(0, 5); | ||
} | ||
|
||
/** | ||
* Returns first five projects ordered by most recently updated. | ||
* @type {[ScopeModel]} | ||
*/ | ||
get truncatedProjectsList() { | ||
return orderBy(this.scope.projectsList, 'updated_time', 'desc').slice(0, 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.