blob: 99b9870e1c7ba6cfa9085904eb5dea71f4eac48d [file] [log] [blame]
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {Observable} from 'rxjs';
import {distinctUntilChanged, map} from 'rxjs/operators';
import {Finalizable} from '../registry';
import {
NumericChangeId,
RevisionPatchSetNum,
BasePatchSetNum,
} from '../../types/common';
import {Model} from '../../models/model';
export enum GerritView {
ADMIN = 'admin',
AGREEMENTS = 'agreements',
CHANGE = 'change',
DASHBOARD = 'dashboard',
DIFF = 'diff',
DOCUMENTATION_SEARCH = 'documentation-search',
EDIT = 'edit',
GROUP = 'group',
PLUGIN_SCREEN = 'plugin-screen',
REPO = 'repo',
SEARCH = 'search',
SETTINGS = 'settings',
}
export interface RouterState {
// Note that this router model view must be updated before view model state.
view?: GerritView;
changeNum?: NumericChangeId;
patchNum?: RevisionPatchSetNum;
basePatchNum?: BasePatchSetNum;
}
export class RouterModel extends Model<RouterState> implements Finalizable {
readonly routerView$: Observable<GerritView | undefined>;
readonly routerChangeNum$: Observable<NumericChangeId | undefined>;
readonly routerPatchNum$: Observable<RevisionPatchSetNum | undefined>;
readonly routerBasePatchNum$: Observable<BasePatchSetNum | undefined>;
constructor() {
super({});
this.routerView$ = this.state$.pipe(
map(state => state.view),
distinctUntilChanged()
);
this.routerChangeNum$ = this.state$.pipe(
map(state => state.changeNum),
distinctUntilChanged()
);
this.routerPatchNum$ = this.state$.pipe(
map(state => state.patchNum),
distinctUntilChanged()
);
this.routerBasePatchNum$ = this.state$.pipe(
map(state => state.basePatchNum),
distinctUntilChanged()
);
}
}