@infomaximum/widget-sdk 3.38.2 → 3.40.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
@@ -863,194 +863,6 @@ interface IBaseWidgetSettings {
863
863
  displayConditionComment?: string;
864
864
  }
865
865
 
866
- interface ILens<T extends TNullable<object>, Value> {
867
- get(obj: T): TNullable<Value>;
868
- set(obj: T, value: Value): void;
869
- }
870
- type TValuePath = string | string[];
871
- type TRecordAccessor<Settings extends object, Value> = TValuePath | ILens<Settings, Value>;
872
- interface IDisplayPredicate<Settings> {
873
- (s: Settings): boolean;
874
- }
875
- /** Конфигурация разделителя */
876
- interface IDividerRecord<Settings extends object = object> {
877
- type: "divider";
878
- shouldDisplay?: IDisplayPredicate<Settings>;
879
- }
880
- /** Конфигурация набора групп */
881
- interface IGroupSetRecord {
882
- type: "groupSet";
883
- groupSetKey: string;
884
- }
885
- type TEmptyRecord = boolean | null | undefined;
886
- /** Набор конфигураций, которые могут встречаться на уровне виджета */
887
- type TWidgetLevelRecord<Settings extends object> = IControlRecord<Settings, any, EControlType> | IDividerRecord<Settings> | IGroupSetRecord | TEmptyRecord;
888
- /** Набор конфигураций, которые могут встречаться на уровне группы */
889
- type TGroupLevelRecord<LevelGroupSettings extends object> = IControlRecord<LevelGroupSettings, any, EControlType> | IDividerRecord<LevelGroupSettings> | TEmptyRecord;
890
- interface ISelectOption {
891
- value: string;
892
- label: string;
893
- disabled?: boolean;
894
- }
895
- declare enum ECustomSelectOptionTypes {
896
- DIVIDER = "DIVIDER",
897
- SYSTEM = "SYSTEM",
898
- GROUP = "GROUP",
899
- BRANCH = "BRANCH",
900
- LEAF = "LEAF"
901
- }
902
- declare enum ECustomSelectTemplates {
903
- FORMULA = "FORMULA",
904
- DIMENSION_GROUPS = "DIMENSION_GROUPS"
905
- }
906
- interface ICustomSelectDividerOption {
907
- type: ECustomSelectOptionTypes.DIVIDER;
908
- }
909
- interface ICustomSelectSystemOption {
910
- type: ECustomSelectOptionTypes.SYSTEM;
911
- template: ECustomSelectTemplates;
912
- }
913
- interface ICustomSelectGroupOption {
914
- type: ECustomSelectOptionTypes.GROUP;
915
- label: string;
916
- options: ICustomSelectOption[];
917
- icon: string;
918
- }
919
- type TCustomSelectFetchOptions = () => Promise<ICustomSelectOption[]>;
920
- type TCustomSelectChildOptions = ICustomSelectOption[] | TCustomSelectFetchOptions;
921
- interface ICustomSelectBranchOption {
922
- type: ECustomSelectOptionTypes.BRANCH;
923
- label: string;
924
- options: TCustomSelectChildOptions;
925
- icon?: string;
926
- disabled?: boolean;
927
- }
928
- interface ICustomSelectLeafOption {
929
- type: ECustomSelectOptionTypes.LEAF;
930
- label: string;
931
- value: string;
932
- onSelect: <T = object>(value: string, update: <R extends object>(f: (prevItems: (T | R)[]) => (T | R)[]) => void) => void;
933
- icon?: string;
934
- disabled?: boolean;
935
- }
936
- type ICustomSelectOption = ICustomSelectDividerOption | ICustomSelectSystemOption | ICustomSelectGroupOption | ICustomSelectBranchOption | ICustomSelectLeafOption;
937
- interface ICustomAddButtonProps {
938
- options: TCustomSelectChildOptions;
939
- hasDropdown?: boolean;
940
- onClick?: ICustomSelectLeafOption["onSelect"];
941
- }
942
- interface IWidgetIndicatorMenuConfig {
943
- hideTablesColumnsOptions?: boolean;
944
- hideCommonOptions?: boolean;
945
- hideQuantityOption?: boolean;
946
- }
947
- interface IMeasureMenuConfig extends IWidgetIndicatorMenuConfig {
948
- }
949
- interface ISortingMenuConfig extends IWidgetIndicatorMenuConfig {
950
- }
951
- /** Кнопка добавления группы в набор */
952
- type TAddButton = {
953
- title: string;
954
- indicatorType: Exclude<EWidgetIndicatorType, EWidgetIndicatorType.CUSTOM | EWidgetIndicatorType.MEASURE | EWidgetIndicatorType.SORTING>;
955
- } | {
956
- title: string;
957
- indicatorType: EWidgetIndicatorType.CUSTOM;
958
- props: ICustomAddButtonProps;
959
- } | {
960
- title: string;
961
- indicatorType: EWidgetIndicatorType.MEASURE;
962
- menuConfig?: IMeasureMenuConfig;
963
- } | {
964
- title: string;
965
- indicatorType: EWidgetIndicatorType.SORTING;
966
- menuConfig?: ISortingMenuConfig;
967
- };
968
- interface IAutoIdentifiedArrayItem {
969
- /**
970
- * Идентификатор, добавляемый системой "на лету" для удобства разработки, не сохраняется на сервер.
971
- * Гарантируется уникальность id в пределах settings виджета.
972
- */
973
- id: number;
974
- }
975
- interface IGroupSettings extends IAutoIdentifiedArrayItem, Record<string, any> {
976
- }
977
- /** Конфигурация набора групп */
978
- interface IGroupSetDescription<Settings extends object, GroupSettings extends object> {
979
- /** Заголовок */
980
- title: string;
981
- /** Максимальное количество групп в наборе */
982
- maxCount: number;
983
- /** Описание доступа к настройкам групп */
984
- accessor: TRecordAccessor<Settings, GroupSettings[]>;
985
- /** Кнопки добавления группы в набор */
986
- addButtons: TAddButton[];
987
- /** Создать элементы управления внутри группы (для вкладки настроек данных) */
988
- createDataRecords?(group: IGroupSettings): TGroupLevelRecord<GroupSettings>[];
989
- /** Создать элементы управления внутри группы (для вкладки настроек отображения) */
990
- createDisplayRecords?(group: IGroupSettings): TGroupLevelRecord<GroupSettings>[];
991
- /** Получить название для плашки */
992
- getGroupTitle?(group: IGroupSettings): string;
993
- /** Валидная ли группа */
994
- isValid?(group: IGroupSettings): boolean;
995
- /** Находится ли группа в состоянии загрузки */
996
- isLoading?(group: IGroupSettings): boolean;
997
- }
998
- /** Конфигурация левой панели */
999
- interface IPanelDescription<Settings extends object, GroupSettings extends IGroupSettings = IGroupSettings> {
1000
- /** Добавить заголовок для виджета */
1001
- useHeader?: boolean;
1002
- /** Добавить описание для виджета */
1003
- useMarkdown?: boolean;
1004
- /** Конфигурация настроек данных виджета */
1005
- dataRecords?: TWidgetLevelRecord<Settings>[];
1006
- /** Конфигурация настроек отображения виджета */
1007
- displayRecords?: TWidgetLevelRecord<Settings>[];
1008
- /** Конфигурации наборов групп */
1009
- groupSetDescriptions?: Record<string, IGroupSetDescription<Settings, GroupSettings>>;
1010
- }
1011
- interface IWidgetProcess {
1012
- guid: string;
1013
- /** Имя процесса */
1014
- name: string;
1015
- /** Формула имени события */
1016
- eventNameFormula: string;
1017
- /** Формула времени события */
1018
- eventTimeFormula: string;
1019
- /** Формула CaseId события */
1020
- eventCaseIdFormula: string;
1021
- /** Формула CaseId кейса */
1022
- caseCaseIdFormula: string;
1023
- /** Имя колонки CaseId события */
1024
- eventCaseIdColumnName: string;
1025
- /** Тип данных CaseId */
1026
- caseIdDataType: ESimpleDataType;
1027
- /** Тип данных времени события */
1028
- eventTimeDataType: ESimpleDataType;
1029
- /** Является ли процесс валидным */
1030
- isValid: boolean;
1031
- }
1032
- /** Конфигурация левой панели при погружении на уровень вниз */
1033
- interface IDivePanelDescription<Settings extends object, GroupSettings extends IGroupSettings = IGroupSettings> extends IPanelDescription<Settings, GroupSettings> {
1034
- }
1035
- interface IPanelDescriptionCreator<Settings extends IBaseWidgetSettings, GroupSettings extends IGroupSettings> {
1036
- (context: IWidgetsContext, panelSettings: Settings): IPanelDescription<Settings, GroupSettings>;
1037
- }
1038
-
1039
- interface IWidgetPlaceholderController {
1040
- setError(value: Error | null): void;
1041
- setConfigured(value: boolean): void;
1042
- setDisplay(value: boolean): void;
1043
- setEmpty(value: boolean): void;
1044
- setOverlay(value: boolean): void;
1045
- }
1046
- interface IWidgetPlaceholderValues {
1047
- error: Error | null;
1048
- isConfigured: boolean;
1049
- isDisplay: boolean | undefined;
1050
- isEmpty: boolean;
1051
- isOverlay: boolean;
1052
- }
1053
-
1054
866
  /** Вид переменной для калькулятора */
1055
867
  interface ICalculatorVariable {
1056
868
  dataType: ESimpleDataType;
@@ -1282,7 +1094,7 @@ declare function mapEventMeasuresToInputs<T extends IProcessIndicator>(indicator
1282
1094
  * @param measuresInOriginalOrder меры виджета (конкретная мера будет браться по индексу)
1283
1095
  * @returns
1284
1096
  */
1285
- declare function mapSortingToInputs(sortingIndicators: IWidgetSortingIndicator[] | undefined, dimensionsInOriginalOrder: IWidgetDimension[] | undefined, measuresInOriginalOrder: IWidgetMeasure[] | undefined, variables: Map<string, TWidgetVariable>): ISortOrder[];
1097
+ declare function mapSortingToInputs(sortingIndicators: IWidgetSortingIndicator[] | undefined, dimensionsInOriginalOrder: IWidgetDimension[] | undefined, measuresInOriginalOrder: IWidgetMeasure[] | undefined, variables: Map<string, TWidgetVariable>, withDefaultSortOrder?: boolean): ISortOrder[];
1286
1098
 
1287
1099
  /**
1288
1100
  * Выбрать активный разрез иерархии на основе активных фильтров.
@@ -1317,6 +1129,194 @@ interface ICalculatorFactory {
1317
1129
  type: () => ITypeCalculator;
1318
1130
  }
1319
1131
 
1132
+ interface ILens<T extends TNullable<object>, Value> {
1133
+ get(obj: T): TNullable<Value>;
1134
+ set(obj: T, value: Value): void;
1135
+ }
1136
+ type TValuePath = string | string[];
1137
+ type TRecordAccessor<Settings extends object, Value> = TValuePath | ILens<Settings, Value>;
1138
+ interface IDisplayPredicate<Settings> {
1139
+ (s: Settings): boolean;
1140
+ }
1141
+ /** Конфигурация разделителя */
1142
+ interface IDividerRecord<Settings extends object = object> {
1143
+ type: "divider";
1144
+ shouldDisplay?: IDisplayPredicate<Settings>;
1145
+ }
1146
+ /** Конфигурация набора групп */
1147
+ interface IGroupSetRecord {
1148
+ type: "groupSet";
1149
+ groupSetKey: string;
1150
+ }
1151
+ type TEmptyRecord = boolean | null | undefined;
1152
+ /** Набор конфигураций, которые могут встречаться на уровне виджета */
1153
+ type TWidgetLevelRecord<Settings extends object> = IControlRecord<Settings, any, EControlType> | IDividerRecord<Settings> | IGroupSetRecord | TEmptyRecord;
1154
+ /** Набор конфигураций, которые могут встречаться на уровне группы */
1155
+ type TGroupLevelRecord<LevelGroupSettings extends object> = IControlRecord<LevelGroupSettings, any, EControlType> | IDividerRecord<LevelGroupSettings> | TEmptyRecord;
1156
+ interface ISelectOption {
1157
+ value: string;
1158
+ label: string;
1159
+ disabled?: boolean;
1160
+ }
1161
+ declare enum ECustomSelectOptionTypes {
1162
+ DIVIDER = "DIVIDER",
1163
+ SYSTEM = "SYSTEM",
1164
+ GROUP = "GROUP",
1165
+ BRANCH = "BRANCH",
1166
+ LEAF = "LEAF"
1167
+ }
1168
+ declare enum ECustomSelectTemplates {
1169
+ FORMULA = "FORMULA",
1170
+ DIMENSION_GROUPS = "DIMENSION_GROUPS"
1171
+ }
1172
+ interface ICustomSelectDividerOption {
1173
+ type: ECustomSelectOptionTypes.DIVIDER;
1174
+ }
1175
+ interface ICustomSelectSystemOption {
1176
+ type: ECustomSelectOptionTypes.SYSTEM;
1177
+ template: ECustomSelectTemplates;
1178
+ }
1179
+ interface ICustomSelectGroupOption {
1180
+ type: ECustomSelectOptionTypes.GROUP;
1181
+ label: string;
1182
+ options: ICustomSelectOption[];
1183
+ icon: string;
1184
+ }
1185
+ type TCustomSelectFetchOptions = () => Promise<ICustomSelectOption[]>;
1186
+ type TCustomSelectChildOptions = ICustomSelectOption[] | TCustomSelectFetchOptions;
1187
+ interface ICustomSelectBranchOption {
1188
+ type: ECustomSelectOptionTypes.BRANCH;
1189
+ label: string;
1190
+ options: TCustomSelectChildOptions;
1191
+ icon?: string;
1192
+ disabled?: boolean;
1193
+ }
1194
+ interface ICustomSelectLeafOption {
1195
+ type: ECustomSelectOptionTypes.LEAF;
1196
+ label: string;
1197
+ value: string;
1198
+ onSelect: <T extends object>(value: string, update: <R extends object>(f: (prevItems: (T | R)[]) => (T | R)[]) => void) => void;
1199
+ icon?: string;
1200
+ disabled?: boolean;
1201
+ }
1202
+ type ICustomSelectOption = ICustomSelectDividerOption | ICustomSelectSystemOption | ICustomSelectGroupOption | ICustomSelectBranchOption | ICustomSelectLeafOption;
1203
+ interface ICustomAddButtonProps {
1204
+ options: TCustomSelectChildOptions;
1205
+ hasDropdown?: boolean;
1206
+ onClick?: ICustomSelectLeafOption["onSelect"];
1207
+ }
1208
+ interface IWidgetIndicatorMenuConfig {
1209
+ hideTablesColumnsOptions?: boolean;
1210
+ hideCommonOptions?: boolean;
1211
+ hideQuantityOption?: boolean;
1212
+ }
1213
+ interface IMeasureMenuConfig extends IWidgetIndicatorMenuConfig {
1214
+ }
1215
+ interface ISortingMenuConfig extends IWidgetIndicatorMenuConfig {
1216
+ }
1217
+ /** Кнопка добавления группы в набор */
1218
+ type TAddButton = {
1219
+ title: string;
1220
+ indicatorType: Exclude<EWidgetIndicatorType, EWidgetIndicatorType.CUSTOM | EWidgetIndicatorType.MEASURE | EWidgetIndicatorType.SORTING>;
1221
+ } | {
1222
+ title: string;
1223
+ indicatorType: EWidgetIndicatorType.CUSTOM;
1224
+ props: ICustomAddButtonProps;
1225
+ } | {
1226
+ title: string;
1227
+ indicatorType: EWidgetIndicatorType.MEASURE;
1228
+ menuConfig?: IMeasureMenuConfig;
1229
+ } | {
1230
+ title: string;
1231
+ indicatorType: EWidgetIndicatorType.SORTING;
1232
+ menuConfig?: ISortingMenuConfig;
1233
+ };
1234
+ interface IAutoIdentifiedArrayItem {
1235
+ /**
1236
+ * Идентификатор, добавляемый системой "на лету" для удобства разработки, не сохраняется на сервер.
1237
+ * Гарантируется уникальность id в пределах settings виджета.
1238
+ */
1239
+ id: number;
1240
+ }
1241
+ interface IGroupSettings extends IAutoIdentifiedArrayItem, Record<string, any> {
1242
+ }
1243
+ /** Конфигурация набора групп */
1244
+ interface IGroupSetDescription<Settings extends object, GroupSettings extends object> {
1245
+ /** Заголовок */
1246
+ title: string;
1247
+ /** Максимальное количество групп в наборе */
1248
+ maxCount: number;
1249
+ /** Описание доступа к настройкам групп */
1250
+ accessor: TRecordAccessor<Settings, GroupSettings[]>;
1251
+ /** Кнопки добавления группы в набор */
1252
+ addButtons: TAddButton[];
1253
+ /** Создать элементы управления внутри группы (для вкладки настроек данных) */
1254
+ createDataRecords?(group: IGroupSettings): TGroupLevelRecord<GroupSettings>[];
1255
+ /** Создать элементы управления внутри группы (для вкладки настроек отображения) */
1256
+ createDisplayRecords?(group: IGroupSettings): TGroupLevelRecord<GroupSettings>[];
1257
+ /** Получить название для плашки */
1258
+ getGroupTitle?(group: IGroupSettings): string;
1259
+ /** Валидная ли группа */
1260
+ isValid?(group: IGroupSettings): boolean;
1261
+ /** Находится ли группа в состоянии загрузки */
1262
+ isLoading?(group: IGroupSettings): boolean;
1263
+ }
1264
+ /** Конфигурация левой панели */
1265
+ interface IPanelDescription<Settings extends object, GroupSettings extends IGroupSettings = IGroupSettings> {
1266
+ /** Добавить заголовок для виджета */
1267
+ useHeader?: boolean;
1268
+ /** Добавить описание для виджета */
1269
+ useMarkdown?: boolean;
1270
+ /** Конфигурация настроек данных виджета */
1271
+ dataRecords?: TWidgetLevelRecord<Settings>[];
1272
+ /** Конфигурация настроек отображения виджета */
1273
+ displayRecords?: TWidgetLevelRecord<Settings>[];
1274
+ /** Конфигурации наборов групп */
1275
+ groupSetDescriptions?: Record<string, IGroupSetDescription<Settings, GroupSettings>>;
1276
+ }
1277
+ interface IWidgetProcess {
1278
+ guid: string;
1279
+ /** Имя процесса */
1280
+ name: string;
1281
+ /** Формула имени события */
1282
+ eventNameFormula: string;
1283
+ /** Формула времени события */
1284
+ eventTimeFormula: string;
1285
+ /** Формула CaseId события */
1286
+ eventCaseIdFormula: string;
1287
+ /** Формула CaseId кейса */
1288
+ caseCaseIdFormula: string;
1289
+ /** Имя колонки CaseId события */
1290
+ eventCaseIdColumnName: string;
1291
+ /** Тип данных CaseId */
1292
+ caseIdDataType: ESimpleDataType;
1293
+ /** Тип данных времени события */
1294
+ eventTimeDataType: ESimpleDataType;
1295
+ /** Является ли процесс валидным */
1296
+ isValid: boolean;
1297
+ }
1298
+ /** Конфигурация левой панели при погружении на уровень вниз */
1299
+ interface IDivePanelDescription<Settings extends object, GroupSettings extends IGroupSettings = IGroupSettings> extends IPanelDescription<Settings, GroupSettings> {
1300
+ }
1301
+ interface IPanelDescriptionCreator<Settings extends IBaseWidgetSettings, GroupSettings extends IGroupSettings> {
1302
+ (context: IWidgetsContext, panelSettings: Settings, calculatorFactory: ICalculatorFactory): IPanelDescription<Settings, GroupSettings>;
1303
+ }
1304
+
1305
+ interface IWidgetPlaceholderController {
1306
+ setError(value: Error | null): void;
1307
+ setConfigured(value: boolean): void;
1308
+ setDisplay(value: boolean): void;
1309
+ setEmpty(value: boolean): void;
1310
+ setOverlay(value: boolean): void;
1311
+ }
1312
+ interface IWidgetPlaceholderValues {
1313
+ error: Error | null;
1314
+ isConfigured: boolean;
1315
+ isDisplay: boolean | undefined;
1316
+ isEmpty: boolean;
1317
+ isOverlay: boolean;
1318
+ }
1319
+
1320
1320
  interface IDefinition<WidgetSettings extends IBaseWidgetSettings, GroupSettings extends IGroupSettings> {
1321
1321
  /** иконка виджета отображаемая в системе (в base64, svg или png) */
1322
1322
  icon?: string;
package/dist/index.esm.js CHANGED
@@ -841,6 +841,55 @@ function mapEventMeasuresToInputs(indicators, process, variables, addFormulas) {
841
841
  });
842
842
  }
843
843
 
844
+ var ESortDirection;
845
+ (function (ESortDirection) {
846
+ ESortDirection["descend"] = "DESC";
847
+ ESortDirection["ascend"] = "ASC";
848
+ ESortDirection["ASC"] = "ascend";
849
+ ESortDirection["DESC"] = "descend";
850
+ })(ESortDirection || (ESortDirection = {}));
851
+
852
+ var getDefaultSortOrder = function (dimensions, measures) {
853
+ /** Если есть условие отображения, то не делаем автосортировку */
854
+ if (dimensions.some(function (dimension) {
855
+ return dimension.displayCondition &&
856
+ dimension.displayCondition.mode !== EDisplayConditionMode.DISABLED;
857
+ })) {
858
+ return [];
859
+ }
860
+ /** Если есть временной разрез, то автосортировка по первому такому разрезу (по возрастанию) */
861
+ var timeDimension = dimensions.find(function (dimension) {
862
+ return dimension.format &&
863
+ [
864
+ EFormatTypes.DATE,
865
+ EFormatTypes.MONTH,
866
+ EFormatTypes.DATETIME,
867
+ EFormatTypes.DAY_OF_WEEK,
868
+ EFormatTypes.HOUR,
869
+ EFormatTypes.MONTH_YEAR,
870
+ EFormatTypes.YEAR,
871
+ EFormatTypes.QUARTER,
872
+ EFormatTypes.QUARTER_YEAR,
873
+ EFormatTypes.DAY_OF_MONTH,
874
+ EFormatTypes.WEEK,
875
+ ].includes(dimension.format);
876
+ });
877
+ if (timeDimension) {
878
+ return [{ formula: getDimensionFormula(timeDimension), direction: ESortDirection.ascend }];
879
+ }
880
+ if (measures.length > 0) {
881
+ var firstMeasure = measures[0];
882
+ if (firstMeasure) {
883
+ return [
884
+ {
885
+ direction: ESortDirection.descend,
886
+ formula: getMeasureFormula(firstMeasure),
887
+ },
888
+ ];
889
+ }
890
+ }
891
+ return [];
892
+ };
844
893
  /**
845
894
  * Преобразовать объекты сортировок из settings виджета в sortOrders вычислителя
846
895
  * @param sortingIndicators объекты сортировок из settings виджета
@@ -848,11 +897,12 @@ function mapEventMeasuresToInputs(indicators, process, variables, addFormulas) {
848
897
  * @param measuresInOriginalOrder меры виджета (конкретная мера будет браться по индексу)
849
898
  * @returns
850
899
  */
851
- function mapSortingToInputs(sortingIndicators, dimensionsInOriginalOrder, measuresInOriginalOrder, variables) {
900
+ function mapSortingToInputs(sortingIndicators, dimensionsInOriginalOrder, measuresInOriginalOrder, variables, withDefaultSortOrder) {
852
901
  if (sortingIndicators === void 0) { sortingIndicators = []; }
853
902
  if (dimensionsInOriginalOrder === void 0) { dimensionsInOriginalOrder = []; }
854
903
  if (measuresInOriginalOrder === void 0) { measuresInOriginalOrder = []; }
855
- return compactMap(sortingIndicators, function (_a) {
904
+ if (withDefaultSortOrder === void 0) { withDefaultSortOrder = true; }
905
+ var sortOrder = compactMap(sortingIndicators, function (_a) {
856
906
  var _b;
857
907
  var value = _a.value, direction = _a.direction;
858
908
  if (value.mode === ESortingValueModes.FORMULA ||
@@ -884,6 +934,9 @@ function mapSortingToInputs(sortingIndicators, dimensionsInOriginalOrder, measur
884
934
  return measure && { formula: getMeasureFormula(measure), direction: direction };
885
935
  }
886
936
  });
937
+ return withDefaultSortOrder && sortOrder.length === 0
938
+ ? getDefaultSortOrder(dimensionsInOriginalOrder, measuresInOriginalOrder)
939
+ : sortOrder;
887
940
  }
888
941
 
889
942
  /**
@@ -977,14 +1030,6 @@ var ECustomSelectTemplates;
977
1030
  ECustomSelectTemplates["DIMENSION_GROUPS"] = "DIMENSION_GROUPS";
978
1031
  })(ECustomSelectTemplates || (ECustomSelectTemplates = {}));
979
1032
 
980
- var ESortDirection;
981
- (function (ESortDirection) {
982
- ESortDirection["descend"] = "DESC";
983
- ESortDirection["ascend"] = "ASC";
984
- ESortDirection["ASC"] = "ascend";
985
- ESortDirection["DESC"] = "descend";
986
- })(ESortDirection || (ESortDirection = {}));
987
-
988
1033
  var findFilterByFormula = function (filters, formula) {
989
1034
  var _a;
990
1035
  return ((_a = filters.find(function (filter) {
package/dist/index.js CHANGED
@@ -842,6 +842,55 @@ function mapEventMeasuresToInputs(indicators, process, variables, addFormulas) {
842
842
  });
843
843
  }
844
844
 
845
+ exports.ESortDirection = void 0;
846
+ (function (ESortDirection) {
847
+ ESortDirection["descend"] = "DESC";
848
+ ESortDirection["ascend"] = "ASC";
849
+ ESortDirection["ASC"] = "ascend";
850
+ ESortDirection["DESC"] = "descend";
851
+ })(exports.ESortDirection || (exports.ESortDirection = {}));
852
+
853
+ var getDefaultSortOrder = function (dimensions, measures) {
854
+ /** Если есть условие отображения, то не делаем автосортировку */
855
+ if (dimensions.some(function (dimension) {
856
+ return dimension.displayCondition &&
857
+ dimension.displayCondition.mode !== exports.EDisplayConditionMode.DISABLED;
858
+ })) {
859
+ return [];
860
+ }
861
+ /** Если есть временной разрез, то автосортировка по первому такому разрезу (по возрастанию) */
862
+ var timeDimension = dimensions.find(function (dimension) {
863
+ return dimension.format &&
864
+ [
865
+ exports.EFormatTypes.DATE,
866
+ exports.EFormatTypes.MONTH,
867
+ exports.EFormatTypes.DATETIME,
868
+ exports.EFormatTypes.DAY_OF_WEEK,
869
+ exports.EFormatTypes.HOUR,
870
+ exports.EFormatTypes.MONTH_YEAR,
871
+ exports.EFormatTypes.YEAR,
872
+ exports.EFormatTypes.QUARTER,
873
+ exports.EFormatTypes.QUARTER_YEAR,
874
+ exports.EFormatTypes.DAY_OF_MONTH,
875
+ exports.EFormatTypes.WEEK,
876
+ ].includes(dimension.format);
877
+ });
878
+ if (timeDimension) {
879
+ return [{ formula: getDimensionFormula(timeDimension), direction: exports.ESortDirection.ascend }];
880
+ }
881
+ if (measures.length > 0) {
882
+ var firstMeasure = measures[0];
883
+ if (firstMeasure) {
884
+ return [
885
+ {
886
+ direction: exports.ESortDirection.descend,
887
+ formula: getMeasureFormula(firstMeasure),
888
+ },
889
+ ];
890
+ }
891
+ }
892
+ return [];
893
+ };
845
894
  /**
846
895
  * Преобразовать объекты сортировок из settings виджета в sortOrders вычислителя
847
896
  * @param sortingIndicators объекты сортировок из settings виджета
@@ -849,11 +898,12 @@ function mapEventMeasuresToInputs(indicators, process, variables, addFormulas) {
849
898
  * @param measuresInOriginalOrder меры виджета (конкретная мера будет браться по индексу)
850
899
  * @returns
851
900
  */
852
- function mapSortingToInputs(sortingIndicators, dimensionsInOriginalOrder, measuresInOriginalOrder, variables) {
901
+ function mapSortingToInputs(sortingIndicators, dimensionsInOriginalOrder, measuresInOriginalOrder, variables, withDefaultSortOrder) {
853
902
  if (sortingIndicators === void 0) { sortingIndicators = []; }
854
903
  if (dimensionsInOriginalOrder === void 0) { dimensionsInOriginalOrder = []; }
855
904
  if (measuresInOriginalOrder === void 0) { measuresInOriginalOrder = []; }
856
- return compactMap(sortingIndicators, function (_a) {
905
+ if (withDefaultSortOrder === void 0) { withDefaultSortOrder = true; }
906
+ var sortOrder = compactMap(sortingIndicators, function (_a) {
857
907
  var _b;
858
908
  var value = _a.value, direction = _a.direction;
859
909
  if (value.mode === exports.ESortingValueModes.FORMULA ||
@@ -885,6 +935,9 @@ function mapSortingToInputs(sortingIndicators, dimensionsInOriginalOrder, measur
885
935
  return measure && { formula: getMeasureFormula(measure), direction: direction };
886
936
  }
887
937
  });
938
+ return withDefaultSortOrder && sortOrder.length === 0
939
+ ? getDefaultSortOrder(dimensionsInOriginalOrder, measuresInOriginalOrder)
940
+ : sortOrder;
888
941
  }
889
942
 
890
943
  /**
@@ -978,14 +1031,6 @@ exports.ECustomSelectTemplates = void 0;
978
1031
  ECustomSelectTemplates["DIMENSION_GROUPS"] = "DIMENSION_GROUPS";
979
1032
  })(exports.ECustomSelectTemplates || (exports.ECustomSelectTemplates = {}));
980
1033
 
981
- exports.ESortDirection = void 0;
982
- (function (ESortDirection) {
983
- ESortDirection["descend"] = "DESC";
984
- ESortDirection["ascend"] = "ASC";
985
- ESortDirection["ASC"] = "ascend";
986
- ESortDirection["DESC"] = "descend";
987
- })(exports.ESortDirection || (exports.ESortDirection = {}));
988
-
989
1034
  var findFilterByFormula = function (filters, formula) {
990
1035
  var _a;
991
1036
  return ((_a = filters.find(function (filter) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infomaximum/widget-sdk",
3
- "version": "3.38.2",
3
+ "version": "3.40.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,6 +25,7 @@
25
25
  "@rollup/plugin-commonjs": "25.0.7",
26
26
  "@rollup/plugin-node-resolve": "15.2.3",
27
27
  "@rollup/plugin-typescript": "11.1.5",
28
+ "core-js": "^3.38.0",
28
29
  "prettier": "3.2.5",
29
30
  "rollup": "4.14.3",
30
31
  "rollup-plugin-delete": "2.0.0",