@apia/api 3.0.12 → 4.0.0

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/dist/index.d.ts CHANGED
@@ -11,6 +11,17 @@ import * as lodash from 'lodash';
11
11
  import * as theme_ui from 'theme-ui';
12
12
 
13
13
  declare function getConfig<LoadType>(outerBehaveConfig?: IApiaApiRequestConfig<LoadType>): IApiaApiRequestConfig<unknown> & IApiaApiRequestConfig<LoadType> & Partial<IApiaApiRequestConfig<unknown>>;
14
+ declare const parseSuccessfulResponse: <LoadType extends Record<string, unknown>>(response: AxiosResponse<string>, currentUrl: string, outerBehaveConfig?: IApiaApiRequestConfig<LoadType>) => Promise<(LoadType & {
15
+ sysMessages: {
16
+ message: _apia_util.TApiaMessage | _apia_util.TApiaMessage[];
17
+ } | undefined;
18
+ exceptions: {
19
+ exception: _apia_util.TApiaMessage | _apia_util.TApiaMessage[];
20
+ } | undefined;
21
+ sysExceptions: {
22
+ exception: _apia_util.TApiaMessage | _apia_util.TApiaMessage[];
23
+ } | undefined;
24
+ }) | null>;
14
25
  type TApiaApiAxiosResponse<LoadType> = AxiosResponse<LoadType | null> & {
15
26
  hasError: boolean;
16
27
  hasMessages: boolean;
@@ -318,7 +329,9 @@ type TFilter = {
318
329
 
319
330
  type FilterState = TFilter;
320
331
  declare class Filter {
332
+ private tableName?;
321
333
  filterState: FilterState;
334
+ focus(): void;
322
335
  constructor(properties: TFilter);
323
336
  Component: (({ filter }: {
324
337
  filter: TApiaFilter;
@@ -350,18 +363,48 @@ type TableControllerEvents = {
350
363
  onSortChange: TResponsiveTableSortChangeEvent;
351
364
  };
352
365
 
366
+ type TFilterTypesElementConditions = {
367
+ onChange: string;
368
+ readonly: boolean;
369
+ name: string;
370
+ valueAsAttribute: boolean;
371
+ disabled: boolean;
372
+ html: boolean;
373
+ text: string;
374
+ id: string;
375
+ title: string;
376
+ type: string;
377
+ value: string;
378
+ selected: boolean;
379
+ options: {
380
+ option: {
381
+ content: string;
382
+ value: string;
383
+ }[];
384
+ };
385
+ };
386
+
387
+ declare class FilterTypes {
388
+ conditions: TFilterTypesElementConditions[];
389
+ constructor();
390
+ protected getFilterTypes(): Promise<void>;
391
+ protected initialLoad(): Promise<void>;
392
+ Component: () => React$1.JSX.Element;
393
+ }
394
+
353
395
  declare class TableController {
354
396
  private emitter;
355
397
  private tableName;
356
398
  private tableSelectionController;
357
399
  private controllerComponent;
400
+ filterTypes: FilterTypes;
358
401
  state: TableControllerState;
359
402
  constructor(initialState?: Partial<TableControllerState>);
360
- Context: (({ children }: {
403
+ clearFilters(): void;
404
+ private parseFilters;
405
+ Context: ({ children }: {
361
406
  children: React.ReactNode;
362
- }) => React$1.JSX.Element) & {
363
- displayName: string;
364
- };
407
+ }) => React$1.JSX.Element;
365
408
  getTableName(): string;
366
409
  Pagination: (() => React$1.JSX.Element) & {
367
410
  displayName: string;
@@ -379,6 +422,7 @@ type QueryControllerStructure = {
379
422
  isDynamic: boolean;
380
423
  openFiltersAutomatically: boolean;
381
424
  runFiltersAutomatically: boolean;
425
+ hideFilterTypes: boolean;
382
426
  title: string;
383
427
  };
384
428
  declare abstract class QueryController {
@@ -390,6 +434,7 @@ declare abstract class QueryController {
390
434
  constructor(ajaxUrl: string);
391
435
  private initEvents;
392
436
  protected getLoadStructureParameters(): Record<string, unknown>;
437
+ protected getClearFiltersParameters(): Record<string, unknown>;
393
438
  protected getPageParameters(): Record<string, unknown>;
394
439
  protected getRefreshParameters(): Record<string, unknown>;
395
440
  protected getSortParameters(): Record<string, unknown>;
@@ -399,8 +444,10 @@ declare abstract class QueryController {
399
444
  protected parseStructure(structure: QueryControllerStructure): void;
400
445
  protected updatePageState(pageInfo?: TApiaFunctionPageInfo): void;
401
446
  protected updateRows(rows: TResponsiveTableRow[]): void;
447
+ clearFilters(): Promise<void>;
402
448
  initialLoad(): Promise<void>;
403
449
  page(num: number): Promise<void>;
450
+ protected areRequiredFilters(): boolean;
404
451
  protected executeRefresh: lodash.DebouncedFunc<() => Promise<void>>;
405
452
  refresh(): Promise<void | undefined>;
406
453
  sort(column: string): Promise<void>;
@@ -421,5 +468,5 @@ declare class QueryModalController {
421
468
  getModalHandler(): ApiaUtilModalHandler | null;
422
469
  }
423
470
 
424
- export { ApiaApi, ApiaApiHandler, type IApiaApiRequestConfig, QueryController, type QueryControllerStructure, QueryModalController, type TApiaApiAxiosResponse, type TApiaApiMethod, type TApiaApiResult, type TFilter, getFunction, getModal, makeApiaUrl };
471
+ export { ApiaApi, ApiaApiHandler, type IApiaApiRequestConfig, QueryController, type QueryControllerStructure, QueryModalController, type TApiaApiAxiosResponse, type TApiaApiMethod, type TApiaApiResult, type TFilter, getFunction, getModal, makeApiaUrl, parseSuccessfulResponse };
425
472
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
2
2
  import * as React from 'react';
3
3
  import React__default, { createContext, useState, useCallback, useEffect, useId } from 'react';
4
- import { Box, Label, spacing, getVariant, Input as Input$1 } from '@apia/theme';
4
+ import { Box, Label, spacing, getVariant, Select as Select$1, Input as Input$1 } from '@apia/theme';
5
5
  import { debugDispatcher, parseXmlAsync, EventEmitter, arrayOrArray, useMount, encrypt, noNaN, getIndex, getLabel, StatefulEmitter, focus, focusSelector, useLatest } from '@apia/util';
6
6
  import { notify, getNotificationMessageObj, dispatchNotifications } from '@apia/notifications';
7
7
  import { classToValidate, Checkbox, FileInput, classToValidationFunction, Input, Radio, Select, Textarea, useFormContext, validationsStore, hasSucceedFormValidation, Form } from '@apia/validations';
@@ -11,8 +11,8 @@ import merge from 'lodash-es/merge';
11
11
  import QueryString from 'qs';
12
12
  import { session } from '@apia/session';
13
13
  import uniqueId from 'lodash-es/uniqueId';
14
- import { ResponsiveTableContext, ResponsiveTable, Pagination, Sort, Responsive, Additional, responsiveTableStore, TableContextReproducer, makeController2, useResponsiveTableContext } from '@apia/table';
15
- import { toJS, makeObservable, observable, action } from 'mobx';
14
+ import { ResponsiveTableContext, ResponsiveTable, Pagination, Sort, Responsive, Additional, responsiveTableStore, TableContextReproducer, makeController2, responsiveTableActions, useResponsiveTableContext, getResponsiveTableContext } from '@apia/table';
15
+ import { makeObservable, observable, action, reaction, toJS } from 'mobx';
16
16
  import { observer } from 'mobx-react-lite';
17
17
  import { throttle } from 'lodash-es';
18
18
 
@@ -3226,8 +3226,17 @@ const AdditionalFiltersComponent = ({
3226
3226
  const filterTitle = getLabel("sbtFilters").text;
3227
3227
  const sortTitle = getLabel("titOrderBy").text;
3228
3228
  const filterTypes = getLabel("btnFilterType").text;
3229
- return /* @__PURE__ */ jsx(TableContextReproducer, { tableName: tableController.getTableName(), children: /* @__PURE__ */ jsx(Box, { className: "additionalFiltersContent", children: /* @__PURE__ */ jsxs(Accordion, { children: [
3230
- /* @__PURE__ */ jsx(
3229
+ const hasAdditional = !![...tableController.state.filters.values()].find(
3230
+ (f) => f.filterState.isAdditional
3231
+ );
3232
+ const hasFilters = !![...tableController.state.filters.values()].find(
3233
+ (f) => !f.filterState.isAdditional && f.filterState.column
3234
+ );
3235
+ const hasSortable = !![...tableController.state.columns.values()].find(
3236
+ (c) => c.allowSorting
3237
+ );
3238
+ return /* @__PURE__ */ jsx(TableContextReproducer, { tableName: tableController.getTableName(), children: /* @__PURE__ */ jsxs(Accordion, { className: "additionalFiltersContent", children: [
3239
+ hasFilters && /* @__PURE__ */ jsx(
3231
3240
  AccordionItem,
3232
3241
  {
3233
3242
  id: "Responsive",
@@ -3235,52 +3244,86 @@ const AdditionalFiltersComponent = ({
3235
3244
  children: /* @__PURE__ */ jsx(Responsive, {})
3236
3245
  }
3237
3246
  ),
3238
- /* @__PURE__ */ jsx(
3247
+ hasAdditional && /* @__PURE__ */ jsx(
3239
3248
  AccordionItem,
3240
3249
  {
3241
3250
  id: "Additional",
3242
- buttonProps: { ariaLabel: sortTitle, label: sortTitle },
3251
+ buttonProps: {
3252
+ ariaLabel: "todo: additional",
3253
+ label: "todo:additional"
3254
+ },
3243
3255
  children: /* @__PURE__ */ jsx(Additional, {})
3244
3256
  }
3245
3257
  ),
3246
- /* @__PURE__ */ jsx(
3258
+ hasSortable && /* @__PURE__ */ jsx(
3247
3259
  AccordionItem,
3248
3260
  {
3249
3261
  id: "Sort",
3250
- buttonProps: { ariaLabel: filterTypes, label: filterTypes },
3262
+ buttonProps: { ariaLabel: sortTitle, label: sortTitle },
3251
3263
  children: /* @__PURE__ */ jsx(Sort, {})
3252
3264
  }
3265
+ ),
3266
+ hasFilters && /* @__PURE__ */ jsx(
3267
+ AccordionItem,
3268
+ {
3269
+ id: "FilterTypes",
3270
+ buttonProps: { ariaLabel: filterTypes, label: filterTypes },
3271
+ children: /* @__PURE__ */ jsx(tableController.filterTypes.Component, {})
3272
+ }
3253
3273
  )
3254
- ] }) }) });
3274
+ ] }) });
3255
3275
  };
3256
3276
 
3257
- var __defProp$4 = Object.defineProperty;
3258
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3259
- var __publicField$4 = (obj, key, value) => {
3260
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3277
+ var __defProp$5 = Object.defineProperty;
3278
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3279
+ var __publicField$5 = (obj, key, value) => {
3280
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
3261
3281
  return value;
3262
3282
  };
3263
- class AdditionalFiltersModalController {
3264
- constructor(tableController) {
3265
- this.tableController = tableController;
3266
- __publicField$4(this, "modalHandler", null);
3283
+ class AdditionalFiltersModal {
3284
+ constructor(queryController) {
3285
+ this.queryController = queryController;
3286
+ __publicField$5(this, "modalHandler", null);
3267
3287
  }
3268
3288
  getModalDefinition() {
3269
3289
  return {
3270
- children: /* @__PURE__ */ jsx(AdditionalFiltersComponent, { tableController: this.tableController }),
3290
+ children: /* @__PURE__ */ jsx(
3291
+ AdditionalFiltersComponent,
3292
+ {
3293
+ tableController: this.queryController.tableController
3294
+ }
3295
+ ),
3271
3296
  onConfirm: () => {
3272
3297
  },
3273
3298
  confirmProps: {
3274
3299
  hideConfirmButton: true,
3275
3300
  hideCancelButton: true,
3276
- additionalButtons: /* @__PURE__ */ jsxs(Fragment, { children: [
3277
- /* @__PURE__ */ jsx(SimpleButton, { children: "TODO:BUSCAR" }),
3278
- ",",
3279
- /* @__PURE__ */ jsx(SimpleButton, { variant: "outline", children: "TODO:FILTER" })
3301
+ additionalButtonsOnRight: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "row", gap: "10px" }, children: [
3302
+ /* @__PURE__ */ jsx(
3303
+ SimpleButton,
3304
+ {
3305
+ variant: "primary-sm",
3306
+ onClick: () => {
3307
+ this.queryController.refresh();
3308
+ },
3309
+ children: getLabel("btnSearch").text
3310
+ }
3311
+ ),
3312
+ /* @__PURE__ */ jsx(
3313
+ SimpleButton,
3314
+ {
3315
+ variant: "outline-sm",
3316
+ onClick: () => {
3317
+ this.queryController.clearFilters();
3318
+ },
3319
+ children: getLabel("btnClearFilter").text
3320
+ }
3321
+ )
3280
3322
  ] })
3281
3323
  },
3282
3324
  draggable: true,
3283
- size: "lg"
3325
+ variant: "layout.common.modals.apiaFinder.additionalFiltersModal",
3326
+ size: "xl"
3284
3327
  };
3285
3328
  }
3286
3329
  async openModal(properties) {
@@ -3294,20 +3337,20 @@ class AdditionalFiltersModalController {
3294
3337
  }
3295
3338
  }
3296
3339
 
3297
- var __defProp$3 = Object.defineProperty;
3298
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3299
- var __publicField$3 = (obj, key, value) => {
3300
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
3340
+ var __defProp$4 = Object.defineProperty;
3341
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3342
+ var __publicField$4 = (obj, key, value) => {
3343
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3301
3344
  return value;
3302
3345
  };
3303
3346
  class QueryModalController {
3304
3347
  constructor(queryController) {
3305
- __publicField$3(this, "emitter", new EventEmitter());
3306
- __publicField$3(this, "queryController");
3307
- __publicField$3(this, "modalHandler", null);
3308
- __publicField$3(this, "currentSelection", null);
3309
- __publicField$3(this, "additionalFiltersController");
3310
- __publicField$3(this, "openModal", async (properties) => {
3348
+ __publicField$4(this, "emitter", new EventEmitter());
3349
+ __publicField$4(this, "queryController");
3350
+ __publicField$4(this, "modalHandler", null);
3351
+ __publicField$4(this, "currentSelection", null);
3352
+ __publicField$4(this, "additionalFiltersController");
3353
+ __publicField$4(this, "openModal", async (properties) => {
3311
3354
  await this.queryController.initialLoad();
3312
3355
  this.modalHandler = ApiaUtil.instance.modals.open({
3313
3356
  ...this.getModalDefinition(),
@@ -3318,8 +3361,8 @@ class QueryModalController {
3318
3361
  throw new Error("QueryController instance is required");
3319
3362
  }
3320
3363
  this.queryController = queryController;
3321
- this.additionalFiltersController = new AdditionalFiltersModalController(
3322
- this.queryController.tableController
3364
+ this.additionalFiltersController = new AdditionalFiltersModal(
3365
+ this.queryController
3323
3366
  );
3324
3367
  this.queryController.tableController.state.props = {
3325
3368
  isMultiple: false
@@ -3351,15 +3394,38 @@ class QueryModalController {
3351
3394
  confirmButtonText: getLabel("btnCon").text,
3352
3395
  cancelButtonText: getLabel("btnCan").text
3353
3396
  },
3354
- NavBar: /* @__PURE__ */ jsx(
3355
- SimpleButton,
3356
- {
3357
- size: "sm",
3358
- variant: "outline",
3359
- onClick: () => this.additionalFiltersController.openModal(),
3360
- children: "Additional filters"
3361
- }
3362
- ),
3397
+ NavBar: /* @__PURE__ */ jsxs(Fragment, { children: [
3398
+ /* @__PURE__ */ jsx(
3399
+ SimpleButton,
3400
+ {
3401
+ variant: "primary-sm",
3402
+ onClick: () => {
3403
+ this.queryController.refresh();
3404
+ },
3405
+ children: getLabel("btnSearch").text
3406
+ }
3407
+ ),
3408
+ /* @__PURE__ */ jsx(
3409
+ SimpleButton,
3410
+ {
3411
+ size: "sm",
3412
+ variant: "outline",
3413
+ onClick: async () => {
3414
+ this.additionalFiltersController.openModal();
3415
+ },
3416
+ children: getLabel("titAdmAdtFilter").text
3417
+ }
3418
+ ),
3419
+ /* @__PURE__ */ jsx(
3420
+ SimpleButton,
3421
+ {
3422
+ size: "sm",
3423
+ variant: "outline",
3424
+ onClick: () => this.queryController.clearFilters(),
3425
+ children: getLabel("btnClearFilter").text
3426
+ }
3427
+ )
3428
+ ] }),
3363
3429
  size: "finder"
3364
3430
  };
3365
3431
  }
@@ -3374,6 +3440,66 @@ class QueryModalController {
3374
3440
  }
3375
3441
  }
3376
3442
 
3443
+ const FilterTypesComponent = observer(
3444
+ ({ filterTypes }) => {
3445
+ return /* @__PURE__ */ jsx(Fragment, { children: filterTypes.conditions.map((f, idx) => {
3446
+ const options = arrayOrArray(f.options.option);
3447
+ return /* @__PURE__ */ jsxs(Label, { children: [
3448
+ /* @__PURE__ */ jsxs(Box, { as: "span", children: [
3449
+ f.text,
3450
+ ":"
3451
+ ] }),
3452
+ /* @__PURE__ */ jsx(
3453
+ Select$1,
3454
+ {
3455
+ title: f.title,
3456
+ onChange: (ev) => {
3457
+ const selectedValue = ev.target.value;
3458
+ filterTypes.conditions[idx].value = selectedValue;
3459
+ },
3460
+ disabled: f.readonly || f.disabled,
3461
+ value: f.value,
3462
+ children: options.map((option) => {
3463
+ return /* @__PURE__ */ jsx("option", { value: option.value, children: option.content }, option.value);
3464
+ })
3465
+ }
3466
+ )
3467
+ ] }, f.name);
3468
+ }) });
3469
+ }
3470
+ );
3471
+
3472
+ var __defProp$3 = Object.defineProperty;
3473
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3474
+ var __publicField$3 = (obj, key, value) => {
3475
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
3476
+ return value;
3477
+ };
3478
+ class FilterTypes {
3479
+ constructor() {
3480
+ __publicField$3(this, "conditions", []);
3481
+ __publicField$3(this, "Component", () => /* @__PURE__ */ jsx(FilterTypesComponent, { filterTypes: this }));
3482
+ makeObservable(this, {
3483
+ conditions: observable
3484
+ });
3485
+ this.initialLoad();
3486
+ }
3487
+ async getFilterTypes() {
3488
+ const result = await ApiaApi$1.post(
3489
+ makeApiaUrl({
3490
+ ajaxUrl: "apia.query.ModalAction.run?",
3491
+ action: "filterOptions"
3492
+ })
3493
+ );
3494
+ if (!result?.data?.form?.elements?.element)
3495
+ return;
3496
+ this.conditions = arrayOrArray(result.data.form.elements.element);
3497
+ }
3498
+ async initialLoad() {
3499
+ await this.getFilterTypes();
3500
+ }
3501
+ }
3502
+
3377
3503
  var __defProp$2 = Object.defineProperty;
3378
3504
  var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3379
3505
  var __publicField$2 = (obj, key, value) => {
@@ -3387,6 +3513,7 @@ class TableController {
3387
3513
  __publicField$2(this, "tableName", `TableController${controllerCount++}`);
3388
3514
  __publicField$2(this, "tableSelectionController");
3389
3515
  __publicField$2(this, "controllerComponent", () => null);
3516
+ __publicField$2(this, "filterTypes", new FilterTypes());
3390
3517
  __publicField$2(this, "state", {
3391
3518
  columns: /* @__PURE__ */ new Map(),
3392
3519
  filters: /* @__PURE__ */ new Map(),
@@ -3394,27 +3521,23 @@ class TableController {
3394
3521
  props: {},
3395
3522
  rows: []
3396
3523
  });
3397
- __publicField$2(this, "Context", observer(({ children }) => {
3398
- const props = toJS(this.state.props);
3524
+ __publicField$2(this, "Context", ({ children }) => {
3525
+ const state = this.state;
3526
+ const props = toJS(state.props);
3399
3527
  return /* @__PURE__ */ jsx(
3400
3528
  ResponsiveTableContext,
3401
3529
  {
3402
3530
  ...props,
3403
- columns: [...toJS(this.state.columns).values()],
3404
- rows: toJS(this.state.rows),
3405
- filters: [...toJS(this.state.filters).values()].map((c) => {
3406
- return {
3407
- id: c.filterState.id,
3408
- column: c.filterState.column,
3409
- asAdditional: c.filterState.isAdditional || this.state.columns.get(c.filterState.column || "")?.hidden
3410
- };
3411
- }),
3412
- FiltersRenderer: (filterId) => this.state.filters.get(filterId).Component,
3531
+ columns: [...toJS(state.columns).values()],
3532
+ rows: [],
3533
+ filters: this.parseFilters(),
3534
+ FiltersRenderer: useCallback(
3535
+ (filterId) => this.state.filters.get(filterId).Component,
3536
+ []
3537
+ ),
3413
3538
  name: this.tableName,
3414
3539
  SelectionHandler: this.controllerComponent,
3415
- onSortChange: () => {
3416
- this.emitter.emit.bind(this.emitter, "onSortChange");
3417
- },
3540
+ onSortChange: this.emitter.emit.bind(this.emitter, "onSortChange"),
3418
3541
  onChangeSelection: this.emitter.emit.bind(
3419
3542
  this.emitter,
3420
3543
  "onChangeSelection"
@@ -3430,7 +3553,7 @@ class TableController {
3430
3553
  children
3431
3554
  }
3432
3555
  );
3433
- }));
3556
+ });
3434
3557
  __publicField$2(this, "Pagination", observer(() => {
3435
3558
  return /* @__PURE__ */ jsx(
3436
3559
  Pagination,
@@ -3454,6 +3577,51 @@ class TableController {
3454
3577
  if (initialState) {
3455
3578
  Object.assign(this.state, initialState);
3456
3579
  }
3580
+ reaction(
3581
+ () => this.state.columns,
3582
+ (columns) => {
3583
+ responsiveTableStore.dispatch(
3584
+ responsiveTableActions.update({
3585
+ tableName: this.tableName,
3586
+ columns: [...toJS(columns).values()]
3587
+ })
3588
+ );
3589
+ }
3590
+ );
3591
+ reaction(
3592
+ () => this.state.filters,
3593
+ () => {
3594
+ responsiveTableStore.dispatch(
3595
+ responsiveTableActions.update({
3596
+ tableName: this.tableName,
3597
+ filters: this.parseFilters()
3598
+ })
3599
+ );
3600
+ }
3601
+ );
3602
+ reaction(
3603
+ () => this.state.rows,
3604
+ (rows) => {
3605
+ responsiveTableStore.dispatch(
3606
+ responsiveTableActions.update({
3607
+ tableName: this.tableName,
3608
+ rows: toJS(rows)
3609
+ })
3610
+ );
3611
+ }
3612
+ );
3613
+ }
3614
+ clearFilters() {
3615
+ [...this.state.filters.values()].forEach((c) => c.filterState.value = "");
3616
+ }
3617
+ parseFilters() {
3618
+ return [...toJS(this.state.filters).values()].map((c) => {
3619
+ return {
3620
+ id: c.filterState.id,
3621
+ column: c.filterState.column,
3622
+ asAdditional: c.filterState.isAdditional || this.state.columns.get(c.filterState.column || "")?.hidden
3623
+ };
3624
+ });
3457
3625
  }
3458
3626
  getTableName() {
3459
3627
  return this.tableName;
@@ -3478,19 +3646,20 @@ var __publicField$1 = (obj, key, value) => {
3478
3646
  };
3479
3647
  class Filter {
3480
3648
  constructor(properties) {
3649
+ __publicField$1(this, "tableName");
3481
3650
  __publicField$1(this, "filterState", {
3482
3651
  runAutomatically: false,
3483
3652
  value: ""
3484
3653
  });
3485
3654
  __publicField$1(this, "Component", observer(({ filter }) => {
3486
- const { onFilterBlur, onFilterChange, onFilterPressEnter } = useResponsiveTableContext();
3655
+ const { onFilterBlur, onFilterPressEnter, name } = useResponsiveTableContext();
3656
+ this.tableName = name;
3487
3657
  return /* @__PURE__ */ jsx(
3488
3658
  Input$1,
3489
3659
  {
3490
3660
  value: this.filterState.value,
3491
3661
  onChange: (ev) => {
3492
3662
  this.filterState.value = ev.target.value;
3493
- onFilterChange?.(filter);
3494
3663
  },
3495
3664
  onKeyDown: (ev) => {
3496
3665
  if (ev.code === "Enter") {
@@ -3505,6 +3674,19 @@ class Filter {
3505
3674
  }));
3506
3675
  Object.assign(this.filterState, properties);
3507
3676
  makeObservable(this, { filterState: observable });
3677
+ reaction(
3678
+ () => this.filterState.value,
3679
+ () => {
3680
+ if (this.tableName) {
3681
+ getResponsiveTableContext(this.tableName).onFilterChange?.({
3682
+ id: properties.id,
3683
+ column: properties.column
3684
+ });
3685
+ }
3686
+ }
3687
+ );
3688
+ }
3689
+ focus() {
3508
3690
  }
3509
3691
  }
3510
3692
 
@@ -3523,10 +3705,12 @@ class QueryController {
3523
3705
  __publicField(this, "tableController", new TableController());
3524
3706
  __publicField(this, "executeRefresh", throttle(
3525
3707
  async () => {
3526
- const refresh = await ApiaApi$1.post(
3527
- makeApiaUrl(this.getRefreshParameters())
3528
- );
3529
- this.parseRefreshResponse(refresh?.data);
3708
+ if (!this.areRequiredFilters()) {
3709
+ const refresh = await ApiaApi$1.post(
3710
+ makeApiaUrl(this.getRefreshParameters())
3711
+ );
3712
+ this.parseRefreshResponse(refresh?.data);
3713
+ }
3530
3714
  },
3531
3715
  300,
3532
3716
  { leading: false, trailing: true }
@@ -3564,6 +3748,12 @@ class QueryController {
3564
3748
  forcePagination: true
3565
3749
  };
3566
3750
  }
3751
+ getClearFiltersParameters() {
3752
+ return {
3753
+ ajaxUrl: this.ajaxUrl,
3754
+ action: "clearFilter"
3755
+ };
3756
+ }
3567
3757
  getPageParameters() {
3568
3758
  return {
3569
3759
  ajaxUrl: this.ajaxUrl,
@@ -3635,7 +3825,8 @@ class QueryController {
3635
3825
  isDynamic: false,
3636
3826
  title: typedResponse.queryData.title,
3637
3827
  openFiltersAutomatically: typedResponse.filters.openFiltersAutomatically,
3638
- runFiltersAutomatically: typedResponse.filters.runFiltersAutomatically
3828
+ runFiltersAutomatically: typedResponse.filters.runFiltersAutomatically,
3829
+ hideFilterTypes: typedResponse.filters.hideFilterTypes
3639
3830
  };
3640
3831
  }
3641
3832
  parseRefreshResponse(response) {
@@ -3690,6 +3881,16 @@ class QueryController {
3690
3881
  updateRows(rows) {
3691
3882
  this.tableController.state.rows = rows;
3692
3883
  }
3884
+ async clearFilters() {
3885
+ const result = await ApiaApi$1.post(
3886
+ makeApiaUrl({ ...this.getClearFiltersParameters() })
3887
+ );
3888
+ if (!result?.data)
3889
+ return;
3890
+ const structure = this.parseLoadStructureResponse(result.data);
3891
+ this.parseStructure(structure);
3892
+ this.refresh();
3893
+ }
3693
3894
  async initialLoad() {
3694
3895
  if (this.initializing && !this.hasInited) {
3695
3896
  throw new Error("Cannot initialize the query twice");
@@ -3708,6 +3909,11 @@ class QueryController {
3708
3909
  );
3709
3910
  this.parseRefreshResponse(page?.data);
3710
3911
  }
3912
+ areRequiredFilters() {
3913
+ return !![...this.tableController.state.filters.values()].find(
3914
+ (c) => c.filterState.required && !c.filterState.value && !c.filterState.isHidden
3915
+ );
3916
+ }
3711
3917
  async refresh() {
3712
3918
  return this.executeRefresh();
3713
3919
  }
@@ -3719,5 +3925,5 @@ class QueryController {
3719
3925
  }
3720
3926
  }
3721
3927
 
3722
- export { ApiaApi$1 as ApiaApi, ApiaApiHandler, QueryController, QueryModalController, getFunction, getModal, makeApiaUrl };
3928
+ export { ApiaApi$1 as ApiaApi, ApiaApiHandler, QueryController, QueryModalController, getFunction, getModal, makeApiaUrl, parseSuccessfulResponse };
3723
3929
  //# sourceMappingURL=index.js.map