Skip to content

Commit

Permalink
Cleaning up old filters references from UI (#3882)
Browse files Browse the repository at this point in the history
* Cleaning up old filters

* Remaining cleanup

* Fix CI

* Create a copy before adding search filter
  • Loading branch information
AdityaHegde authored Jan 26, 2024
1 parent bbd5b11 commit 396252e
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 426 deletions.
118 changes: 0 additions & 118 deletions web-common/src/features/dashboards/actions/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { useMetaQuery } from "@rilldata/web-common/features/dashboards/selectors";
import { createShowHideMeasuresStore } from "@rilldata/web-common/features/dashboards/show-hide-selectors";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { sanitiseExpression } from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import { useTimeControlStore } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import { EntityStatus } from "@rilldata/web-common/features/entity-management/types";
import { createResizeListenerActionFactory } from "@rilldata/web-common/lib/actions/create-resize-listener-factory";
Expand Down Expand Up @@ -131,14 +132,14 @@
metricViewName,
{
measureNames: $selectedMeasureNames,
filter: $dashboardStore?.filters,
where: sanitiseExpression($dashboardStore?.whereFilter),
},
{
query: {
enabled:
$selectedMeasureNames?.length > 0 &&
$timeControlsStore.ready &&
!!$dashboardStore?.filters,
!!$dashboardStore?.whereFilter,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
* Create a table with the selected dimension and measures
* to be displayed in explore
*/
import { cancelDashboardQueries } from "@rilldata/web-common/features/dashboards/dashboard-queries";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { useTimeControlStore } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import {
createQueryServiceMetricsViewComparison,
createQueryServiceMetricsViewTotals,
} from "@rilldata/web-common/runtime-client";
import { useQueryClient } from "@tanstack/svelte-query";
import { getDimensionFilterWithSearch } from "./dimension-table-utils";
import DimensionHeader from "./DimensionHeader.svelte";
import DimensionTable from "./DimensionTable.svelte";
Expand All @@ -30,6 +27,7 @@
},
comparison: { isBeingCompared },
dimensions: { dimensionTableDimName, dimensionTableColumnName },
dimensionFilters: { unselectedDimensionValues },
dimensionTable: {
virtualizedTableColumns,
selectedDimensionValueNames,
Expand All @@ -38,7 +36,11 @@
activeMeasure: { activeMeasureName },
},
actions: {
dimensionsFilter: { toggleDimensionValueSelection },
dimensionsFilter: {
toggleDimensionValueSelection,
selectItemsInFilter,
deselectItemsInFilter,
},
},
metricsViewName,
runtime,
Expand All @@ -51,8 +53,6 @@
let searchText = "";
const queryClient = useQueryClient();
$: instanceId = $runtime.instanceId;
const timeControlsStore = useTimeControlStore(stateManagers);
Expand Down Expand Up @@ -114,27 +114,22 @@
function toggleAllSearchItems() {
const labels = tableRows.map((row) => row[dimensionColumnName] as string);
cancelDashboardQueries(queryClient, $metricsViewName);
if (areAllTableRowsSelected) {
metricsExplorerStore.deselectItemsInFilter(
$metricsViewName,
dimensionName,
labels,
);
deselectItemsInFilter(dimensionName, labels);
notifications.send({
message: `Removed ${labels.length} items from filter`,
});
return;
} else {
const newValuesSelected = metricsExplorerStore.selectItemsInFilter(
$metricsViewName,
const newValuesSelected = $unselectedDimensionValues(
dimensionName,
labels,
);
selectItemsInFilter(dimensionName, labels);
notifications.send({
message: `Added ${newValuesSelected} items to filter`,
message: `Added ${newValuesSelected.length} items to filter`,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
matchExpressionByName,
filterExpressions,
createAndExpression,
copyFilterExpression,
} from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import { V1Operation } from "../../../runtime-client";
import PercentOfTotal from "./PercentOfTotal.svelte";
Expand All @@ -18,7 +19,6 @@ import type {
V1Expression,
V1MetricsViewComparisonRow,
V1MetricsViewComparisonValue,
V1MetricsViewFilter,
V1MetricsViewToplistResponseDataItem,
} from "../../../runtime-client";

Expand All @@ -44,6 +44,7 @@ export function updateFilterOnSearch(
dimensionName: string,
): V1Expression | undefined {
if (!filterForDimension) return undefined;
// create a copy
const addNull = "null".includes(searchText);
if (searchText !== "") {
let cond: V1Expression;
Expand All @@ -57,6 +58,7 @@ export function updateFilterOnSearch(
cond = createLikeExpression(dimensionName, `%${searchText}%`);
}

filterForDimension = copyFilterExpression(filterForDimension);
const filterIdx = filterForDimension.cond?.exprs?.findIndex((e) =>
matchExpressionByName(e, dimensionName),
);
Expand All @@ -66,12 +68,13 @@ export function updateFilterOnSearch(
filterForDimension.cond?.exprs?.splice(filterIdx, 0, cond);
}
} else {
filterExpressions(
filterForDimension,
(e) =>
e.cond?.op === V1Operation.OPERATION_LIKE ||
e.cond?.op === V1Operation.OPERATION_NLIKE,
);
filterForDimension =
filterExpressions(
filterForDimension,
(e) =>
e.cond?.op === V1Operation.OPERATION_LIKE ||
e.cond?.op === V1Operation.OPERATION_NLIKE,
) ?? createAndExpression([]);
}
return filterForDimension;
}
Expand Down Expand Up @@ -506,22 +509,3 @@ export function prepareDimensionTableRows(
});
return tableRows;
}

export function getSelectedRowIndicesFromFilters(
rows: DimensionTableRow[],
filters: V1MetricsViewFilter,
dimensionName: string,
excludeMode: boolean,
): number[] {
const selectedDimValues =
((excludeMode
? filters?.exclude?.find((d) => d.name === dimensionName)?.in
: filters?.include?.find((d) => d.name === dimensionName)
?.in) as string[]) ?? [];

return selectedDimValues
.map((label) => {
return rows.findIndex((row) => row[dimensionName] === label);
})
.filter((i) => i >= 0);
}
7 changes: 1 addition & 6 deletions web-common/src/features/dashboards/proto-state/fromProto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ export function getDashboardStateFromProto(
metricsView: V1MetricsView,
): Partial<MetricsExplorerEntity> {
const dashboard = DashboardState.fromBinary(binary);
const entity: Partial<MetricsExplorerEntity> = {
filters: {
include: [],
exclude: [],
},
};
const entity: Partial<MetricsExplorerEntity> = {};

if (dashboard.filters) {
entity.whereFilter = convertFilterToExpression(dashboard.filters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import type { VirtualizedTableColumns } from "@rilldata/web-common/components/virtualized-table/types";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { sanitiseExpression } from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import { useTimeControlStore } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import { createQueryServiceMetricsViewRows } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
Expand All @@ -24,13 +25,13 @@
metricViewName,
{
limit: $limit,
filter: $dashboardStore.filters,
where: sanitiseExpression($dashboardStore.whereFilter),
timeStart: $timeControlsStore.timeStart,
timeEnd: $timeControlsStore.timeEnd,
},
{
query: {
enabled: $timeControlsStore.ready && !!$dashboardStore?.filters,
enabled: $timeControlsStore.ready && !!$dashboardStore?.whereFilter,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import CaretDownIcon from "@rilldata/web-common/components/icons/CaretDownIcon.svelte";
import CaretUpIcon from "@rilldata/web-common/components/icons/CaretUpIcon.svelte";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { sanitiseExpression } from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import { useTimeControlStore } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import { formatCompactInteger } from "@rilldata/web-common/lib/formatters";
import { createQueryServiceMetricsViewTotals } from "@rilldata/web-common/runtime-client";
Expand Down Expand Up @@ -71,7 +72,7 @@
],
timeStart: $timeControlsStore.timeStart,
timeEnd,
filter: $dashboardStore?.filters,
where: sanitiseExpression($dashboardStore?.whereFilter),
},
{
query: {
Expand All @@ -81,10 +82,10 @@
{
timeStart: $timeControlsStore.timeStart,
timeEnd,
filter: $dashboardStore?.filters,
where: sanitiseExpression($dashboardStore?.whereFilter),
},
],
enabled: $timeControlsStore.ready && !!$dashboardStore?.filters,
enabled: $timeControlsStore.ready && !!$dashboardStore?.whereFilter,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sanitiseExpression } from "@rilldata/web-common/features/dashboards/stores/filter-utils";
import type { TimeControlStore } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import { get } from "svelte/store";
import { runtime } from "../../../runtime-client/runtime-store";
Expand Down Expand Up @@ -32,7 +33,7 @@ export default async function exportMetrics({
metricsViewRowsRequest: {
instanceId: get(runtime).instanceId,
metricsViewName: metricViewName,
filter: dashboard.filters,
where: sanitiseExpression(dashboard.whereFilter),
timeStart: timeControlState.timeStart,
timeEnd: timeControlState.timeEnd,
},
Expand Down
Loading

1 comment on commit 396252e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.