Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/xh/toolbox into BR_Chart…
Browse files Browse the repository at this point in the history
…Debugging
  • Loading branch information
febbraiod committed Oct 15, 2024
2 parents 56f49ee + 451203e commit 4ef6d4a
Show file tree
Hide file tree
Showing 7 changed files with 901 additions and 994 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {HoistModel, managed, XH} from '@xh/hoist/core';
import {GridModel, ExcelFormat, boolCheckCol, localDateCol} from '@xh/hoist/cmp/grid';
import {FilterChooserModel} from '@xh/hoist/cmp/filter';
import {bindable, makeObservable} from '@xh/hoist/mobx';
import {boolCheckCol, ExcelFormat, GridModel, localDateCol} from '@xh/hoist/cmp/grid';
import {HoistModel, managed, XH} from '@xh/hoist/core';
import {CompoundFilter, FieldFilter} from '@xh/hoist/data';
import {fmtNumberTooltip, millionsRenderer, numberRenderer} from '@xh/hoist/format';
import {bindable, makeObservable} from '@xh/hoist/mobx';

export class StoreColumnFilterPanelModel extends HoistModel {
@bindable.ref filterJson: string = JSON.stringify(null);
Expand All @@ -19,7 +20,7 @@ export class StoreColumnFilterPanelModel extends HoistModel {

// Update filter JSON
this.addReaction({
track: () => this.gridModel.filterModel.filter,
track: () => this.gridModel.filterModel.filter as FieldFilter | CompoundFilter,
run: filter => {
this.filterJson = JSON.stringify(filter?.toJSON() ?? null, undefined, 2);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {HoistModel, managed, XH} from '@xh/hoist/core';
import {Cube, View} from '@xh/hoist/data';
import {ColumnSpec, GridModel, TreeStyle} from '@xh/hoist/cmp/grid';
import {FilterChooserModel} from '@xh/hoist/cmp/filter';
import {ColumnSpec, GridModel, TreeStyle} from '@xh/hoist/cmp/grid';
import {GroupingChooserModel} from '@xh/hoist/cmp/grouping';
import {observable, makeObservable, comparer} from '@xh/hoist/mobx';
import {HoistModel, managed, XH} from '@xh/hoist/core';
import {CompoundFilter, Cube, FieldFilter, View} from '@xh/hoist/data';
import {numberRenderer} from '@xh/hoist/format';
import {comparer, makeObservable, observable} from '@xh/hoist/mobx';

export class ViewColumnFilterPanelModel extends HoistModel {
@observable.ref filterJson: string = JSON.stringify(null);
Expand Down Expand Up @@ -35,7 +35,7 @@ export class ViewColumnFilterPanelModel extends HoistModel {

// Update filter JSON
this.addReaction({
track: () => this.query.filter,
track: () => this.query.filter as FieldFilter | CompoundFilter,
run: filter => {
this.filterJson = JSON.stringify(filter?.toJSON() ?? null, undefined, 2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GridScrollingModel extends HoistModel {
super();
makeObservable(this);
this.addReaction({
track: () => [this.rowData, this.columnDefs, this.isColVirtualizationEnabled],
track: () => [this.rowData, this.columnDefs, this.isColVirtualizationEnabled] as const,
run: ([data]) => {
XH.safeDestroy(this.gridModel);
this.gridModel = this.createGridModel();
Expand Down
42 changes: 34 additions & 8 deletions client-app/src/core/svc/GitHubService.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
import {HoistService, PlainObject, XH} from '@xh/hoist/core';
import {HoistService, LoadSpec, XH} from '@xh/hoist/core';
import {Icon} from '@xh/hoist/icon';
import {computed, observable, makeObservable, runInAction} from '@xh/hoist/mobx';
import {computed, makeObservable, observable, runInAction} from '@xh/hoist/mobx';
import {LocalDate} from '@xh/hoist/utils/datetime';
import {forOwn, sortBy} from 'lodash';

// TODO - auto-refresh with app, do so efficiently, only replacing local data when new commits.
export interface RepoCommitHistory {
repo: string;
lastCommitTimestamp: string;
firstLoaded: number;
lastUpdated: number;
commits: Commit[];
}

export interface Commit {
id: string;
repo: string;
abbreviatedOid: string;
author: {email: string; name: string};
authorEmail: string;
authorName: string;
committedDate: Date;
committedDay: LocalDate;
isRelease: boolean;
messageHeadline: string;
messageBody: string;
changeFiles: number;
additions: number;
deletions: number;
url: string;
}

export class GitHubService extends HoistService {
static instance: GitHubService;

/** Loaded commits histories, keyed by repoName. */
@observable.ref commitHistories: PlainObject = {};
@observable.ref commitHistories: Record<string, RepoCommitHistory> = {};

/** Loaded array of commits across all repositories. */
@computed
get allCommits() {
get allCommits(): Commit[] {
const ret = [];
forOwn(this.commitHistories, v => ret.push(...v.commits));
return sortBy(ret, it => -it.committedDate);
Expand All @@ -26,18 +51,19 @@ export class GitHubService extends HoistService {

override async initAsync() {
// Subscribe to websocket based updates so we refresh and pick up new commits immediately.
XH.webSocketService.subscribe('gitHubUpdate', () => this.loadAsync());
XH.webSocketService.subscribe('gitHubUpdate', () => this.autoRefreshAsync());

// Note we do not await this - we don't want the app load to block here.
this.loadAsync();
}

override async doLoadAsync() {
override async doLoadAsync(loadSpec: LoadSpec) {
try {
const priorCommitCount = this.allCommits.length,
commitHistories = await XH.fetchJson({
url: 'gitHub/allCommits',
track: 'Loaded GitHub commit history'
track: 'Loaded GitHub commit history',
loadSpec
});

forOwn(commitHistories, v => {
Expand Down
4 changes: 2 additions & 2 deletions client-app/src/desktop/AppModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TabContainerModel} from '@xh/hoist/cmp/tab';
import {managed, XH} from '@xh/hoist/core';
import {LoadSpec, managed, XH} from '@xh/hoist/core';
import {
autoRefreshAppOption,
sizingModeAppOption,
Expand Down Expand Up @@ -59,7 +59,7 @@ export class AppModel extends BaseAppModel {
});
}

override async doLoadAsync(loadSpec) {
override async doLoadAsync(loadSpec: LoadSpec) {
await XH.gitHubService.loadAsync(loadSpec);
}

Expand Down
8 changes: 4 additions & 4 deletions client-app/src/desktop/tabs/grids/AgGridViewModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HoistModel, XH} from '@xh/hoist/core';
import {HoistModel, LoadSpec, XH} from '@xh/hoist/core';
import {AgGridModel} from '@xh/hoist/cmp/ag-grid';
import {observable, makeObservable, runInAction} from '@xh/hoist/mobx';
import {fmtMillions, fmtNumber} from '@xh/hoist/format';
Expand Down Expand Up @@ -74,16 +74,16 @@ export class AgGridViewModel extends HoistModel {
constructor() {
super();
makeObservable(this);
const {agGridModel} = this;

this.addReaction({
track: () => [this.data, agGridModel.agApi],
track: () => [this.data, this.agGridModel.agApi] as const,
run: ([data, api]) => {
if (api) api.updateGridOptions({rowData: data});
}
});
}

override async doLoadAsync(loadSpec) {
override async doLoadAsync(loadSpec: LoadSpec) {
const data = await XH.portfolioService.getPricedRawPositionsAsync({loadSpec});
runInAction(() => (this.data = data));
}
Expand Down
Loading

0 comments on commit 4ef6d4a

Please sign in to comment.