react-hook-core 0.1.0 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/components.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import {RouteComponentProps} from 'react-router';
3
3
  import {clone, diff, makeDiff} from 'reflectx';
4
- import {addParametersIntoUrl, append, buildMessage, changePage, changePageSize, formatResultsByComponent, getFieldsFromForm, getModel, handleAppend, handleSortEvent, initFilter, mergeFilter as mergeFilter2, more, reset, Searchable, showPaging, validate} from 'search-core';
5
- import {BaseDiffState, createDiffStatus, createEditStatus, DiffApprService, DiffParameter, DiffState, DiffStatusConfig, hideLoading, showLoading} from './core';
6
- import {Attributes, buildId, EditStatusConfig, error, ErrorMessage, Filter, getCurrencyCode, getModelName as getModelName2, HistoryProps, initForm, LoadingService, Locale, message, messageByHttpStatus, ModelHistoryProps, ModelProps, removePhoneFormat, ResourceService, SearchParameter, SearchResult, SearchService, SearchState, StringMap, UIService, ViewParameter, ViewService} from './core';
4
+ import {addParametersIntoUrl, append, buildMessage, changePage, changePageSize, formatResults, getFieldsFromForm, getModel, handleAppend, handleSortEvent, initFilter, mergeFilter as mergeFilter2, more, reset, Searchable, showPaging, validate} from 'search-core';
5
+ import {BaseDiffState, createDiffStatus, createEditStatus, DiffApprService, DiffParameter, DiffState, DiffStatusConfig, handleToggle, hideLoading, showLoading} from './core';
6
+ import {Attributes, buildId, EditStatusConfig, error, ErrorMessage, Filter, getCurrencyCode, getModelName as getModelName2, initForm, LoadingService, Locale, message, messageByHttpStatus, PageChange, pageSizes, removePhoneFormat, ResourceService, SearchParameter, SearchResult, SearchService, SearchState, StringMap, UIService, ViewParameter, ViewService} from './core';
7
7
  import {formatDiffModel, getDataFields} from './diff';
8
8
  import {build, createModel as createModel2, EditParameter, GenericService, handleStatus, handleVersion, initPropertyNullInModel, ResultInfo} from './edit';
9
9
  import {focusFirstError, readOnly} from './formutil';
@@ -47,27 +47,27 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
47
47
  this.showModel = this.showModel.bind(this);
48
48
  this.ref = React.createRef();
49
49
  }
50
- protected name?: string;
51
- protected running?: boolean;
52
- protected resourceService: ResourceService;
53
- protected resource: StringMap;
54
- protected loading?: LoadingService;
55
- protected showError: (msg: string, title?: string, detail?: string, callback?: () => void) => void;
56
- protected getLocale?: (profile?: string) => Locale;
57
- protected loadData?: (id: ID, ctx?: any) => Promise<T>;
50
+ name?: string;
51
+ running?: boolean;
52
+ resourceService: ResourceService;
53
+ resource: StringMap;
54
+ loading?: LoadingService;
55
+ showError: (msg: string, title?: string, detail?: string, callback?: () => void) => void;
56
+ getLocale?: (profile?: string) => Locale;
57
+ loadData?: (id: ID) => Promise<T|null>;
58
58
  // protected service: ViewService<T, ID>;
59
- protected form?: HTMLFormElement;
60
- protected ref: any;
61
- protected keys?: string[];
62
- protected metadata?: Attributes;
59
+ form?: HTMLFormElement;
60
+ ref: any;
61
+ keys?: string[];
62
+ metadata?: Attributes;
63
63
 
64
- protected back(event: any) {
64
+ back(event: any) {
65
65
  if (event) {
66
66
  event.preventDefault();
67
67
  }
68
68
  this.props.history.goBack();
69
69
  }
70
- protected getModelName(): string {
70
+ getModelName(): string {
71
71
  if (this.name && this.name.length > 0) {
72
72
  return this.name;
73
73
  }
@@ -115,7 +115,7 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
115
115
  });
116
116
  }
117
117
  }
118
- protected handleNotFound(form?: HTMLFormElement): void {
118
+ handleNotFound(form?: HTMLFormElement): void {
119
119
  const msg = message(this.resourceService.value, 'error_not_found', 'error');
120
120
  if (form) {
121
121
  readOnly(form);
@@ -133,9 +133,9 @@ export class ViewComponent<T, ID, P extends RouteComponentProps, S> extends Reac
133
133
  }
134
134
  }
135
135
 
136
- export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S> {
136
+ export class BaseComponent<P, S> extends React.Component<P, S> {
137
137
  constructor(props: P,
138
- protected getLocale?: () => Locale,
138
+ public getLocale?: () => Locale,
139
139
  private removeErr?: (ctrl: HTMLInputElement) => void) {
140
140
  super(props);
141
141
  this.getModelName = this.getModelName.bind(this);
@@ -145,8 +145,8 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
145
145
  this.updateDateState = this.updateDateState.bind(this);
146
146
  this.prepareCustomData = this.prepareCustomData.bind(this);
147
147
  }
148
- protected running?: boolean;
149
- protected form?: HTMLFormElement|null;
148
+ running?: boolean;
149
+ form?: HTMLFormElement|null;
150
150
  /*
151
151
  protected handleSubmitForm(e) {
152
152
  if (e.which === 13) {
@@ -163,7 +163,7 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
163
163
 
164
164
  prepareCustomData(data: any) { }
165
165
 
166
- protected updatePhoneState = (event: any) => {
166
+ updatePhoneState = (event: any) => {
167
167
  const re = /^[0-9\b]+$/;
168
168
  const target = event.currentTarget as HTMLInputElement;
169
169
  const value = removePhoneFormat(target.value);
@@ -182,7 +182,7 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
182
182
  }
183
183
  }
184
184
 
185
- protected updateDateState = (name: string, value: any) => {
185
+ updateDateState = (name: string, value: any) => {
186
186
  const props: any = this.props;
187
187
  const modelName = this.getModelName(this.form);
188
188
  const state = (this.state as any)[modelName];
@@ -194,7 +194,7 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
194
194
  this.setState(objSet);
195
195
  }
196
196
  }
197
- protected getModelName(f?: HTMLFormElement|null): string {
197
+ getModelName(f?: HTMLFormElement|null): string {
198
198
  let f2 = f;
199
199
  if (!f2) {
200
200
  f2 = this.form;
@@ -207,14 +207,14 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
207
207
  }
208
208
  return 'model';
209
209
  }
210
- protected updateState = (e: any, callback?: () => void, lc?: Locale) => {
210
+ updateState = (e: any, callback?: () => void, lc?: Locale) => {
211
211
  const ctrl = e.currentTarget as HTMLInputElement;
212
212
  const modelName = this.getModelName(ctrl.form);
213
213
  const l = localeOf(lc, this.getLocale);
214
214
  const props = this.props;
215
215
  handleEvent(e, this.removeErr);
216
- if (props.setGlobalState) {
217
- handleProps(e, props, ctrl, modelName, l, this.prepareCustomData);
216
+ if ((props as any).setGlobalState) {
217
+ handleProps(e, props as any, ctrl, modelName, l, this.prepareCustomData);
218
218
  } else {
219
219
  const objSet: any = buildState(e, this.state, ctrl, modelName, l);
220
220
  if (objSet) {
@@ -226,7 +226,7 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
226
226
  }
227
227
  }
228
228
  }
229
- protected updateFlatState(e: any, callback?: () => void, lc?: Locale) {
229
+ updateFlatState(e: any, callback?: () => void, lc?: Locale) {
230
230
  const l = localeOf(lc, this.getLocale);
231
231
  const objSet: any = buildFlatState(e, this.state, l);
232
232
  if (objSet != null) {
@@ -238,10 +238,10 @@ export class BaseComponent<P extends ModelProps, S> extends React.Component<P, S
238
238
  }
239
239
  }
240
240
  }
241
- export interface MessageOnlyState extends ModelProps {
241
+ export interface MessageOnlyState {
242
242
  message?: string;
243
243
  }
244
- export class MessageComponent<P extends MessageOnlyState, S extends MessageOnlyState> extends BaseComponent<P, S> {
244
+ export class MessageComponent<S extends MessageOnlyState, P> extends BaseComponent<P, S> {
245
245
  constructor(props: P,
246
246
  getLocale?: () => Locale,
247
247
  removeErr?: (ctrl: HTMLInputElement) => void) {
@@ -255,7 +255,7 @@ export class MessageComponent<P extends MessageOnlyState, S extends MessageOnlyS
255
255
  ref: any;
256
256
  name?: string;
257
257
  alertClass = '';
258
- protected getModelName(f?: HTMLFormElement|null): string {
258
+ getModelName(f?: HTMLFormElement|null): string {
259
259
  if (this.name && this.name.length > 0) {
260
260
  return this.name;
261
261
  }
@@ -291,7 +291,7 @@ export class MessageComponent<P extends MessageOnlyState, S extends MessageOnlyS
291
291
  this.setState({ message: '' });
292
292
  }
293
293
  }
294
- export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProps, I extends SearchState<T, S>> extends BaseComponent<P, I> implements Searchable {
294
+ export class BaseSearchComponent<T, F extends Filter, P, I extends SearchState<T, F>> extends BaseComponent<P, I> implements Searchable {
295
295
  constructor(props: P,
296
296
  protected resourceService: ResourceService,
297
297
  protected showMessage: (msg: string) => void,
@@ -301,12 +301,12 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
301
301
  protected listFormId?: string) {
302
302
  super(props, getLocale, (ui ? ui.removeError : undefined));
303
303
  this.resource = resourceService.resource();
304
+ this.hideFilter = true;
304
305
  this.getModelName = this.getModelName.bind(this);
305
306
  this.showMessage = this.showMessage.bind(this);
306
307
 
307
308
  this.toggleFilter = this.toggleFilter.bind(this);
308
309
  this.load = this.load.bind(this);
309
- this.add = this.add.bind(this);
310
310
  this.getSearchForm = this.getSearchForm.bind(this);
311
311
  this.setSearchForm = this.setSearchForm.bind(this);
312
312
 
@@ -316,7 +316,7 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
316
316
 
317
317
  this.pageSizeChanged = this.pageSizeChanged.bind(this);
318
318
  this.clearQ = this.clearQ.bind(this);
319
- this.searchOnClick = this.searchOnClick.bind(this);
319
+ this.search = this.search.bind(this);
320
320
 
321
321
  this.resetAndSearch = this.resetAndSearch.bind(this);
322
322
  this.doSearch = this.doSearch.bind(this);
@@ -329,7 +329,8 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
329
329
  this.showMore = this.showMore.bind(this);
330
330
  this.pageChanged = this.pageChanged.bind(this);
331
331
 
332
- this.url = (props.match ? props.match.url : (props as any)['props'].match.url);
332
+ const currentUrl = window.location.host + window.location.pathname;
333
+ this.url = removeUrlParams(currentUrl);
333
334
  /*
334
335
  this.locationSearch = '';
335
336
  const location = (props.location ? props.location : props['props'].location);
@@ -338,16 +339,17 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
338
339
  }
339
340
  */
340
341
  }
341
- protected resource: StringMap;
342
- protected url: string;
342
+ resource: StringMap;
343
+ url: string;
343
344
 
345
+ filter?: F;
344
346
  // Pagination
345
- initPageSize = 20;
346
- pageSize = 20;
347
+ initPageSize = 24;
348
+ pageSize = 24;
347
349
  pageIndex?: number = 1;
348
350
  nextPageToken?: string;
349
- itemTotal = 0;
350
- pageTotal = 0;
351
+ total = 0;
352
+ pages = 0;
351
353
  showPaging?: boolean;
352
354
  append?: boolean;
353
355
  appendMode?: boolean;
@@ -367,7 +369,7 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
367
369
  tmpPageIndex?: number = 1;
368
370
 
369
371
  pageMaxSize = 7;
370
- pageSizes: number[] = [10, 20, 40, 60, 100, 200, 400, 800];
372
+ pageSizes: number[] = pageSizes;
371
373
 
372
374
  list?: T[];
373
375
  excluding?: string[]|number[];
@@ -383,19 +385,16 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
383
385
  approvable?: boolean;
384
386
  deletable?: boolean;
385
387
 
386
- protected getModelName(): string {
388
+ getModelName(): string {
387
389
  return 'filter';
388
390
  }
389
391
 
390
- toggleFilter(event: any): void {
391
- this.hideFilter = !this.hideFilter;
392
- }
393
- protected add = (event: any) => {
394
- event.preventDefault();
395
- const url = (this.props as any)['props'].match.url + '/add';
396
- this.props.history.push(url);
392
+ toggleFilter(event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void {
393
+ const x = !this.hideFilter;
394
+ handleToggle(event.target as HTMLInputElement, !x);
395
+ this.hideFilter = x;
397
396
  }
398
- load(s: S, autoSearch: boolean): void {
397
+ load(s: F, autoSearch: boolean): void {
399
398
  const obj2 = initFilter(s, this);
400
399
  this.setFilter(obj2);
401
400
  const com = this;
@@ -406,23 +405,26 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
406
405
  }
407
406
  }
408
407
 
409
- protected setSearchForm(form: HTMLFormElement): void {
408
+ setSearchForm(form: HTMLFormElement): void {
410
409
  this.form = form;
411
410
  }
412
411
 
413
- protected getSearchForm(): HTMLFormElement|undefined|null {
412
+ getSearchForm(): HTMLFormElement|undefined|null {
414
413
  if (!this.form && this.listFormId) {
415
414
  this.form = document.getElementById(this.listFormId) as HTMLFormElement;
416
415
  }
417
416
  return this.form;
418
417
  }
419
- setFilter(filter: S): void {
420
- this.setState(filter as any);
418
+ setFilter(filter: F): void {
419
+ const modelName = this.getModelName();
420
+ const objSet: any = {};
421
+ objSet[modelName] = filter;
422
+ this.setState(objSet);
421
423
  }
422
- protected getCurrencyCode(): string|undefined {
424
+ getCurrencyCode(): string|undefined {
423
425
  return getCurrencyCode(this.form);
424
426
  }
425
- getFilter(): S {
427
+ getFilter(): F {
426
428
  const name = this.getModelName();
427
429
  let lc: Locale|undefined;
428
430
  if (this.getLocale) {
@@ -436,10 +438,10 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
436
438
  const l = this.getList();
437
439
  const f = this.getSearchForm();
438
440
  const dc = (this.ui ? this.ui.decodeFromForm : undefined);
439
- const obj3 = getModel<T, S>(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
441
+ const obj3 = getModel<T, F>(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
440
442
  return obj3;
441
443
  }
442
- protected getFields(): string[]|undefined {
444
+ getFields(): string[]|undefined {
443
445
  const fs = getFieldsFromForm(this.fields, this.initFields, this.form);
444
446
  this.initFields = true;
445
447
  return fs;
@@ -450,11 +452,11 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
450
452
  this.pageSizeChanged(size);
451
453
  }
452
454
  */
453
- protected pageSizeOnClick = () => {
455
+ pageSizeOnClick = () => {
454
456
  this.setState(prevState => ({ isPageSizeOpenDropDown: !(prevState as any).isPageSizeOpenDropDown } as any));
455
457
  }
456
458
 
457
- protected clearQ(): void {
459
+ clearQ(): void {
458
460
  const m = this.state.model;
459
461
  if (m) {
460
462
  m.q = '';
@@ -465,7 +467,7 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
465
467
  });
466
468
  }
467
469
  }
468
- searchOnClick(event: any): void {
470
+ search(event: any): void {
469
471
  if (event) {
470
472
  event.preventDefault();
471
473
  if (!this.getSearchForm()) {
@@ -509,26 +511,27 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
509
511
  });
510
512
  }
511
513
 
512
- call(s: S): void {
514
+ call(s: F): void {
513
515
 
514
516
  }
515
517
 
516
- validateSearch(se: S, callback: () => void): void {
518
+ validateSearch(se: F, callback: () => void): void {
517
519
  const u = this.ui;
518
520
  const vl = (u ? u.validateForm : undefined);
519
521
  validate(se, callback, this.getSearchForm(), localeOf(undefined, this.getLocale), vl);
520
522
  }
521
- showResults(s: S, sr: SearchResult<T>) {
523
+ showResults(s: F, sr: SearchResult<T>) {
522
524
  const com = this;
523
525
  const results = sr.list;
524
526
  if (results && results.length > 0) {
525
527
  const lc = localeOf(undefined, this.getLocale);
526
- formatResultsByComponent(results, com, lc);
528
+ // formatResultsByComponent(results, com, lc);
529
+ formatResults(results, com.pageIndex, com.pageSize, com.pageSize, com.sequenceNo, com.format, lc);
527
530
  }
528
531
  const am = com.appendMode;
529
532
  com.pageIndex = (s.page && s.page >= 1 ? s.page : 1);
530
533
  if (sr.total) {
531
- com.itemTotal = sr.total;
534
+ com.total = sr.total;
532
535
  }
533
536
  if (am) {
534
537
  let limit = s.limit;
@@ -610,13 +613,13 @@ export class BaseSearchComponent<T, S extends Filter, P extends ModelHistoryProp
610
613
  this.doSearch();
611
614
  }
612
615
 
613
- pageChanged(data: any) {
614
- const { currentPage, itemsPerPage } = data;
615
- changePage(this, currentPage, itemsPerPage);
616
+ pageChanged(data: PageChange) {
617
+ const { page, size } = data;
618
+ changePage(this, page, size);
616
619
  this.doSearch();
617
620
  }
618
621
  }
619
- export class SearchComponent<T, S extends Filter, P extends ModelHistoryProps, I extends SearchState<T, S>> extends BaseSearchComponent<T, S, P, I> {
622
+ export class SearchComponent<T, S extends Filter, P extends RouteComponentProps, I extends SearchState<T, S>> extends BaseSearchComponent<T, S, P, I> {
620
623
  constructor(props: P, sv: ((s: S, ctx?: any) => Promise<SearchResult<T>>) | SearchService<T, S>,
621
624
  param: ResourceService|SearchParameter,
622
625
  showMessage?: (msg: string, option?: string) => void,
@@ -630,14 +633,15 @@ export class SearchComponent<T, S extends Filter, P extends ModelHistoryProps, I
630
633
  if (sv) {
631
634
  if (typeof sv === 'function') {
632
635
  const x: any = sv;
633
- this.search = x;
636
+ this.service = x;
634
637
  } else {
635
- this.search = sv.search;
638
+ this.service = sv.search;
636
639
  if (sv.keys) {
637
640
  this.keys = sv.keys();
638
641
  }
639
642
  }
640
643
  }
644
+ this.add = this.add.bind(this);
641
645
  this.call = this.call.bind(this);
642
646
  this.showError = getErrorFunc(param, showError);
643
647
  this.componentDidMount = this.componentDidMount.bind(this);
@@ -646,7 +650,7 @@ export class SearchComponent<T, S extends Filter, P extends ModelHistoryProps, I
646
650
  this.ref = React.createRef();
647
651
  }
648
652
  protected showError: (m: string, header?: string, detail?: string, callback?: () => void) => void;
649
- protected search?: (s: S, limit?: number, offset?: number|string, fields?: string[]) => Promise<SearchResult<T>>;
653
+ protected service?: (s: S, limit?: number, offset?: number|string, fields?: string[]) => Promise<SearchResult<T>>;
650
654
  // protected service: SearchService<T, S>;
651
655
  protected ref: any;
652
656
  protected autoSearch: boolean;
@@ -663,6 +667,11 @@ export class SearchComponent<T, S extends Filter, P extends ModelHistoryProps, I
663
667
  const s: any = {};
664
668
  return s;
665
669
  }
670
+ add = (event: any) => {
671
+ event.preventDefault();
672
+ const url = this.url + '/add';
673
+ this.props.history.push(url);
674
+ }
666
675
  call(se: S) {
667
676
  this.running = true;
668
677
  const s = clone(se);
@@ -687,8 +696,8 @@ export class SearchComponent<T, S extends Filter, P extends ModelHistoryProps, I
687
696
  delete se['firstLimit'];
688
697
  showLoading(this.loading);
689
698
  const com = this;
690
- if (this.search) {
691
- this.search(s, limit, next, fields).then(sr => {
699
+ if (this.service) {
700
+ this.service(s, limit, next, fields).then(sr => {
692
701
  com.showResults(s, sr);
693
702
  com.running = undefined;
694
703
  hideLoading(com.loading);
@@ -702,7 +711,7 @@ export class SearchComponent<T, S extends Filter, P extends ModelHistoryProps, I
702
711
  }
703
712
  }
704
713
 
705
- export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> extends BaseComponent<P, S> {
714
+ export abstract class BaseEditComponent<T, P extends RouteComponentProps, S> extends BaseComponent<P, S> {
706
715
  constructor(props: P,
707
716
  protected resourceService: ResourceService,
708
717
  protected showMessage: (msg: string) => void,
@@ -738,11 +747,11 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
738
747
  this.getModel = this.getModel.bind(this);
739
748
  this.createModel = this.createModel.bind(this);
740
749
 
741
- this.newOnClick = this.newOnClick.bind(this);
742
- this.saveOnClick = this.saveOnClick.bind(this);
750
+ this.create = this.create.bind(this);
751
+ this.save = this.save.bind(this);
743
752
  this.onSave = this.onSave.bind(this);
744
753
  this.validate = this.validate.bind(this);
745
- this.save = this.save.bind(this);
754
+ this.doSave = this.doSave.bind(this);
746
755
  this.succeed = this.succeed.bind(this);
747
756
  this.fail = this.fail.bind(this);
748
757
  this.postSave = this.postSave.bind(this);
@@ -766,25 +775,25 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
766
775
 
767
776
  insertSuccessMsg: string;
768
777
  updateSuccessMsg: string;
769
- protected back(event: any) {
778
+ back(event: any) {
770
779
  if (event) {
771
780
  event.preventDefault();
772
781
  }
773
782
  this.props.history.goBack();
774
783
  }
775
- protected resetState(newMod: boolean, model: T, originalModel?: T) {
784
+ resetState(newMod: boolean, model: T, originalModel?: T) {
776
785
  this.newMode = newMod;
777
786
  this.orginalModel = originalModel;
778
787
  this.showModel(model);
779
788
  }
780
- protected handleNotFound(form?: HTMLFormElement|null): void {
789
+ handleNotFound(form?: HTMLFormElement|null): void {
781
790
  const msg = message(this.resourceService.value, 'error_not_found', 'error');
782
791
  if (form) {
783
792
  readOnly(form);
784
793
  }
785
794
  this.showError(msg.message, msg.title);
786
795
  }
787
- protected getModelName(f?: HTMLFormElement): string {
796
+ getModelName(f?: HTMLFormElement): string {
788
797
  if (this.name && this.name.length > 0) {
789
798
  return this.name;
790
799
  }
@@ -807,7 +816,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
807
816
  }
808
817
 
809
818
  // end of: can be in ViewComponent
810
- protected createModel(): T {
819
+ createModel(): T {
811
820
  if (this.metadata) {
812
821
  const obj = createModel2<T>(this.metadata);
813
822
  return obj;
@@ -817,7 +826,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
817
826
  }
818
827
  }
819
828
 
820
- newOnClick = (event: any) => {
829
+ create = (event: any) => {
821
830
  if (event) {
822
831
  event.preventDefault();
823
832
  }
@@ -834,7 +843,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
834
843
  }, 100);
835
844
  }
836
845
  }
837
- protected saveOnClick = (event: any) => {
846
+ save = (event: any) => {
838
847
  event.preventDefault();
839
848
  (event as any).persist();
840
849
  if (!this.form && event && event.target) {
@@ -862,7 +871,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
862
871
  com.validate(obj, () => {
863
872
  const msg = message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
864
873
  this.confirm(msg.message, msg.title, () => {
865
- com.save(obj, obj, isBack);
874
+ com.doSave(obj, obj, isBack);
866
875
  }, msg.no, msg.yes);
867
876
  });
868
877
  } else {
@@ -874,14 +883,14 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
874
883
  com.validate(obj, () => {
875
884
  const msg = message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
876
885
  this.confirm(msg.message, msg.title, () => {
877
- com.save(obj, diffObj, isBack);
886
+ com.doSave(obj, diffObj, isBack);
878
887
  }, msg.no, msg.yes);
879
888
  });
880
889
  }
881
890
  }
882
891
  }
883
892
  }
884
- protected validate(obj: T, callback: (obj2?: T) => void) {
893
+ validate(obj: T, callback: (obj2?: T) => void) {
885
894
  if (this.ui && this.form) {
886
895
  const valid = this.ui.validateForm(this.form, localeOf(undefined, this.getLocale));
887
896
  if (valid) {
@@ -892,10 +901,10 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
892
901
  }
893
902
  }
894
903
 
895
- protected save(obj: T, dif?: T, isBack?: boolean) {
904
+ doSave(obj: T, dif?: T, isBack?: boolean) {
896
905
  }
897
906
 
898
- protected succeed(msg: string, isBack?: boolean, result?: ResultInfo<T>) {
907
+ succeed(msg: string, isBack?: boolean, result?: ResultInfo<T>) {
899
908
  if (result) {
900
909
  const model = result.value;
901
910
  this.newMode = false;
@@ -913,7 +922,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
913
922
  this.back(null);
914
923
  }
915
924
  }
916
- protected fail(result: ResultInfo<T>) {
925
+ fail(result: ResultInfo<T>) {
917
926
  const errors = result.errors;
918
927
  const f = this.form;
919
928
  const u = this.ui;
@@ -936,7 +945,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
936
945
  }
937
946
  }
938
947
 
939
- protected postSave(res: number|string|ResultInfo<T>, backOnSave?: boolean) {
948
+ postSave(res: number|string|ResultInfo<T>, backOnSave?: boolean) {
940
949
  this.running = false;
941
950
  hideLoading(this.loading);
942
951
  const st = this.status;
@@ -972,7 +981,7 @@ export abstract class BaseEditComponent<T, P extends ModelHistoryProps, S> exten
972
981
  }
973
982
  }
974
983
  }
975
- protected handleDuplicateKey(result?: ResultInfo<T>) {
984
+ handleDuplicateKey(result?: ResultInfo<T>) {
976
985
  const msg = message(this.resourceService.value, 'error_duplicate_key', 'error');
977
986
  this.showError(msg.message, msg.title);
978
987
  }
@@ -1008,20 +1017,18 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
1008
1017
  this.keys = [];
1009
1018
  }
1010
1019
  this.load = this.load.bind(this);
1011
- this.save = this.save.bind(this);
1020
+ this.doSave = this.doSave.bind(this);
1012
1021
  this.componentDidMount = this.componentDidMount.bind(this);
1013
1022
  this.ref = React.createRef();
1014
1023
  }
1015
- protected ref: any;
1024
+ ref: any;
1016
1025
  componentDidMount() {
1017
1026
  const k = (this.ui ? this.ui.registerEvents : undefined);
1018
1027
  this.form = initForm(this.ref.current, k);
1019
1028
  const id = buildId<ID>(this.props, this.keys);
1020
- if (id) {
1021
- this.load(id);
1022
- }
1029
+ this.load(id);
1023
1030
  }
1024
- load(_id: ID, callback?: (m: T, showM: (m2: T) => void) => void) {
1031
+ load(_id: ID|null, callback?: (m: T, showM: (m2: T) => void) => void) {
1025
1032
  const id: any = _id;
1026
1033
  if (id != null && id !== '') {
1027
1034
  const com = this;
@@ -1073,7 +1080,7 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
1073
1080
  }
1074
1081
  }
1075
1082
  }
1076
- protected save(obj: T, body?: T, isBack?: boolean) {
1083
+ doSave(obj: T, body?: T, isBack?: boolean) {
1077
1084
  this.running = true;
1078
1085
  showLoading(this.loading);
1079
1086
  const isBackO = (isBack == null || isBack === undefined ? this.backOnSuccess : isBack);
@@ -1098,7 +1105,7 @@ export class EditComponent<T, ID, P extends RouteComponentProps, S> extends Base
1098
1105
  }
1099
1106
  }
1100
1107
 
1101
- export class BaseDiffApprComponent<T, ID, P extends HistoryProps, S extends BaseDiffState> extends React.Component<P, S & any> {
1108
+ export class BaseDiffApprComponent<T, ID, P extends RouteComponentProps, S extends BaseDiffState> extends React.Component<P, S & any> {
1102
1109
  constructor(props: P, protected keys: string[], protected resourceService: ResourceService,
1103
1110
  protected showMessage: (msg: string, option?: string) => void,
1104
1111
  protected showError: (m: string, title?: string, detail?: string, callback?: () => void) => void,
@@ -1122,25 +1129,25 @@ export class BaseDiffApprComponent<T, ID, P extends HistoryProps, S extends Base
1122
1129
  disabled: false
1123
1130
  };
1124
1131
  }
1125
- protected status: DiffStatusConfig;
1126
- protected id?: ID;
1127
- protected form?: HTMLFormElement;
1128
- protected running?: boolean;
1129
- protected resource: StringMap;
1132
+ status: DiffStatusConfig;
1133
+ id?: ID;
1134
+ form?: HTMLFormElement;
1135
+ running?: boolean;
1136
+ resource: StringMap;
1130
1137
 
1131
- protected back(event: any) {
1138
+ back(event: any) {
1132
1139
  if (event) {
1133
1140
  event.preventDefault();
1134
1141
  }
1135
1142
  this.props.history.goBack();
1136
1143
  }
1137
1144
 
1138
- protected initModel(): T {
1145
+ initModel(): T {
1139
1146
  const x: any = {};
1140
1147
  return x;
1141
1148
  }
1142
1149
 
1143
- protected postApprove(s: number|string, err?: any) {
1150
+ postApprove(s: number|string, err?: any) {
1144
1151
  this.setState({ disabled: true });
1145
1152
  const r = this.resourceService;
1146
1153
  const st = this.status;
@@ -1156,7 +1163,7 @@ export class BaseDiffApprComponent<T, ID, P extends HistoryProps, S extends Base
1156
1163
  }
1157
1164
  }
1158
1165
 
1159
- protected postReject(status: number|string, err?: any) {
1166
+ postReject(status: number|string, err?: any) {
1160
1167
  this.setState({ disabled: true });
1161
1168
  const r = this.resourceService;
1162
1169
  const st = this.status;
@@ -1211,7 +1218,7 @@ export class BaseDiffApprComponent<T, ID, P extends HistoryProps, S extends Base
1211
1218
  }
1212
1219
  }
1213
1220
 
1214
- protected handleNotFound() {
1221
+ handleNotFound() {
1215
1222
  this.setState({ disabled: true });
1216
1223
  const msg = message(this.resourceService.value, 'error_not_found', 'error');
1217
1224
  this.showError(msg.message, msg.title);
@@ -1235,7 +1242,7 @@ export class DiffApprComponent<T, ID, P extends RouteComponentProps, S extends D
1235
1242
  disabled: false,
1236
1243
  };
1237
1244
  }
1238
- protected ref: any;
1245
+ ref: any;
1239
1246
 
1240
1247
  componentDidMount() {
1241
1248
  this.form = this.ref.current;
@@ -1317,3 +1324,7 @@ export class DiffApprComponent<T, ID, P extends RouteComponentProps, S extends D
1317
1324
  }
1318
1325
  }
1319
1326
  }
1327
+ export function removeUrlParams(url: string): string {
1328
+ const startParams = url.indexOf('?');
1329
+ return startParams !== -1 ? url.substring(0, startParams) : url;
1330
+ }