Skip to content

Commit

Permalink
Address links to search page scattered around OSF (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda authored Aug 17, 2023
1 parent 8d33501 commit ea5ca11
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/dashboard/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<OsfLink
data-analytics-name='noteworthy_search'
local-class='btn btn-default'
@href='/search/?q=*'
@route='search'
>
{{t 'dashboard.noteworthy.search_more'}}
</OsfLink>
Expand Down
7 changes: 3 additions & 4 deletions app/home/-components/hero-banner/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { tagName } from '@ember-decorators/component';
import Component from '@ember/component';
import { action } from '@ember/object';
import { alias } from '@ember/object/computed';
import RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';
import { camelize } from '@ember/string';
import Features from 'ember-feature-flags/services/features';
import config from 'ember-get-config';

import { serviceLinks } from 'ember-osf-web/const/service-links';

import { layout } from 'ember-osf-web/decorators/component';

import styles from './styles';
Expand All @@ -20,13 +19,13 @@ const { featureFlagNames: { ABTesting } } = config;
@tagName('')
export default class HomeHeroBanner extends Component {
@service features!: Features;
@service router!: RouterService;

@alias(`features.${camelize(ABTesting.homePageHeroTextVersionB)}`)
shouldShowVersionB!: boolean;

@action
search(query: string) {
const { search } = serviceLinks;
window.location.href = `${search}?q=${query}&page=1`;
this.router.transitionTo('search', { queryParams: { q: query }});
}
}
6 changes: 3 additions & 3 deletions app/search/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { tracked } from '@glimmer/tracking';
import { OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';

export default class SearchController extends Controller {
@tracked cardSearchText?: string = '';
@tracked q?: string = '';
@tracked sort?: string = '-relevance';
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked page?: string = '';

queryParams = ['cardSearchText', 'page', 'sort', 'resourceType'];
queryParams = ['q', 'page', 'sort', 'resourceType'];

@action
onSearch(queryOptions: OnSearchParams) {
this.cardSearchText = queryOptions.cardSearchText;
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
this.page = queryOptions.page;
Expand Down
2 changes: 1 addition & 1 deletion app/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<SearchPage
@route='search'
@cardSearchText={{this.cardSearchText}}
@cardSearchText={{this.q}}
@queryParams={{this.queryParams}}
@onSearch={{action this.onSearch}}
@showResourceTypeFilter={{true}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { tagName } from '@ember-decorators/component';
import Component from '@ember/component';
import { action, computed } from '@ember/object';
import { alias, and } from '@ember/object/computed';
import RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';
import { waitFor } from '@ember/test-waiters';
import { task } from 'ember-concurrency';
import config from 'ember-get-config';
import Intl from 'ember-intl/services/intl';
import Toast from 'ember-toastr/services/toast';

import { layout } from 'ember-osf-web/decorators/component';
import Registration from 'ember-osf-web/models/registration';
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception';
import pathJoin from 'ember-osf-web/utils/path-join';

import template from './template';

Expand All @@ -25,15 +24,10 @@ export interface TagsManager {
registration: Registration;
}

const {
OSF: {
url: baseUrl,
},
} = config;

@tagName('')
@layout(template)
export default class TagsManagerComponent extends Component {
@service router!: RouterService;
// required
registration!: Registration;

Expand Down Expand Up @@ -95,7 +89,7 @@ export default class TagsManagerComponent extends Component {

@action
clickTag(tag: string): void {
window.location.assign(`${pathJoin(baseUrl, 'search')}?q=(tags:"${encodeURIComponent(tag)}")`);
this.router.transitionTo('search', { queryParams: { q: `${encodeURIComponent(tag)}` } });
}

@action
Expand Down
9 changes: 4 additions & 5 deletions lib/osf-components/addon/components/tags-widget/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ import { attribute } from '@ember-decorators/component';
import Component from '@ember/component';
import { assert } from '@ember/debug';
import { action } from '@ember/object';
import RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';
import config from 'ember-get-config';

import { layout } from 'ember-osf-web/decorators/component';
import OsfModel from 'ember-osf-web/models/osf-model';
import Analytics from 'ember-osf-web/services/analytics';
import pathJoin from 'ember-osf-web/utils/path-join';

import styles from './styles';
import template from './template';

const { OSF: { url: baseUrl } } = config;

interface Taggable extends OsfModel {
tags: string[];
}

@layout(template, styles)
export default class TagsWidget extends Component.extend({ styles }) {
@service router!: RouterService;

// required arguments
taggable!: Taggable;

Expand Down Expand Up @@ -64,7 +63,7 @@ export default class TagsWidget extends Component.extend({ styles }) {

@action
_clickTag(tag: string): void {
window.location.assign(`${pathJoin(baseUrl, 'search')}?q=(tags:"${encodeURIComponent(tag)}")`);
this.router.transitionTo('search', { queryParams: { q: `${encodeURIComponent(tag)}` } });
}

_onChange() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { tagName } from '@ember-decorators/component';
import Component from '@ember/component';
import { action, set } from '@ember/object';
import RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';
import { BufferedChangeset } from 'ember-changeset/types';
import config from 'ember-get-config';

import { layout } from 'ember-osf-web/decorators/component';
import DraftRegistrationModel from 'ember-osf-web/models/draft-registration';
import pathJoin from 'ember-osf-web/utils/path-join';
import { TagsManager } from 'osf-components/components/editable-field/tags-manager/component';

import template from './template';

const {
OSF: { url: baseUrl },
} = config;

export type MetadataTagsManager = Pick<TagsManager, 'addTag' | 'removeTag' | 'clickTag' | 'tags'>;

@tagName('')
@layout(template)
export default class MetadataTagsManagerComponent extends Component {
@service router!: RouterService;
// required
changeset!: BufferedChangeset;
valuePath!: string;
Expand Down Expand Up @@ -58,6 +55,6 @@ export default class MetadataTagsManagerComponent extends Component {

@action
clickTag(tag: string): void {
window.location.assign(`${pathJoin(baseUrl, 'search')}?q=(tags:"${encodeURIComponent(tag)}")`);
this.router.transitionTo('search', { queryParams: { q: `${encodeURIComponent(tag)}` } });
}
}
2 changes: 1 addition & 1 deletion translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ node_navbar:
settings: Settings
comments: Comments
status:
welcome_message: '<h1>Welcome to OSF!</h1><p>Visit our <a href="https://help.osf.io/" target="_blank" rel="noreferrer">Guides</a> to learn about creating a project, or get inspiration from <a href="https://osf.io/explore/activity/#popularPublicProjects">popular public projects</a>.</p>'
welcome_message: '<h1>Welcome to OSF!</h1><p>Visit our <a href="https://help.osf.io/" target="_blank" rel="noreferrer">Guides</a> to learn about creating a project, or get inspiration from <a href="https://osf.io/search?resourceType=Project%2CProjectComponent">popular public projects</a>.</p>'
alternate_email_error: 'The email address has <b>NOT</b> been added to your account. Please log out and revisit the link in your email. Thank you.'
# remove_addon: 'Because the GitHub add-on for {extra.category} "{extra.title}" was authenticated by {extra.user}, authentication information has been deleted.'
project_deleted: 'Project has been successfully deleted.'
Expand Down

0 comments on commit ea5ca11

Please sign in to comment.