Skip to content

Commit

Permalink
Merge pull request #5849 from tomachalek/last_conc_id_issues_b
Browse files Browse the repository at this point in the history
Fix handling of the 'ReloadConc' action ...
  • Loading branch information
tomachalek authored Jun 1, 2023
2 parents df75fee + 7b1f16a commit 6defc3b
Show file tree
Hide file tree
Showing 32 changed files with 382 additions and 156 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"d3": "^7.6.1",
"d3-color": "^3.1.0",
"diff": "^5.1.0",
"kombo": "^0.95.2",
"kombo": "^0.96.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
Expand Down
4 changes: 3 additions & 1 deletion public/files/js/app/navigation/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ export class History implements Kontext.IHistory {
}

setOnPopState(fn:(event:PopStateEvent)=>void):void {
window.onpopstate = fn;
window.onpopstate = (event:PopStateEvent) => {
fn(event);
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion public/files/js/app/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export abstract class PageModel implements Kontext.IURLHandler, IConcArgsHandler
const concIds = pipe(
value,
List.filter(v => v[0] === '~'),
List.map(v => v.substr(1))
List.map(v => v.substring(1))
);
if (!List.empty(concIds)) {
this.setConf<string>('concPersistenceOpId', List.head(concIds));
Expand Down
1 change: 1 addition & 0 deletions public/files/js/models/asyncTask/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Action } from 'kombo';
import * as Kontext from '../../types/kontext';



export class Actions {

static InboxToggleOverviewVisibility:Action<{
Expand Down
2 changes: 1 addition & 1 deletion public/files/js/models/coll/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class CollResultModel extends StatelessModel<CollResultModelState> {
}

private processDataReload(state:CollResultModelState):Observable<[AjaxResponse, CollServerArgs]> {
return this.suspend({}, (action, syncData) => {
return this.waitForAction({}, (action, syncData) => {
if (action.name === Actions.FormPrepareSubmitArgsDone.name) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion public/files/js/models/coll/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class CollResultsSaveModel extends StatelessModel<CollResultsSaveModelSta
}

private submit(state:CollResultsSaveModelState):void {
this.suspend({}, (action, syncData) => {
this.waitForAction({}, (action, syncData) => {
if (action.name === Actions.FormPrepareSubmitArgsDone.name) {
return null;
}
Expand Down
22 changes: 22 additions & 0 deletions public/files/js/models/concordance/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export interface PublishLineSelectionPayload {

export class Actions {

static ReadyToAddNewOperation:Action<{
lastConcId:string;
}> = {
name: 'CONCORDANCE_READY_TO_ADD_NEW_OPERATION'
};

static isReadyToAddNewOperation(a:Action):a is typeof Actions.ReadyToAddNewOperation {
return a.name === Actions.ReadyToAddNewOperation.name;
};

static AddedNewOperation:Action<{
concId:string;
data:AjaxConcResponse;
Expand Down Expand Up @@ -98,8 +108,16 @@ export class Actions {
return a.name === Actions.ChangePage.name;
}

/**
* defines a reload of an already known operation
*/
static ReloadConc:Action<{
concId:string;
arf:number;
concSize:number;
fullSize:number;
corpusIpm:number;
queryChainSize:number;
isPopState?:boolean;
viewMode?:ConcViewMode;
}> = {
Expand Down Expand Up @@ -434,6 +452,10 @@ export class Actions {
name: 'CONCORDANCE_PUBLISH_STORED_LINE_SELECTIONS'
};

static isPublishStoredLineSelections(a:Action):a is typeof Actions.PublishStoredLineSelections {
return a.name == Actions.PublishStoredLineSelections.name;
}

static DownloadSelectionOverview:Action<{
format:string;
}> = {
Expand Down
55 changes: 41 additions & 14 deletions public/files/js/models/concordance/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
this.pushHistoryState({
name: Actions.ReloadConc.name,
payload: {
concId: action.payload.data.conc_persistence_op_id
concId: action.payload.data.conc_persistence_op_id,
arf: action.payload.data.result_arf,
concSize: action.payload.data.concsize,
corpusIpm: action.payload.data.result_relative_freq,
fullSize: action.payload.data.fullsize,
queryChainSize: List.size(action.payload.data.query_overview)
}
});
Dict.forEach(
Expand Down Expand Up @@ -409,7 +414,7 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
}
forkJoin([
this.waitForAction({}, (action, syncData) => {
return action.name === Actions.PublishStoredLineSelections.name ?
return Actions.isPublishStoredLineSelections(action) ?
null : syncData;
}).pipe(
map(v => (v as typeof Actions.PublishStoredLineSelections).payload)
Expand All @@ -432,6 +437,8 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
this.state.highlightWordsStore
);

this.layoutModel.updateConcArgs({q: [action.payload.concId]});

} else {
Dict.forEach(
(_, kcAttr) => {
Expand Down Expand Up @@ -474,11 +481,16 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
concatMap(v => this.loadConcPage())

).subscribe({
next: ([concId,]) => {
next: ([resp, ]) => {
this.pushHistoryState({
name: Actions.ReloadConc.name,
payload: {
concId
concId: resp.conc_persistence_op_id,
arf: resp.result_arf,
concSize: resp.concsize,
fullSize: resp.fullsize,
corpusIpm: resp.result_relative_freq,
queryChainSize: List.size(resp.query_overview)
}
});
this.emitChange();
Expand Down Expand Up @@ -596,11 +608,16 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
state.attrViewMode = action.payload.attrVmode;
});
this.loadConcPage().subscribe({
next: ([concId,]) => {
next: ([resp,]) => {
this.pushHistoryState({
name: Actions.ReloadConc.name,
payload: {
concId
concId: resp.conc_persistence_op_id,
arf: resp.result_arf,
corpusIpm: resp.result_relative_freq,
concSize: resp.concsize,
fullSize: resp.fullsize,
queryChainSize: List.size(resp.query_overview)
}
});
this.emitChange();
Expand All @@ -622,11 +639,16 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
state.currentPage = 1;
});
this.loadConcPage().subscribe({
next: ([concId,]) => {
next: ([resp,]) => {
this.pushHistoryState({
name: Actions.ReloadConc.name,
payload: {
concId
concId: resp.conc_persistence_op_id,
arf: resp.result_arf,
corpusIpm: resp.result_relative_freq,
concSize: resp.concsize,
fullSize: resp.fullsize,
queryChainSize: List.size(resp.query_overview)
}
});
this.emitChange();
Expand Down Expand Up @@ -959,7 +981,7 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
* @param concId if non-empty then a specific concordance is loaded
* @return a 2-tuple [actual conc. ID, page num]
*/
private loadConcPage(concId?:string):Observable<[string, number]> {
private loadConcPage(concId?:string):Observable<[AjaxConcResponse, number]> {
return this.changePage('customPage', 1, concId ? `~${concId}` : undefined);
}

Expand All @@ -983,7 +1005,7 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
action:PaginationActions,
pageNumber?:number,
concId?:string
):Observable<[string, number]> {
):Observable<[AjaxConcResponse, number]> {

const pageNum:number = action === 'customPage' ?
pageNumber : this.state.pagination[action];
Expand Down Expand Up @@ -1020,7 +1042,7 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {
});
}
),
map(resp => tuple(resp.conc_persistence_op_id, pageNum))
map(resp => tuple(resp, pageNum))
);
}

Expand Down Expand Up @@ -1226,14 +1248,19 @@ export class ConcordanceModel extends StatefulModel<ConcordanceModelState> {

).pipe(
tap(
data => {
resp => {
this.changeState(state => {
this.importData(state, data);
this.importData(state, resp);
});
this.pushHistoryState({
name: Actions.ReloadConc.name,
payload: {
concId: data.conc_persistence_op_id,
concId: resp.conc_persistence_op_id,
arf: resp.result_arf,
corpusIpm: resp.result_relative_freq,
concSize: resp.concsize,
fullSize: resp.fullsize,
queryChainSize: List.size(resp.query_overview),
viewMode
}
});
Expand Down
12 changes: 12 additions & 0 deletions public/files/js/models/concordance/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ export class ConcSummaryModel extends StatelessModel<ConcSummaryModelState> {
}
);

this.addActionHandler(
Actions.ReloadConc,
(state, action) => {
state.arf = action.payload.arf;
state.concSize = action.payload.concSize;
state.fullSize = action.payload.fullSize;
state.ipm = null;
state.queryChainSize = action.payload.queryChainSize;
state.corpusIpm = action.payload.corpusIpm;
}
)

this.addActionHandler(
Actions.AddedNewOperation,
(state, action) => {
Expand Down
4 changes: 2 additions & 2 deletions public/files/js/models/concordance/ttdist/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class TextTypesDistModel extends StatefulModel<TextTypesDistModelState> {
state.blockedByAsyncConc = !action.payload.finished;
}
);
this.suspendWithTimeout(5000, {}, (action, syncData) => {
this.waitForActionWithTimeout(5000, {}, (action, syncData) => {
if (ConcActions.isConcordanceRecalculationReady(action)) {
return null;
}
Expand All @@ -113,7 +113,7 @@ export class TextTypesDistModel extends StatefulModel<TextTypesDistModelState> {
ConcActions.LoadTTDictOverview.name,
action => {
if (this.state.blocks.length === 0) {
this.suspendWithTimeout(5000, {}, (action, syncData) => {
this.waitForActionWithTimeout(5000, {}, (action, syncData) => {
if (ConcActions.isConcordanceRecalculationReady(action)) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion public/files/js/models/freqs/regular/freqCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ export class FreqChartsModel extends StatelessModel<FreqChartsModelState> {
Actions.ResultSetMinFreqVal,
null,
(state, action, dispatch) => {
this.suspendWithTimeout(
this.waitForActionWithTimeout(
5000,
{},
(action, syncData) => {
Expand Down
4 changes: 2 additions & 2 deletions public/files/js/models/freqs/regular/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class FreqResultsSaveModel extends StatefulModel<FreqResultsSaveModelStat
state.saveformat = action.payload.saveformat,
state.toLine.value = `${state.quickSaveRowLimit}`
});
this.suspend({}, (action, syncData) =>
this.waitForAction({}, (action, syncData) =>
action.name === Actions.ResultPrepareSubmitArgsDone.name ? null : syncData

).subscribe(
Expand Down Expand Up @@ -151,7 +151,7 @@ export class FreqResultsSaveModel extends StatefulModel<FreqResultsSaveModelStat

} else {
this.changeState(state => {state.formIsActive = false});
this.suspend({}, (action, syncData) => {
this.waitForAction({}, (action, syncData) => {
return action.name === Actions.ResultPrepareSubmitArgsDone.name ? null : syncData
}).subscribe(
(action) => {
Expand Down
2 changes: 1 addition & 1 deletion public/files/js/models/freqs/regular/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class FreqDataRowsModel extends StatelessModel<FreqDataRowsModelState> {
Actions.ResultSetMinFreqVal,
null,
(state, action, dispatch) => {
this.suspendWithTimeout(
this.waitForActionWithTimeout(
5000,
{},
(action, syncData) => {
Expand Down
2 changes: 1 addition & 1 deletion public/files/js/models/options/structsAttrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class CorpusViewOptionsModel extends StatelessModel<CorpusViewOptionsMode
},
(state, action, dispatch) => {
if (!state.hasLoadedData) {
this.suspendWithTimeout(20000, {}, (action , syncData) => {
this.waitForActionWithTimeout(20000, {}, (action , syncData) => {
return null;

}).pipe(
Expand Down
2 changes: 1 addition & 1 deletion public/files/js/models/pquery/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class PqueryResultModel extends StatefulModel<PqueryResultModelState> {
this.addActionHandler<typeof Actions.ResultApplyQuickFilter>(
Actions.ResultApplyQuickFilter.name,
action => {
this.suspendWithTimeout(
this.waitForActionWithTimeout(
1000,
{},
(action2, syncData) => Actions.isResultApplyQuickFilterArgsReady(action2) ? null : syncData
Expand Down
4 changes: 2 additions & 2 deletions public/files/js/models/pquery/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class PqueryResultsSaveModel extends StatefulModel<PqueryResultsSaveModel
state.saveformat = action.payload.saveformat,
state.toLine.value = `${state.quickSaveRowLimit}`
});
this.suspend({}, (action, syncData) =>
this.waitForAction({}, (action, syncData) =>
action.name === Actions.SaveFormPrepareSubmitArgsDone.name ? null : syncData

).subscribe(
Expand Down Expand Up @@ -147,7 +147,7 @@ export class PqueryResultsSaveModel extends StatefulModel<PqueryResultsSaveModel

} else {
this.changeState(state => {state.formIsActive = false});
this.suspend({}, (action, syncData) => {
this.waitForAction({}, (action, syncData) => {
return action.name === Actions.SaveFormPrepareSubmitArgsDone.name ? null : syncData
}).subscribe(
(action) => {
Expand Down
Loading

0 comments on commit 6defc3b

Please sign in to comment.