diff --git a/src/core/features/search/components/global-search-result/global-search-result.html b/src/core/features/search/components/global-search-result/global-search-result.html index 2e6304296..46c186d82 100644 --- a/src/core/features/search/components/global-search-result/global-search-result.html +++ b/src/core/features/search/components/global-search-result/global-search-result.html @@ -11,14 +11,14 @@ -
-
+
+
- +
-
+
- {{ 'core.search.resultby' | translate: { $a: result.context.userName } }} + {{ 'core.search.resultby' | translate: { $a: renderedContext.userName } }}
diff --git a/src/core/features/search/components/global-search-result/global-search-result.ts b/src/core/features/search/components/global-search-result/global-search-result.ts index 8b952b009..437dc3b72 100644 --- a/src/core/features/search/components/global-search-result/global-search-result.ts +++ b/src/core/features/search/components/global-search-result/global-search-result.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component, Input, Output, EventEmitter, OnChanges } from '@angular/core'; -import { CoreSearchGlobalSearchResult } from '@features/search/services/global-search'; +import { CoreSearchGlobalSearchResult, CoreSearchGlobalSearchResultContext } from '@features/search/services/global-search'; @Component({ selector: 'core-search-global-search-result', @@ -23,6 +23,9 @@ import { CoreSearchGlobalSearchResult } from '@features/search/services/global-s export class CoreSearchGlobalSearchResultComponent implements OnChanges { @Input() result!: CoreSearchGlobalSearchResult; + @Input() showCourse?: boolean; + + renderedContext: CoreSearchGlobalSearchResultContext | null = null; renderedIcon: string | null = null; @Output() onClick = new EventEmitter(); @@ -31,9 +34,25 @@ export class CoreSearchGlobalSearchResultComponent implements OnChanges { * @inheritdoc */ ngOnChanges(): void { + this.renderedContext = this.computeRenderedContext(); this.renderedIcon = this.computeRenderedIcon(); } + /** + * Calculate the value of the context to render. + * + * @returns Rendered context. + */ + private computeRenderedContext(): CoreSearchGlobalSearchResultContext | null { + const context = this.result.context ?? {}; + + if (this.showCourse === false) { + delete context.courseName; + } + + return Object.keys(context).length > 0 ? context : null; + } + /** * Calculate the value of the icon to render. * diff --git a/src/core/features/search/stories/global-search-result.stories.ts b/src/core/features/search/stories/global-search-result.stories.ts index 125f4666b..8bc43c2bd 100644 --- a/src/core/features/search/stories/global-search-result.stories.ts +++ b/src/core/features/search/stories/global-search-result.stories.ts @@ -37,6 +37,7 @@ interface Args { module: 'forum-activity' | 'forum-post' | 'assign' | 'none'; courseContext: boolean; userContext: boolean; + showCourse: boolean; } export default > { @@ -79,6 +80,7 @@ export default > { module: 'none', courseContext: false, userContext: false, + showCourse: true, }, parameters: { design: { @@ -88,7 +90,7 @@ export default > { }, }; -const Template = story(({ image, courseContext, userContext, module, ...args }) => { +const Template = story(({ image, courseContext, userContext, module, showCourse, ...args }) => { const result: CoreSearchGlobalSearchResult = { ...args, id: 1, @@ -126,7 +128,7 @@ const Template = story(({ image, courseContext, userContext, module, ...ar return { component: CoreSearchGlobalSearchResultComponent, - props: { result }, + props: { result, showCourse }, }; });