@lightdash/common 0.1357.1 → 0.1359.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/types/catalog.d.ts +15 -4
- package/dist/types/catalog.js +5 -1
- package/dist/utils/filters.d.ts +3 -0
- package/dist/utils/filters.js +35 -1
- package/package.json +1 -1
package/dist/types/catalog.d.ts
CHANGED
@@ -24,6 +24,15 @@ export type ApiCatalogSearch = {
|
|
24
24
|
filter?: CatalogFilter;
|
25
25
|
catalogTags?: string[];
|
26
26
|
};
|
27
|
+
type EmojiIcon = {
|
28
|
+
unicode: string;
|
29
|
+
};
|
30
|
+
type CustomIcon = {
|
31
|
+
url: string;
|
32
|
+
};
|
33
|
+
export type CatalogItemIcon = EmojiIcon | CustomIcon;
|
34
|
+
export declare const isEmojiIcon: (icon: CatalogItemIcon | null) => icon is EmojiIcon;
|
35
|
+
export declare const isCustomIcon: (icon: CatalogItemIcon | null) => icon is CustomIcon;
|
27
36
|
export type CatalogField = Pick<Field, 'name' | 'label' | 'fieldType' | 'tableLabel' | 'description'> & Pick<Dimension, 'requiredAttributes'> & {
|
28
37
|
catalogSearchUuid: string;
|
29
38
|
type: CatalogType.Field;
|
@@ -33,6 +42,7 @@ export type CatalogField = Pick<Field, 'name' | 'label' | 'fieldType' | 'tableLa
|
|
33
42
|
tags?: string[];
|
34
43
|
categories: Pick<Tag, 'name' | 'color' | 'tagUuid'>[];
|
35
44
|
chartUsage: number | undefined;
|
45
|
+
icon: CatalogItemIcon | null;
|
36
46
|
};
|
37
47
|
export type CatalogTable = Pick<TableBase, 'name' | 'label' | 'groupLabel' | 'description' | 'requiredAttributes'> & {
|
38
48
|
catalogSearchUuid: string;
|
@@ -43,6 +53,7 @@ export type CatalogTable = Pick<TableBase, 'name' | 'label' | 'groupLabel' | 'de
|
|
43
53
|
categories: Pick<Tag, 'name' | 'color' | 'tagUuid'>[];
|
44
54
|
joinedTables?: CompiledExploreJoin[];
|
45
55
|
chartUsage: number | undefined;
|
56
|
+
icon: CatalogItemIcon | null;
|
46
57
|
};
|
47
58
|
export type CatalogItem = CatalogField | CatalogTable;
|
48
59
|
export type ApiCatalogResults = CatalogItem[];
|
@@ -75,12 +86,9 @@ export type CatalogFieldMap = {
|
|
75
86
|
cachedExploreUuid: string;
|
76
87
|
};
|
77
88
|
};
|
78
|
-
export type CatalogItemWithTagUuids = {
|
79
|
-
catalogSearchUuid: string;
|
89
|
+
export type CatalogItemWithTagUuids = Pick<CatalogItem, 'catalogSearchUuid' | 'name' | 'type'> & {
|
80
90
|
cachedExploreUuid: string;
|
81
91
|
projectUuid: string;
|
82
|
-
name: string;
|
83
|
-
type: CatalogType;
|
84
92
|
fieldType?: string;
|
85
93
|
exploreBaseTable: string;
|
86
94
|
catalogTags: {
|
@@ -89,11 +97,13 @@ export type CatalogItemWithTagUuids = {
|
|
89
97
|
createdAt: Date;
|
90
98
|
}[];
|
91
99
|
};
|
100
|
+
export type CatalogItemsWithIcons = Pick<CatalogItem, 'catalogSearchUuid' | 'icon' | 'name' | 'type'> & Pick<CatalogItemWithTagUuids, 'cachedExploreUuid' | 'projectUuid' | 'fieldType' | 'exploreBaseTable'>;
|
92
101
|
export type SchedulerIndexCatalogJobPayload = {
|
93
102
|
projectUuid: string;
|
94
103
|
explores: (Explore | ExploreError)[];
|
95
104
|
userUuid: string;
|
96
105
|
prevCatalogItemsWithTags: CatalogItemWithTagUuids[];
|
106
|
+
prevCatalogItemsWithIcons: CatalogItemsWithIcons[];
|
97
107
|
};
|
98
108
|
export type CatalogFieldWhere = {
|
99
109
|
fieldName: string;
|
@@ -103,3 +113,4 @@ export type ChartUsageIn = CatalogFieldWhere & {
|
|
103
113
|
chartUsage: number;
|
104
114
|
};
|
105
115
|
export declare const indexCatalogJob = "indexCatalog";
|
116
|
+
export {};
|
package/dist/types/catalog.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.indexCatalogJob = exports.getBasicType = exports.CatalogFilter = exports.CatalogType = void 0;
|
3
|
+
exports.indexCatalogJob = exports.getBasicType = exports.isCustomIcon = exports.isEmojiIcon = exports.CatalogFilter = exports.CatalogType = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const assertUnreachable_1 = tslib_1.__importDefault(require("../utils/assertUnreachable"));
|
6
6
|
const field_1 = require("./field");
|
@@ -15,6 +15,10 @@ var CatalogFilter;
|
|
15
15
|
CatalogFilter["Dimensions"] = "dimensions";
|
16
16
|
CatalogFilter["Metrics"] = "metrics";
|
17
17
|
})(CatalogFilter = exports.CatalogFilter || (exports.CatalogFilter = {}));
|
18
|
+
const isEmojiIcon = (icon) => Boolean(icon && 'unicode' in icon);
|
19
|
+
exports.isEmojiIcon = isEmojiIcon;
|
20
|
+
const isCustomIcon = (icon) => Boolean(icon && 'url' in icon);
|
21
|
+
exports.isCustomIcon = isCustomIcon;
|
18
22
|
const getBasicType = (field) => {
|
19
23
|
const { type } = field;
|
20
24
|
switch (type) {
|
package/dist/utils/filters.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { type DashboardTile } from '../types/dashboard';
|
1
2
|
import { type Table } from '../types/explore';
|
2
3
|
import { type CompiledField, type CustomSqlDimension, type Dimension, type Field, type FilterableDimension, type FilterableField, type FilterableItem, type ItemsMap, type TableCalculation } from '../types/field';
|
3
4
|
import { FilterOperator, FilterType, type AndFilterGroup, type DashboardFieldTarget, type DashboardFilterRule, type DashboardFilters, type FilterDashboardToRule, type FilterGroup, type FilterGroupItem, type FilterRule, type Filters, type MetricFilterRule, type OrFilterGroup } from '../types/filter';
|
@@ -14,6 +15,7 @@ export declare const createFilterRuleFromField: (field: FilterableField, value?:
|
|
14
15
|
export declare const matchFieldExact: (a: Field) => (b: Field) => boolean;
|
15
16
|
export declare const matchFieldByTypeAndName: (a: Field) => (b: Field) => boolean;
|
16
17
|
export declare const matchFieldByType: (a: Field) => (b: Field) => boolean;
|
18
|
+
export declare const isTileFilterable: (tile: DashboardTile) => boolean;
|
17
19
|
export declare const applyDefaultTileTargets: (filterRule: DashboardFilterRule<FilterOperator, DashboardFieldTarget, any, any>, field: FilterableDimension, availableTileFilters: Record<string, FilterableDimension[] | undefined>) => DashboardFilterRule<FilterOperator, DashboardFieldTarget, any, any>;
|
18
20
|
export declare const createDashboardFilterRuleFromField: ({ field, availableTileFilters, isTemporary, value, }: {
|
19
21
|
field: Exclude<FilterableItem, TableCalculation | CustomSqlDimension> | CompiledField;
|
@@ -43,6 +45,7 @@ export declare const isDimensionValueInvalidDate: (item: FilterableField, value:
|
|
43
45
|
export declare const getFiltersFromGroup: (filterGroup: FilterGroup, fields: ItemsMap[string][]) => Filters;
|
44
46
|
export declare const deleteFilterRuleFromGroup: (filterGroup: FilterGroup, id: string) => FilterGroup;
|
45
47
|
export declare const getDashboardFilterRulesForTile: (tileUuid: string, rules: DashboardFilterRule[]) => DashboardFilterRule[];
|
48
|
+
export declare const getTabUuidsForFilterRules: (dashboardTiles: DashboardTile[] | undefined, filters: DashboardFilters, filterableFieldsByTileUuid: Record<string, FilterableDimension[]> | undefined) => Record<string, string[]>;
|
46
49
|
export declare const getDashboardFilterRulesForTables: (tables: string[], rules: DashboardFilterRule[]) => DashboardFilterRule[];
|
47
50
|
export declare const getDashboardFilterRulesForTileAndTables: (tileUuid: string, tables: string[], rules: DashboardFilterRule[]) => DashboardFilterRule[];
|
48
51
|
export declare const getDashboardFiltersForTileAndTables: (tileUuid: string, tables: string[], dashboardFilters: DashboardFilters) => DashboardFilters;
|
package/dist/utils/filters.js
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.resetRequiredFilterRules = exports.reduceRequiredDimensionFiltersToFilterRules = exports.isFilterRuleInQuery = exports.createFilterRuleFromRequiredMetricRule = exports.addDashboardFiltersToMetricQuery = exports.overrideFilterGroupWithFilterRules = exports.overrideChartFilter = exports.addFiltersToMetricQuery = exports.getDashboardFiltersForTileAndTables = exports.getDashboardFilterRulesForTileAndTables = exports.getDashboardFilterRulesForTables = exports.getDashboardFilterRulesForTile = exports.deleteFilterRuleFromGroup = exports.getFiltersFromGroup = exports.isDimensionValueInvalidDate = exports.addFilterRule = exports.createDashboardFilterRuleFromField = exports.applyDefaultTileTargets = exports.matchFieldByType = exports.matchFieldByTypeAndName = exports.matchFieldExact = exports.createFilterRuleFromField = exports.getFilterRuleWithDefaultValue = exports.getFilterTypeFromItem = exports.getFilterGroupItemsPropertyName = exports.getItemsFromFilterGroup = exports.hasNestedGroups = exports.countTotalFilterRules = exports.getTotalFilterRules = exports.getFilterRulesFromGroup = void 0;
|
3
|
+
exports.resetRequiredFilterRules = exports.reduceRequiredDimensionFiltersToFilterRules = exports.isFilterRuleInQuery = exports.createFilterRuleFromRequiredMetricRule = exports.addDashboardFiltersToMetricQuery = exports.overrideFilterGroupWithFilterRules = exports.overrideChartFilter = exports.addFiltersToMetricQuery = exports.getDashboardFiltersForTileAndTables = exports.getDashboardFilterRulesForTileAndTables = exports.getDashboardFilterRulesForTables = exports.getTabUuidsForFilterRules = exports.getDashboardFilterRulesForTile = exports.deleteFilterRuleFromGroup = exports.getFiltersFromGroup = exports.isDimensionValueInvalidDate = exports.addFilterRule = exports.createDashboardFilterRuleFromField = exports.applyDefaultTileTargets = exports.isTileFilterable = exports.matchFieldByType = exports.matchFieldByTypeAndName = exports.matchFieldExact = exports.createFilterRuleFromField = exports.getFilterRuleWithDefaultValue = exports.getFilterTypeFromItem = exports.getFilterGroupItemsPropertyName = exports.getItemsFromFilterGroup = exports.hasNestedGroups = exports.countTotalFilterRules = exports.getTotalFilterRules = exports.getFilterRulesFromGroup = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
6
6
|
const moment_1 = tslib_1.__importDefault(require("moment"));
|
7
7
|
const uuid_1 = require("uuid");
|
8
|
+
const dashboard_1 = require("../types/dashboard");
|
8
9
|
const field_1 = require("../types/field");
|
9
10
|
const filter_1 = require("../types/filter");
|
10
11
|
const timeFrames_1 = require("../types/timeFrames");
|
@@ -182,6 +183,8 @@ const matchFieldByTypeAndName = (a) => (b) => a.type === b.type && a.name === b.
|
|
182
183
|
exports.matchFieldByTypeAndName = matchFieldByTypeAndName;
|
183
184
|
const matchFieldByType = (a) => (b) => a.type === b.type;
|
184
185
|
exports.matchFieldByType = matchFieldByType;
|
186
|
+
const isTileFilterable = (tile) => ![dashboard_1.DashboardTileTypes.MARKDOWN, dashboard_1.DashboardTileTypes.LOOM].includes(tile.type);
|
187
|
+
exports.isTileFilterable = isTileFilterable;
|
185
188
|
const getDefaultTileTargets = (field, availableTileFilters) => Object.entries(availableTileFilters).reduce((acc, [tileUuid, availableFilters]) => {
|
186
189
|
if (!availableFilters)
|
187
190
|
return acc;
|
@@ -409,6 +412,37 @@ const getDashboardFilterRulesForTile = (tileUuid, rules) => rules
|
|
409
412
|
})
|
410
413
|
.filter((f) => f !== null);
|
411
414
|
exports.getDashboardFilterRulesForTile = getDashboardFilterRulesForTile;
|
415
|
+
const getTabUuidsForFilterRules = (dashboardTiles, filters, filterableFieldsByTileUuid) => {
|
416
|
+
if (!dashboardTiles)
|
417
|
+
return {};
|
418
|
+
return dashboardTiles.reduce((acc, tile) => {
|
419
|
+
if (!tile.tabUuid || !(0, exports.isTileFilterable)(tile)) {
|
420
|
+
return acc;
|
421
|
+
}
|
422
|
+
const filterIdsForTile = (0, exports.getDashboardFilterRulesForTile)(tile.uuid, filters.dimensions)
|
423
|
+
.filter((filterRule) => {
|
424
|
+
const tileConfig = filterRule.tileTargets?.[tile.uuid];
|
425
|
+
// TODO: Move this fallback logic to the getDashboardFilterRulesForTile function
|
426
|
+
if (tileConfig === undefined && filterableFieldsByTileUuid) {
|
427
|
+
return filterableFieldsByTileUuid[tile.uuid]?.some((f) => (0, item_1.getItemId)(f) === filterRule.target.fieldId);
|
428
|
+
}
|
429
|
+
// Apply filter to tile
|
430
|
+
return !!tileConfig;
|
431
|
+
})
|
432
|
+
.map((tileFilter) => tileFilter.id);
|
433
|
+
// Set filter id as key and tile tab uuids as values
|
434
|
+
filterIdsForTile.forEach((filterId) => {
|
435
|
+
if (!acc[filterId]) {
|
436
|
+
acc[filterId] = [];
|
437
|
+
}
|
438
|
+
if (tile.tabUuid && !acc[filterId].includes(tile.tabUuid)) {
|
439
|
+
acc[filterId].push(tile.tabUuid);
|
440
|
+
}
|
441
|
+
});
|
442
|
+
return acc;
|
443
|
+
}, {});
|
444
|
+
};
|
445
|
+
exports.getTabUuidsForFilterRules = getTabUuidsForFilterRules;
|
412
446
|
const getDashboardFilterRulesForTables = (tables, rules) => rules.filter((f) => tables.includes(f.target.tableName));
|
413
447
|
exports.getDashboardFilterRulesForTables = getDashboardFilterRulesForTables;
|
414
448
|
const getDashboardFilterRulesForTileAndTables = (tileUuid, tables, rules) => (0, exports.getDashboardFilterRulesForTables)(tables, (0, exports.getDashboardFilterRulesForTile)(tileUuid, rules));
|