Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { ChangeDetectionStrategy, Component, model } from '@angular/core';

import { FilterChipsComponent } from '@osf/shared/components/filter-chips/filter-chips.component';
import { SearchFiltersComponent } from '@osf/shared/components/search-filters/search-filters.component';
import { DiscoverableFilter, FilterOption } from '@osf/shared/models/search/discoverable-filter.model';
import { DiscoverableFilter } from '@osf/shared/models/search/discoverable-filter.model';
import { FilterOptionRemoved } from '@osf/shared/models/search/filter-option-removed';
import { FilterOptionSelected } from '@osf/shared/models/search/filter-option-selected.model';
import { FilterOptionsSearchText } from '@osf/shared/models/search/filter-options-search-text.model';
import {
ClearFilterSearchResults,
FetchResources,
Expand Down Expand Up @@ -44,7 +47,7 @@ export class FiltersSectionComponent {

filtersVisible = model<boolean>();

onSelectedFilterOptionsChanged(event: { filter: DiscoverableFilter; filterOption: FilterOption[] }): void {
onSelectedFilterOptionsChanged(event: FilterOptionSelected): void {
this.actions.updateSelectedFilterOption(event.filter.key, event.filterOption);
this.actions.fetchResources();
}
Expand All @@ -57,15 +60,15 @@ export class FiltersSectionComponent {
this.actions.loadMoreFilterOptions(filter.key);
}

onSearchFilterOptions(event: { searchText: string; filter: DiscoverableFilter }): void {
onSearchFilterOptions(event: FilterOptionsSearchText): void {
if (event.searchText.trim()) {
this.actions.loadFilterOptionsWithSearch(event.filter.key, event.searchText);
} else {
this.actions.clearFilterSearchResults(event.filter.key);
}
}

onFilterChipRemoved(event: { filterKey: string; optionRemoved: FilterOption }): void {
onFilterChipRemoved(event: FilterOptionRemoved): void {
const updatedOptions = this.selectedFilterOptions()[event.filterKey].filter(
(option) => option.value !== event.optionRemoved.value
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Chip } from 'primeng/chip';
import { ChangeDetectionStrategy, Component, computed, input, output } from '@angular/core';

import { DiscoverableFilter, FilterOption } from '@osf/shared/models/search/discoverable-filter.model';
import { FilterOptionRemoved } from '@osf/shared/models/search/filter-option-removed';

@Component({
selector: 'osf-filter-chips',
Expand All @@ -14,7 +15,7 @@ export class FilterChipsComponent {
filterOptions = input<Record<string, FilterOption[]>>({});
filters = input.required<DiscoverableFilter[]>();

selectedOptionRemoved = output<{ filterKey: string; optionRemoved: FilterOption }>();
selectedOptionRemoved = output<FilterOptionRemoved>();

filterLabels = computed(() =>
this.filters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { ActivatedRoute, Router } from '@angular/router';
import { PreprintProviderDetails } from '@osf/features/preprints/models';
import { normalizeQuotes } from '@osf/shared/helpers/normalize-quotes';
import { DiscoverableFilter, FilterOption } from '@osf/shared/models/search/discoverable-filter.model';
import { FilterOptionRemoved } from '@osf/shared/models/search/filter-option-removed';
import { FilterOptionSelected } from '@osf/shared/models/search/filter-option-selected.model';
import { FilterOptionsSearchText } from '@osf/shared/models/search/filter-options-search-text.model';
import { SearchFiltersComponent } from '@shared/components/search-filters/search-filters.component';
import { ResourceType } from '@shared/enums/resource-type.enum';
import { TabOption } from '@shared/models/tab-option.model';
Expand Down Expand Up @@ -130,15 +133,15 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
this.actions.loadMoreFilterOptions(filter.key);
}

onSearchFilterOptions(event: { searchText: string; filter: DiscoverableFilter }): void {
onSearchFilterOptions(event: FilterOptionsSearchText): void {
if (event.searchText.trim()) {
this.actions.loadFilterOptionsWithSearch(event.filter.key, event.searchText);
} else {
this.actions.clearFilterSearchResults(event.filter.key);
}
}

onSelectedFilterOptionsChanged(event: { filter: DiscoverableFilter; filterOption: FilterOption[] }): void {
onSelectedFilterOptionsChanged(event: FilterOptionSelected): void {
this.actions.updateSelectedFilterOption(event.filter.key, event.filterOption);

const currentFilters = this.filterOptions();
Expand Down Expand Up @@ -171,7 +174,7 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
}
}

onSelectedOptionRemoved(event: { filterKey: string; optionRemoved: FilterOption }): void {
onSelectedOptionRemoved(event: FilterOptionRemoved): void {
const updatedOptions = this.filterOptions()[event.filterKey].filter(
(option) => option.value !== event.optionRemoved.value
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
FilterOperatorOption,
FilterOption,
} from '@osf/shared/models/search/discoverable-filter.model';
import { FilterOptionSelected } from '@osf/shared/models/search/filter-option-selected.model';
import { FilterOptionsSearchText } from '@osf/shared/models/search/filter-options-search-text.model';

import { GenericFilterComponent } from '../generic-filter/generic-filter.component';
import { LoadingSpinnerComponent } from '../loading-spinner/loading-spinner.component';
Expand Down Expand Up @@ -52,8 +54,8 @@ export class SearchFiltersComponent {
loadFilterOptions = output<DiscoverableFilter>();
loadMoreFilterOptions = output<DiscoverableFilter>();

filterOptionSelected = output<{ filter: DiscoverableFilter; filterOption: FilterOption[] }>();
filterOptionsSearch = output<{ filter: DiscoverableFilter; searchText: string }>();
filterOptionSelected = output<FilterOptionSelected>();
filterOptionsSearch = output<FilterOptionsSearchText>();

readonly String = String;
readonly Boolean = Boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@for (step of steps(); track $index) {
@if (currentStep() === $index + 1) {
<div class="stepper" [ngStyle]="getStepPosition(step)">
<div class="stepper" [ngStyle]="isTablet() ? step.position : step.mobilePosition">

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old method returned step.mobilePosition || {} but the new template expression passes undefined directly to ngStyle when mobilePosition is absent. Change to step.mobilePosition ?? {} and add a test covering this case since the one that verified it was deleted.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SEARCH_TUTORIAL_STEPS always defines both positions. I made position and mobilePosition required on TutorialStep, so the compiler enforces this. The ?? {} fallback is no longer needed.

<h3 class="stepper-title">{{ step.title | translate }}</h3>

<p>{{ step.description | translate }}</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { SEARCH_TUTORIAL_STEPS } from '@osf/shared/constants/search-tutorial-steps.const';
import { TutorialStep } from '@shared/models/tutorial-step.model';

import { provideOSFCore } from '@testing/osf.testing.provider';

Expand All @@ -11,13 +10,6 @@ describe('SearchHelpTutorialComponent', () => {
let component: SearchHelpTutorialComponent;
let fixture: ComponentFixture<SearchHelpTutorialComponent>;

const mockTutorialStep: TutorialStep = {
title: 'Test Step',
description: 'This is a test step',
position: { top: '10px', left: '20px' },
mobilePosition: { top: '10px', left: '20px' },
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [SearchHelpTutorialComponent],
Expand Down Expand Up @@ -102,21 +94,6 @@ describe('SearchHelpTutorialComponent', () => {
expect(component.currentStep()).toBe(0);
});

it('should return position object when step has position', () => {
const position = component.getStepPosition(mockTutorialStep);
expect(position).toEqual({ top: '10px', left: '20px' });
});

it('should return empty object when step has no position', () => {
const stepWithoutPosition: TutorialStep = {
title: 'Test Step',
description: 'This is a test step',
};

const position = component.getStepPosition(stepWithoutPosition);
expect(position).toEqual({});
});

it('should maintain currentStep state across method calls', () => {
expect(component.currentStep()).toBe(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { toSignal } from '@angular/core/rxjs-interop';

import { SEARCH_TUTORIAL_STEPS } from '@osf/shared/constants/search-tutorial-steps.const';
import { IS_MEDIUM } from '@osf/shared/helpers/breakpoints.tokens';
import { TutorialStep } from '@shared/models/tutorial-step.model';

@Component({
selector: 'osf-search-help-tutorial',
Expand Down Expand Up @@ -36,8 +35,4 @@ export class SearchHelpTutorialComponent {
this.currentStep.set(nextStepIndex);
}
}

getStepPosition(step: TutorialStep) {
return this.isTablet() ? step.position : step.mobilePosition || {};
}
}
6 changes: 6 additions & 0 deletions src/app/shared/models/search/filter-option-removed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { FilterOption } from './discoverable-filter.model';

export interface FilterOptionRemoved {
filterKey: string;
optionRemoved: FilterOption;
}
6 changes: 6 additions & 0 deletions src/app/shared/models/search/filter-option-selected.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DiscoverableFilter, FilterOption } from './discoverable-filter.model';

export interface FilterOptionSelected {
filter: DiscoverableFilter;
filterOption: FilterOption[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DiscoverableFilter } from './discoverable-filter.model';

export interface FilterOptionsSearchText {
filter: DiscoverableFilter;
searchText: string;
}
10 changes: 4 additions & 6 deletions src/app/shared/models/tutorial-step.model.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export interface TutorialStep {
title: string;
description: string;
position?: Position;
mobilePosition?: Position;
position: Position;
mobilePosition: Position;
}

interface Position {
top?: string;
left?: string;
right?: string;
bottom?: string;
top: string;
left: string;
}
Loading