Skip to content

Commit

Permalink
Move accessService logic to share-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Oct 3, 2023
1 parent 555c44d commit 5655dfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 11 additions & 1 deletion app/adapters/share-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import config from 'ember-get-config';
import config from 'ember-osf-web/config/environment';

const osfUrl = config.OSF.url;

export default class ShareAdapter extends JSONAPIAdapter {
host = config.OSF.shareBaseUrl.replace(/\/$/, ''); // Remove trailing slash to avoid // in URLs
namespace = 'api/v3';

queryRecord(store: any, type: any, query: any) {
// check if we aren't serving locally, otherwise add accessService query param to card/value searches
if (['index-card-search', 'index-value-search'].includes(type.modelName) && !osfUrl.includes('localhost')) {
query.cardSearchFilter['accessService'] = osfUrl;
}
return super.queryRecord(store, type, query);
}
}
6 changes: 0 additions & 6 deletions lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Store from '@ember-data/store';
import { action } from '@ember/object';
import Media from 'ember-responsive';

import config from 'ember-osf-web/config/environment';
import { ShareMoreThanTenThousand } from 'ember-osf-web/models/index-card-search';
import SearchResultModel from 'ember-osf-web/models/search-result';
import ProviderModel from 'ember-osf-web/models/provider';
Expand Down Expand Up @@ -67,7 +66,6 @@ interface SearchArgs {
activeFilters: Filter[];
}

const osfURL = config.OSF.url;
const searchDebounceTime = 100;

export default class SearchPage extends Component<SearchArgs> {
Expand Down Expand Up @@ -221,10 +219,6 @@ export default class SearchPage extends Component<SearchArgs> {
resourceTypeFilter = Object.values(ResourceTypeFilterValue).join(',');
}
filterQueryObject['resourceType'] = resourceTypeFilter;
// Add the accessService if we are not serving locally
if (!osfURL.includes('localhost')) {
filterQueryObject['accessService'] = osfURL; // Only fetch items from the current OSF environment
}
filterQueryObject = { ...filterQueryObject, ...this.args.defaultQueryOptions };
this.filterQueryObject = filterQueryObject;
const searchResult = await this.store.queryRecord('index-card-search', {
Expand Down

0 comments on commit 5655dfb

Please sign in to comment.