Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxJS deprecation fixes #17649

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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 @@ -26,110 +26,110 @@
// See COPYRIGHT and LICENSE files for more details.
//++

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

export const indicatorLocationSelector = '.loading-indicator--location';
export const indicatorBackgroundSelector = '.loading-indicator--background';

export function withLoadingIndicator<T>(indicator:LoadingIndicator, delayStopTime?:number):(source:Observable<T>) => Observable<T> {
return (source$:Observable<T>) => {
indicator.start();

return source$.pipe(
tap(
() => indicator.delayedStop(delayStopTime),
() => indicator.stop(),
() => indicator.stop(),
),
tap({
next: () => indicator.delayedStop(delayStopTime),
error: () => indicator.stop(),
complete: () => indicator.stop(),
}),
);
};
}

export function withDelayedLoadingIndicator<T>(indicator:() => LoadingIndicator):(source:Observable<T>) => Observable<T> {
return (source$:Observable<T>) => {
setTimeout(() => indicator().start());

return source$.pipe(
tap(
() => undefined,
() => indicator().stop(),
() => indicator().stop(),
),
tap({
next: () => undefined,
error: () => indicator().stop(),
complete: () => indicator().stop(),
}),
);
};
}

export class LoadingIndicator {
private indicatorTemplate =
`<div class="loading-indicator--background">
<div class="op-loading-indicator">
<div></div><div></div>
</div>
</div>
`;

constructor(public indicator:JQuery) {
}

public set promise(promise:Promise<unknown>) {
this.start();

// Keep bound method around
const stopper = () => this.delayedStop();

promise
.then(stopper)
.catch(stopper);
}

public start() {
// If we're currently having an active indicator, remove that one
this.stop();
this.indicator.prepend(this.indicatorTemplate);
}

public delayedStop(time = 25) {
setTimeout(() => this.stop(), time);
}

public stop() {
this.indicator.find('.loading-indicator--background').remove();
}
}

@Injectable({ providedIn: 'root' })
export class LoadingIndicatorService {
// Provide shortcut to the primarily used indicators
public get table() {
return this.indicator('table');
}

public get wpDetails() {
return this.indicator('wpDetails');
}

public get modal() {
return this.indicator('modal');
}

// Returns a getter function to an indicator
// in case the indicator is shown conditionally
public getter(name:string):() => LoadingIndicator {
return this.indicator.bind(this, name);
}

// Return an indicator by name or element
public indicator(indicator:string|JQuery):LoadingIndicator {
if (typeof indicator === 'string') {
indicator = this.getIndicatorAt(indicator);
}

return new LoadingIndicator(indicator);
}

private getIndicatorAt(name:string):JQuery {
return jQuery(indicatorLocationSelector).filter(`[data-indicator-name="${name}"]`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class FileLinksResourceService extends ResourceStoreService<IFileLink> {
switchMap((collection) => from(collection._embedded.elements)),
groupBy(
(fileLink) => fileLink._links.storage.href,
(fileLink) => fileLink,
{ element: (fileLink) => fileLink },
),
mergeMap((group$) => {
const seed = { storage: group$.key, fileLinks: [] as IFileLink[] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ export class IanBellService {
)
.pipe(
map((result) => result.total),
tap(
(count) => {
tap({
next: (count) => {
this.store.update({ totalUnread: count });
},
(error) => {
error: (error) => {
console.error('Failed to load notifications: %O', error);
this.store.update({ totalUnread: -1 });
},
),
}),
catchError(() => EMPTY),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ export class OpAutocompleterComponent<T extends IAutocompleteItem = IAutocomplet

return NEVER;
}),
tap(
() => this.loading$.next(false),
() => this.loading$.next(false),
),
tap({
next: () => this.loading$.next(false),
error: () => this.loading$.next(false),
}),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
.values$()
.pipe(
take(1),
tap((val) => console.log(`VAL ${val}`), (err) => console.error(`ERR ${err}`)),
tap({ next: (val) => console.log(`VAL ${val}`), error: (err) => console.error(`ERR ${err}`) }),

Check failure on line 102 in frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts#L102 <no-console>(https://eslint.org/docs/latest/rules/no-console)

Unexpected console statement.
Raw output
{"ruleId":"no-console","severity":2,"message":"Unexpected console statement.","line":102,"column":30,"nodeType":"MemberExpression","messageId":"unexpected","endLine":102,"endColumn":41}

Check failure on line 102 in frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts#L102 <@typescript-eslint/restrict-template-expressions>(https://typescript-eslint.io/rules/restrict-template-expressions)

Invalid type "HalResource | null" of template literal expression.
Raw output
{"ruleId":"@typescript-eslint/restrict-template-expressions","severity":2,"message":"Invalid type \"HalResource | null\" of template literal expression.","line":102,"column":49,"nodeType":"Identifier","messageId":"invalidType","endLine":102,"endColumn":52}
);
}

Expand Down
Loading