Skip to content

Commit

Permalink
improves handling for manual config reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Peter committed Aug 29, 2024
1 parent 6229847 commit ae08bda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ReminderStatus,
ReminderType,
REMINDER_DRAWER_OPEN_CLASS,
REMINDER_LOCAL_STORAGE_DEFAULT_CONFIG,
REMINDER_MAIN_HEADER_CLASS,
REMINDER_TYPE_FRAGMENT,
} from '../../reminder.model';
Expand Down Expand Up @@ -161,11 +162,12 @@ export class ReminderDrawerComponent implements OnDestroy {
this.reminderService.config$
.pipe(filter((config) => !isEqual(config, this.config)))
.subscribe((config) => {
this.config = config;
// fallback in case of corrupted config
this.config = { ...REMINDER_LOCAL_STORAGE_DEFAULT_CONFIG, ...config };
this.setTypeFilter(
config.filter && has(config.filter, REMINDER_TYPE_FRAGMENT)
has(this.config.filter, REMINDER_TYPE_FRAGMENT)
? config.filter[REMINDER_TYPE_FRAGMENT]
: '',
: null,
false
);
})
Expand Down
5 changes: 5 additions & 0 deletions src/app/reminder-plugin/reminder.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const REMINDER_TENENAT_OPTION_CATEGORY: ITenantOption['category'] = 'c8y.
export const REMINDER_TENENAT_OPTION_TYPE_KEY: ITenantOption['key'] = 'types';
export const REMINDER_LOCAL_STORAGE_FILTER = 'c8y_rpFilter';
export const REMINDER_LOCAL_STORAGE_CONFIG = 'c8y_rpConfig';
export const REMINDER_LOCAL_STORAGE_DEFAULT_CONFIG = {
toast: false,
browser: false,
filter: { reminderType: '' },
};

export interface Reminder extends IEvent {
status: ReminderStatus;
Expand Down
18 changes: 13 additions & 5 deletions src/app/reminder-plugin/services/reminder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ import {
EventService,
IEvent,
IResult,
TenantOptionsService
TenantOptionsService,
} from '@c8y/client';
import {
AlertService,
EventRealtimeService,
RealtimeMessage
RealtimeMessage,
} from '@c8y/ngx-components';
import { TranslateService } from '@ngx-translate/core';
import { cloneDeep, filter as _filter, has, isEqual, orderBy, sortBy } from 'lodash';
import {
cloneDeep,
filter as _filter,
has,
isEqual,
orderBy,
sortBy,
} from 'lodash';
import moment from 'moment';
import { BehaviorSubject, Subscription } from 'rxjs';
import { filter, map } from 'rxjs/operators';
Expand All @@ -26,9 +33,10 @@ import {
ReminderType,
REMINDER_INITIAL_QUERY_SIZE,
REMINDER_LOCAL_STORAGE_CONFIG,
REMINDER_LOCAL_STORAGE_DEFAULT_CONFIG,
REMINDER_TENENAT_OPTION_CATEGORY,
REMINDER_TENENAT_OPTION_TYPE_KEY,
REMINDER_TYPE
REMINDER_TYPE,
} from '../reminder.model';
import { ActiveTabService } from './active-tab.service';
import { DomService } from './dom.service';
Expand Down Expand Up @@ -386,7 +394,7 @@ export class ReminderService {
private loadConfig(): void {
this._config = this.localStorageService.getOrDefault<ReminderConfig>(
REMINDER_LOCAL_STORAGE_CONFIG,
{ toast: false, browser: false, filter: null }
REMINDER_LOCAL_STORAGE_DEFAULT_CONFIG
);
this.config$.next(this._config);
}
Expand Down

0 comments on commit ae08bda

Please sign in to comment.