Skip to content

Commit

Permalink
Merge branch 'develop' into search-deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda authored Oct 23, 2023
2 parents a3fb14f + 689475b commit 53e2a9d
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 43 deletions.
51 changes: 50 additions & 1 deletion app/models/index-card.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { getOwner } from '@ember/application';
import { inject as service } from '@ember/service';
import { waitFor } from '@ember/test-waiters';
import Model, { AsyncHasMany, attr, hasMany } from '@ember-data/model';
import { dropTask } from 'ember-concurrency';
import IntlService from 'ember-intl/services/intl';

import GetLocalizedPropertyHelper from 'ember-osf-web/helpers/get-localized-property';
import { getOwner } from '@ember/application';
import config from 'ember-osf-web/config/environment';
import OsfModel from 'ember-osf-web/models/osf-model';
import { tracked } from 'tracked-built-ins';
const osfUrl = config.OSF.url;

export interface LanguageText {
'@language': string;
Expand All @@ -23,10 +29,28 @@ export default class IndexCardModel extends Model {

getLocalizedString = new GetLocalizedPropertyHelper(getOwner(this));

@tracked osfModel?: OsfModel;

get resourceId() {
return this.resourceIdentifier[0];
}

get osfModelType() {
const types = this.resourceMetadata.resourceType.map( (item: any) => item['@id']);
if (types.includes('Project') || types.includes('ProjectComponent')) {
return 'node';
} else if (types.includes('Registration') || types.includes('RegistrationComponent')) {
return 'registration';
} else if (types.includes('Preprint')) {
return 'preprint';
} else if (types.includes('Person') || types.includes('Agent')) {
return 'user';
} else if(types.includes('File')) {
return 'file';
}
return null;
}

get label() {
const possibleLabelKeys = ['displayLabel', 'name', 'title'];
for (const key of possibleLabelKeys) {
Expand All @@ -44,6 +68,31 @@ export default class IndexCardModel extends Model {
}
return '';
}

@dropTask
@waitFor
async getOsfModel(options?: object) {
const identifier = this.resourceIdentifier;
if (identifier && this.osfModelType) {
const guid = this.guidFromIdentifierList(identifier);
if (guid) {
const osfModel = await this.store.findRecord(this.osfModelType, guid, options);
this.osfModel = osfModel;
}
}
}

guidFromIdentifierList() {
for (const iri of this.resourceIdentifier) {
if (iri && iri.startsWith(osfUrl)) {
const pathSegments = iri.slice(osfUrl.length).split('/').filter(Boolean);
if (pathSegments.length === 1) {
return pathSegments[0]; // one path segment; looks like osf-id
}
}
}
return null;
}
}

declare module 'ember-data/types/registries/model' {
Expand Down
6 changes: 5 additions & 1 deletion app/models/search-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ export default class SearchResultModel extends Model {
return this.resourceMetadata['@id'];
}

// returns list of affilated institutions for users
// returns list of contributors for osf objects
// returns list of affiliated institutions for osf users
get affiliatedEntities() {
if (this.resourceType === 'user') {
// return something
if (this.resourceMetadata.affiliation) {
return this.resourceMetadata.affiliation.map((item: any) =>
({ name: item.name[0]['@value'], absoluteUrl: item['@id'] }));
}
} else if (this.resourceMetadata.creator) {
return this.resourceMetadata.creator?.map((item: any) =>
({ name: item.name[0]['@value'], absoluteUrl: item['@id'] }));
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { buildValidations, validator } from 'ember-cp-validations';
import config from 'ember-osf-web/config/environment';
import { Link } from 'jsonapi-typescript';

import PreprintModel from 'ember-osf-web/models/preprint';
import SparseNodeModel from 'ember-osf-web/models/sparse-node';
import ContributorModel from './contributor';
import DraftRegistrationModel from './draft-registration';
Expand Down Expand Up @@ -114,6 +115,9 @@ export default class UserModel extends OsfModel.extend(Validations) {
@hasMany('draft-registration')
draftRegistrations!: AsyncHasMany<DraftRegistrationModel>;

@hasMany('preprint')
preprints!: AsyncHasMany<PreprintModel>;

@hasMany('institution', { inverse: 'users' })
institutions!: AsyncHasMany<InstitutionModel>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.branded-nav-wrapper {
.branded-nav {
z-index: 999;
z-index: 998;
}

:global(.navbar) {
Expand Down
2 changes: 1 addition & 1 deletion lib/osf-components/addon/components/osf-dialog/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
align-items: center;
justify-content: center;

z-index: 1100;
z-index: 999;
background-color: rgba(0, 0, 0, 0.5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class SearchPage extends Component<SearchArgs> {
}
this.filterQueryObject = filterQueryObject;
const searchResult = await this.store.queryRecord('index-card-search', {
cardSearchText,
'cardSearchText[*,creator.name,isContainedBy.creator.name]': cardSearchText,
'page[cursor]': page,
sort,
cardSearchFilter: filterQueryObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,21 @@ export default class FilterFacet extends Component<FilterFacetArgs> {
@tracked hasMoreValueOptions = false;
@tracked nextPageCursor = '';

get shouldShowTopValues() {
const { args: { property: { propertyPathKey } } } = this;
return propertyPathKey !== 'creator';
}

@action
toggleFacet() {
if (this.filterableValues.length === 0 && !taskFor(this.fetchFacetValues).lastComplete) {
taskFor(this.fetchFacetValues).perform();
if (this.shouldShowTopValues) {
if (this.filterableValues.length === 0 && !taskFor(this.fetchFacetValues).lastComplete) {
taskFor(this.fetchFacetValues).perform();
}
this.collapsed = !this.collapsed;
} else {
this.openSeeMoreModal();
}
this.collapsed = !this.collapsed;
}

@action
Expand Down Expand Up @@ -105,8 +114,14 @@ export default class FilterFacet extends Component<FilterFacetArgs> {
@waitFor
async fetchFacetValues() {
const { cardSearchText, cardSearchFilter, property } = this.args;
const { page, sort, filterString } = this;

const { page, sort, filterString, shouldShowTopValues } = this;
if (!shouldShowTopValues && !filterString.trim()) {
this.filterableValues = [];
this.modalValueOptions = [];
this.hasMoreValueOptions = false;
this.nextPageCursor = '';
return; // skip fetching
}
const valueSearch = await this.store.queryRecord('index-value-search', {
cardSearchText,
cardSearchFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@
@search={{perform this.debouncedValueSearch}}
@onChange={{action this.updateSelectedProperty}}
@afterOptionsComponent={{component 'search-page/filter-facet/after-options' fetchValues=(perform this.loadMoreValues) hasMoreValues=this.hasMoreValueOptions}}
@selectedItemComponent={{component 'search-page/filter-facet/value-option' isSelected=true}}
as |property|
>
<span>{{property.indexCard.label}} ({{property.cardSearchResultCount}})</span>
<SearchPage::FilterFacet::ValueOption @option={{property}} />
</PowerSelect>
</dialog.main>
<dialog.footer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Component from '@glimmer/component';

import SearchResultModel from 'ember-osf-web/models/search-result';

interface ValueOptionArgs {
option: SearchResultModel;
isSelected?: Boolean;
}

export default class ValueOption extends Component<ValueOptionArgs> {
get additionalDetail() {
const { affiliation: affiliatedEntities = [] } = this.args.option.resourceMetadata;
return affiliatedEntities.flatMap(
(entity: any) => entity.name?.map((name: any) => name['@value']),
).filter(Boolean).join(', ');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.SelectedValueOption {
margin-left: 0.5em;
}

.AdditionalDetail {
margin-left: 0.5em;
font-size: 0.8em;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div local-class={{if @isSelected 'SelectedValueOption'}}>
<div>{{@option.indexCard.label}} ({{@option.cardSearchResultCount}})</div>
{{#if this.additionalDetail}}
<div local-class='AdditionalDetail'>{{this.additionalDetail}}</div>
{{/if}}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ as |layout|>
<SearchResultCard @result={{item}} />
{{else}}
<div local-class='no-results'>
<p>{{t 'search.no-results'}}</p>
<p data-test-search-page-no-results>{{t 'search.no-results'}}</p>
</div>
{{/each}}
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Store from '@ember-data/store';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import SearchResultModel from 'ember-osf-web/models/search-result';
import { inject as service } from '@ember/service';
import Intl from 'ember-intl/services/intl';

import SearchResultModel from 'ember-osf-web/models/search-result';
import UserModel from 'ember-osf-web/models/user';

interface Args {
result: SearchResultModel;
}

export default class SearchResultCard extends Component<Args> {
@service intl!: Intl;
@service store!: Store;

@tracked isOpenSecondaryMetadata = false;
@tracked osfUser?: UserModel;

@action
toggleSecondaryMetadata() {
Expand All @@ -22,10 +28,23 @@ export default class SearchResultCard extends Component<Args> {
return this.intl.t(`osf-components.search-result-card.${this.args.result.resourceType}`);
}

// not sure if this is the best way, as there was a resourceType of "unknown" out in the wild
get secondaryMetadataComponent() {
const { resourceType } = this.args.result;

return `search-result-card/${resourceType.replace('_component', '')}-secondary-metadata`;
switch (resourceType) {
case 'project':
case 'project_component':
return 'search-result-card/project-secondary-metadata';
case 'registration':
case 'registration_component':
return 'search-result-card/registration-secondary-metadata';
case 'preprint':
return 'search-result-card/preprint-secondary-metadata';
case 'file':
return 'search-result-card/file-secondary-metadata';
case 'user':
return 'search-result-card/user-secondary-metadata';
default:
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,3 @@
</dd>
{{/if}}
</dl>

Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
</InlineList>
</dd>
{{/if}}
</dl>
</dl>
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@
padding-top: 10px;
}

dt,
dd {
dt {
margin: 15px 0 0 5px;
}

dd {
margin-left: 5px;
}
}
42 changes: 20 additions & 22 deletions lib/osf-components/addon/components/search-result-card/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
<div local-class='type-label'>
{{this.cardTypeLabel}}
</div>
{{#if (not-eq @result.resourceType 'user')}}
<Button
{{on 'click' this.toggleSecondaryMetadata}}
aria-label={{if this.isOpenSecondaryMetadata
(t 'osf-components.search-result-card.hide_additional_metadata')
(t 'osf-components.search-result-card.show_additional_metadata')
}}
aria-controls={{secondaryMetadataPanelId}}
aria-expanded={{this.isOpenSecondaryMetadata}}
>
{{#if this.isOpenSecondaryMetadata}}
<FaIcon
@icon={{'angle-up'}}
/>
{{else}}
<FaIcon
@icon={{'angle-down'}}
/>
{{/if}}
</Button>
{{/if}}
<Button
{{on 'click' this.toggleSecondaryMetadata}}
aria-label={{if this.isOpenSecondaryMetadata
(t 'osf-components.search-result-card.hide_additional_metadata')
(t 'osf-components.search-result-card.show_additional_metadata')
}}
aria-controls={{secondaryMetadataPanelId}}
aria-expanded={{this.isOpenSecondaryMetadata}}
>
{{#if this.isOpenSecondaryMetadata}}
<FaIcon
@icon={{'angle-up'}}
/>
{{else}}
<FaIcon
@icon={{'angle-down'}}
/>
{{/if}}
</Button>
</div>
<h4>
<a data-test-search-result-card-title href={{@result.absoluteUrl}} target='_blank' rel='noopener noreferrer'> {{@result.displayTitle}} </a>
Expand Down Expand Up @@ -104,4 +102,4 @@
</panel.body>
</CpPanel>
{{/let}}
</div>
</div>
Loading

0 comments on commit 53e2a9d

Please sign in to comment.