From dd0bfbb3fd5e270ade260a12e23d3441933ca942 Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Fri, 12 Apr 2024 16:37:43 -0500 Subject: [PATCH] Add less-equal, greater-equal, null, not null filter types, get things working --- .../positron_ipykernel/data_explorer.py | 8 +- .../positron_ipykernel/data_explorer_comm.py | 8 +- .../tests/test_data_explorer.py | 1 + .../comms/data_explorer-backend-openrpc.json | 7 +- .../addEditRowFilterModalPopup.tsx | 102 ++++++++++++++++-- .../rowFilterDescriptor.ts | 90 ++++++++++++++++ .../components/rowFilterWidget.tsx | 42 +++++++- .../components/rowFilterBar/rowFilterBar.tsx | 94 +++++++++------- .../languageRuntimeDataExplorerClient.ts | 16 ++- .../common/positronDataExplorerComm.ts | 9 +- 10 files changed, 316 insertions(+), 61 deletions(-) diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer.py b/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer.py index 71e79e9fc49..c88c33e724c 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer.py @@ -24,6 +24,7 @@ from .access_keys import decode_access_key from .data_explorer_comm import ( + BackendState, ColumnFrequencyTable, ColumnHistogram, ColumnSummaryStats, @@ -35,7 +36,6 @@ ColumnSortKey, DataExplorerBackendMessageContent, DataExplorerFrontendEvent, - DataExplorerState, FilterResult, GetColumnProfilesFeatures, GetColumnProfilesRequest, @@ -222,7 +222,7 @@ def _prof_histogram(self, column_index: int) -> ColumnHistogram: pass @abc.abstractmethod - def _get_state(self) -> DataExplorerState: + def _get_state(self) -> BackendState: pass @@ -724,13 +724,13 @@ def _prof_histogram(self, column_index: int): get_column_profiles=_column_profile_features, ) - def _get_state(self) -> DataExplorerState: + def _get_state(self) -> BackendState: if self.view_indices is not None: num_rows = len(self.view_indices) else: num_rows = self.table.shape[0] - return DataExplorerState( + return BackendState( table_shape=TableShape(num_rows=num_rows, num_columns=self.table.shape[1]), row_filters=self.filters, sort_keys=self.sort_keys, diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer_comm.py b/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer_comm.py index 54e9a54f94a..fd06b9ad1d1 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer_comm.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/data_explorer_comm.py @@ -167,7 +167,7 @@ class FilterResult(BaseModel): ) -class DataExplorerState(BaseModel): +class BackendState(BaseModel): """ The current backend state for the data explorer """ @@ -270,6 +270,10 @@ class RowFilter(BaseModel): Specifies a table row filter based on a single column's values """ + filter_id: str = Field( + description="Unique identifier for this filter", + ) + filter_type: RowFilterType = Field( description="Type of row filter to apply", ) @@ -903,7 +907,7 @@ class SchemaUpdateParams(BaseModel): FilterResult.update_forward_refs() -DataExplorerState.update_forward_refs() +BackendState.update_forward_refs() TableShape.update_forward_refs() diff --git a/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_data_explorer.py b/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_data_explorer.py index 47db33dab56..7664b504485 100644 --- a/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_data_explorer.py +++ b/extensions/positron-python/python_files/positron/positron_ipykernel/tests/test_data_explorer.py @@ -672,6 +672,7 @@ def test_pandas_get_data_values(dxf: DataExplorerFixture): def _filter(filter_type, column_index, condition="and", is_valid=None, **kwargs): kwargs.update( { + "filter_id": guid(), "filter_type": filter_type, "column_index": column_index, "condition": condition, diff --git a/positron/comms/data_explorer-backend-openrpc.json b/positron/comms/data_explorer-backend-openrpc.json index 68541b15d16..a41ec4e57df 100644 --- a/positron/comms/data_explorer-backend-openrpc.json +++ b/positron/comms/data_explorer-backend-openrpc.json @@ -240,7 +240,7 @@ "result": { "schema": { "type": "object", - "name": "data_explorer_state", + "name": "backend_state", "description": "The current backend state for the data explorer", "required": [ "table_shape", @@ -385,11 +385,16 @@ "type": "object", "description": "Specifies a table row filter based on a single column's values", "required": [ + "filter_id", "filter_type", "column_index", "condition" ], "properties": { + "filter_id": { + "type": "string", + "description": "Unique identifier for this filter" + }, "filter_type": { "description": "Type of row filter to apply", "$ref": "#/components/schemas/row_filter_type" diff --git a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/addEditRowFilterModalPopup.tsx b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/addEditRowFilterModalPopup.tsx index 94d0d6ee4a5..853db830a5b 100644 --- a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/addEditRowFilterModalPopup.tsx +++ b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/addEditRowFilterModalPopup.tsx @@ -21,7 +21,7 @@ import { DataExplorerClientInstance } from 'vs/workbench/services/languageRuntim import { DropDownListBox, DropDownListBoxEntry } from 'vs/workbench/browser/positronComponents/dropDownListBox/dropDownListBox'; import { RowFilterParameter } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/components/rowFilterParameter'; import { DropDownColumnSelector } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/components/dropDownColumnSelector'; -import { RangeRowFilterDescriptor, RowFilterDescriptor, RowFilterCondition, RowFilterDescriptorIsBetween, RowFilterDescriptorIsEmpty, RowFilterDescriptorIsEqualTo, RowFilterDescriptorIsGreaterThan, RowFilterDescriptorIsLessThan, RowFilterDescriptorIsNotBetween, RowFilterDescriptorIsNotEmpty, SingleValueRowFilterDescriptor } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor'; +import { RangeRowFilterDescriptor, RowFilterDescriptor, RowFilterCondition, RowFilterDescriptorIsBetween, RowFilterDescriptorIsEmpty, RowFilterDescriptorIsEqualTo, RowFilterDescriptorIsGreaterThan, RowFilterDescriptorIsLessThan, RowFilterDescriptorIsNotBetween, RowFilterDescriptorIsNotEmpty, SingleValueRowFilterDescriptor, RowFilterDescriptorIsLessOrEqual, RowFilterDescriptorIsGreaterOrEqual, RowFilterDescriptorIsNotNull, RowFilterDescriptorIsNull } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor'; /** * Validates a row filter value. @@ -141,25 +141,46 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp // Build the condition entries. const conditionEntries: DropDownListBoxEntry[] = []; - // Every type allows is empty and is not empty conditions. + // Every type allows is null and is not null conditions. conditionEntries.push(new DropDownListBoxItem({ - identifier: RowFilterCondition.CONDITION_IS_EMPTY, + identifier: RowFilterCondition.CONDITION_IS_NULL, title: localize( - 'positron.addEditRowFilter.conditionIsEmpty', - "is empty" + 'positron.addEditRowFilter.conditionIsNull', + "is null" ), - value: RowFilterCondition.CONDITION_IS_EMPTY + value: RowFilterCondition.CONDITION_IS_NULL })); conditionEntries.push(new DropDownListBoxItem({ - identifier: RowFilterCondition.CONDITION_IS_NOT_EMPTY, + identifier: RowFilterCondition.CONDITION_IS_NOT_NULL, title: localize( - 'positron.addEditRowFilter.conditionIsNotEmpty', - "is not empty" + 'positron.addEditRowFilter.conditionIsNotNull', + "is not null" ), - value: RowFilterCondition.CONDITION_IS_NOT_EMPTY + value: RowFilterCondition.CONDITION_IS_NOT_NULL })); conditionEntries.push(new DropDownListBoxSeparator()); + if (selectedColumnSchema.type_display === ColumnDisplayType.String) { + // String types support is empty, is not empty filter types + conditionEntries.push(new DropDownListBoxItem({ + identifier: RowFilterCondition.CONDITION_IS_EMPTY, + title: localize( + 'positron.addEditRowFilter.conditionIsEmpty', + "is empty" + ), + value: RowFilterCondition.CONDITION_IS_EMPTY + })); + conditionEntries.push(new DropDownListBoxItem({ + identifier: RowFilterCondition.CONDITION_IS_NOT_EMPTY, + title: localize( + 'positron.addEditRowFilter.conditionIsNotEmpty', + "is not empty" + ), + value: RowFilterCondition.CONDITION_IS_NOT_EMPTY + })); + conditionEntries.push(new DropDownListBoxSeparator()); + } + // Add is less than / is greater than conditions. switch (selectedColumnSchema.type_display) { case ColumnDisplayType.Number: @@ -174,6 +195,14 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp ), value: RowFilterCondition.CONDITION_IS_LESS_THAN })); + conditionEntries.push(new DropDownListBoxItem({ + identifier: RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL, + title: localize( + 'positron.addEditRowFilter.conditionIsLessThanOrEqual', + "is less than or equal to" + ), + value: RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL + })); conditionEntries.push(new DropDownListBoxItem({ identifier: RowFilterCondition.CONDITION_IS_GREATER_THAN, title: localize( @@ -182,6 +211,14 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp ), value: RowFilterCondition.CONDITION_IS_GREATER_THAN })); + conditionEntries.push(new DropDownListBoxItem({ + identifier: RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL, + title: localize( + 'positron.addEditRowFilter.conditionIsGreaterThanOrEqual', + "is greater than or equal to" + ), + value: RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL + })); break; } @@ -240,13 +277,17 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp switch (selectedCondition) { // Do not render the first row filter parameter component. case undefined: + case RowFilterCondition.CONDITION_IS_NULL: + case RowFilterCondition.CONDITION_IS_NOT_NULL: case RowFilterCondition.CONDITION_IS_EMPTY: case RowFilterCondition.CONDITION_IS_NOT_EMPTY: return null; // Render the first row filter parameter component in single-value mode. case RowFilterCondition.CONDITION_IS_LESS_THAN: + case RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL: case RowFilterCondition.CONDITION_IS_GREATER_THAN: + case RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL: case RowFilterCondition.CONDITION_IS_EQUAL_TO: placeholderText = localize( 'positron.addEditRowFilter.valuePlaceholder', @@ -287,10 +328,14 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp switch (selectedCondition) { // Do not render the second row filter parameter component. case undefined: + case RowFilterCondition.CONDITION_IS_NULL: + case RowFilterCondition.CONDITION_IS_NOT_NULL: case RowFilterCondition.CONDITION_IS_EMPTY: case RowFilterCondition.CONDITION_IS_NOT_EMPTY: case RowFilterCondition.CONDITION_IS_LESS_THAN: + case RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL: case RowFilterCondition.CONDITION_IS_GREATER_THAN: + case RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL: case RowFilterCondition.CONDITION_IS_EQUAL_TO: return null; @@ -469,6 +514,18 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp break; } + // Apply the is null row filter. + case RowFilterCondition.CONDITION_IS_NULL: { + applyRowFilter(new RowFilterDescriptorIsNull(selectedColumnSchema)); + break; + } + + // Apply the is not null row filter. + case RowFilterCondition.CONDITION_IS_NOT_NULL: { + applyRowFilter(new RowFilterDescriptorIsNotNull(selectedColumnSchema)); + break; + } + // Apply the is less than row filter. case RowFilterCondition.CONDITION_IS_LESS_THAN: { if (!validateFirstRowFilterValue()) { @@ -481,6 +538,18 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp break; } + // Apply the is less than row filter. + case RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL: { + if (!validateFirstRowFilterValue()) { + return; + } + applyRowFilter(new RowFilterDescriptorIsLessOrEqual( + selectedColumnSchema, + firstRowFilterValue + )); + break; + } + // Apply the is greater than row filter. case RowFilterCondition.CONDITION_IS_GREATER_THAN: { if (!validateFirstRowFilterValue()) { @@ -493,6 +562,18 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp break; } + // Apply the is greater than row filter. + case RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL: { + if (!validateFirstRowFilterValue()) { + return; + } + applyRowFilter(new RowFilterDescriptorIsGreaterOrEqual( + selectedColumnSchema, + firstRowFilterValue + )); + break; + } + // Apply the is equal to row filter. case RowFilterCondition.CONDITION_IS_EQUAL_TO: { if (!validateFirstRowFilterValue()) { @@ -505,6 +586,7 @@ export const AddEditRowFilterModalPopup = (props: AddEditRowFilterModalPopupProp break; } + // Apply the is between row filter. case RowFilterCondition.CONDITION_IS_BETWEEN: { if (!validateFirstRowFilterValue()) { diff --git a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor.ts b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor.ts index 3434a0b968b..152472023ff 100644 --- a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor.ts +++ b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor.ts @@ -12,10 +12,14 @@ export enum RowFilterCondition { // Conditions with no parameters. CONDITION_IS_EMPTY = 'is-empty', CONDITION_IS_NOT_EMPTY = 'is-not-empty', + CONDITION_IS_NULL = 'is-null', + CONDITION_IS_NOT_NULL = 'is-not-null', // Conditions with one parameter. CONDITION_IS_LESS_THAN = 'is-less-than', + CONDITION_IS_LESS_OR_EQUAL = 'is-less-than-or-equal-to', CONDITION_IS_GREATER_THAN = 'is-greater-than', + CONDITION_IS_GREATER_OR_EQUAL = 'is-greater-than-or-equal-to', CONDITION_IS_EQUAL_TO = 'is-equal-to', // Conditions with two parameters. @@ -86,6 +90,46 @@ export class RowFilterDescriptorIsNotEmpty extends BaseRowFilterDescriptor { } } +/** + * RowFilterDescriptorIsNull class. + */ +export class RowFilterDescriptorIsNull extends BaseRowFilterDescriptor { + /** + * Constructor. + * @param columnSchema The column schema. + */ + constructor(columnSchema: ColumnSchema) { + super(columnSchema); + } + + /** + * Gets the row filter condition. + */ + get rowFilterCondition() { + return RowFilterCondition.CONDITION_IS_NULL; + } +} + +/** + * RowFilterDescriptorIsNotEmpty class. + */ +export class RowFilterDescriptorIsNotNull extends BaseRowFilterDescriptor { + /** + * Constructor. + * @param columnSchema The column schema. + */ + constructor(columnSchema: ColumnSchema) { + super(columnSchema); + } + + /** + * Gets the row filter condition. + */ + get rowFilterCondition() { + return RowFilterCondition.CONDITION_IS_NOT_NULL; + } +} + /** * SingleValueRowFilterDescriptor class. */ @@ -121,6 +165,27 @@ export class RowFilterDescriptorIsLessThan extends SingleValueRowFilterDescripto } } +/** + * RowFilterDescriptorIsLessOrEqual class. + */ +export class RowFilterDescriptorIsLessOrEqual extends SingleValueRowFilterDescriptor { + /** + * Constructor. + * @param columnSchema The column schema. + * @param value The value. + */ + constructor(columnSchema: ColumnSchema, value: string) { + super(columnSchema, value); + } + + /** + * Gets the row filter condition. + */ + get rowFilterCondition() { + return RowFilterCondition.CONDITION_IS_LESS_OR_EQUAL; + } +} + /** * RowFilterDescriptorIsGreaterThan class. */ @@ -142,6 +207,27 @@ export class RowFilterDescriptorIsGreaterThan extends SingleValueRowFilterDescri } } +/** + * RowFilterDescriptorIsGreaterOrEqual class. + */ +export class RowFilterDescriptorIsGreaterOrEqual extends SingleValueRowFilterDescriptor { + /** + * Constructor. + * @param columnSchema The column schema. + * @param value The value. + */ + constructor(columnSchema: ColumnSchema, value: string) { + super(columnSchema, value); + } + + /** + * Gets the row filter condition. + */ + get rowFilterCondition() { + return RowFilterCondition.CONDITION_IS_GREATER_OR_EQUAL; + } +} + /** * RowFilterDescriptorIsEqualTo class. */ @@ -232,8 +318,12 @@ export class RowFilterDescriptorIsNotBetween extends RangeRowFilterDescriptor { export type RowFilterDescriptor = RowFilterDescriptorIsEmpty | RowFilterDescriptorIsNotEmpty | + RowFilterDescriptorIsNull | + RowFilterDescriptorIsNotNull | RowFilterDescriptorIsLessThan | + RowFilterDescriptorIsLessOrEqual | RowFilterDescriptorIsGreaterThan | + RowFilterDescriptorIsGreaterOrEqual | RowFilterDescriptorIsEqualTo | RowFilterDescriptorIsBetween | RowFilterDescriptorIsNotBetween; diff --git a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/components/rowFilterWidget.tsx b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/components/rowFilterWidget.tsx index 25bbc0ea8ae..014a1bb5fb5 100644 --- a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/components/rowFilterWidget.tsx +++ b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/components/rowFilterWidget.tsx @@ -12,7 +12,20 @@ import { forwardRef } from 'react'; // eslint-disable-line no-duplicate-imports // Other dependencies. import { localize } from 'vs/nls'; import { Button } from 'vs/base/browser/ui/positronComponents/button/button'; -import { RowFilterDescriptor, RowFilterDescriptorIsBetween, RowFilterDescriptorIsEmpty, RowFilterDescriptorIsEqualTo, RowFilterDescriptorIsGreaterThan, RowFilterDescriptorIsLessThan, RowFilterDescriptorIsNotBetween, RowFilterDescriptorIsNotEmpty } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor'; +import { + RowFilterDescriptor, + RowFilterDescriptorIsBetween, + RowFilterDescriptorIsEmpty, + RowFilterDescriptorIsEqualTo, + RowFilterDescriptorIsGreaterThan, + RowFilterDescriptorIsGreaterOrEqual, + RowFilterDescriptorIsLessThan, + RowFilterDescriptorIsLessOrEqual, + RowFilterDescriptorIsNotBetween, + RowFilterDescriptorIsNotEmpty, + RowFilterDescriptorIsNotNull, + RowFilterDescriptorIsNull +} from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor'; /** * RowFilterWidgetProps interface. @@ -46,18 +59,45 @@ export const RowFilterWidget = forwardRef ; + } else if (props.rowFilter instanceof RowFilterDescriptorIsNull) { + return <> + {props.rowFilter.columnSchema.column_name} + + {localize('positron.dataExplorer.rowFilterWidget.isNull', "is null")} + + ; + } else if (props.rowFilter instanceof RowFilterDescriptorIsNotNull) { + return <> + {props.rowFilter.columnSchema.column_name} + + {localize('positron.dataExplorer.rowFilterWidget.isNotNull', "is not null")} + + ; + } else if (props.rowFilter instanceof RowFilterDescriptorIsLessThan) { return <> {props.rowFilter.columnSchema.column_name} < {props.rowFilter.value} ; + } else if (props.rowFilter instanceof RowFilterDescriptorIsLessOrEqual) { + return <> + {props.rowFilter.columnSchema.column_name} + <= + {props.rowFilter.value} + ; } else if (props.rowFilter instanceof RowFilterDescriptorIsGreaterThan) { return <> {props.rowFilter.columnSchema.column_name} > {props.rowFilter.value} ; + } else if (props.rowFilter instanceof RowFilterDescriptorIsGreaterOrEqual) { + return <> + {props.rowFilter.columnSchema.column_name} + >= + {props.rowFilter.value} + ; } else if (props.rowFilter instanceof RowFilterDescriptorIsEqualTo) { return <> {props.rowFilter.columnSchema.column_name} diff --git a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/rowFilterBar.tsx b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/rowFilterBar.tsx index 54deaf0aa4f..1e6341303b5 100644 --- a/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/rowFilterBar.tsx +++ b/src/vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/rowFilterBar.tsx @@ -18,10 +18,23 @@ import { ContextMenuItem } from 'vs/workbench/browser/positronComponents/context import { ContextMenuSeparator } from 'vs/workbench/browser/positronComponents/contextMenu/contextMenuSeparator'; import { usePositronDataExplorerContext } from 'vs/workbench/browser/positronDataExplorer/positronDataExplorerContext'; import { PositronModalReactRenderer } from 'vs/workbench/browser/positronModalReactRenderer/positronModalReactRenderer'; -import { CompareFilterParamsOp, RowFilter, RowFilterType } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; +import { CompareFilterParamsOp, RowFilter, RowFilterCondition, RowFilterType } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; import { RowFilterWidget } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/rowFilterBar/components/rowFilterWidget'; import { AddEditRowFilterModalPopup } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/addEditRowFilterModalPopup'; -import { RowFilterDescriptor, RowFilterDescriptorIsEmpty, RowFilterDescriptorIsNotEmpty, RowFilterDescriptorIsLessThan, RowFilterDescriptorIsGreaterThan, RowFilterDescriptorIsEqualTo, RowFilterDescriptorIsBetween, RowFilterDescriptorIsNotBetween } from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor'; +import { + RowFilterDescriptor, + RowFilterDescriptorIsEmpty, + RowFilterDescriptorIsNotEmpty, + RowFilterDescriptorIsNull, + RowFilterDescriptorIsNotNull, + RowFilterDescriptorIsLessThan, + RowFilterDescriptorIsGreaterThan, + RowFilterDescriptorIsEqualTo, + RowFilterDescriptorIsBetween, + RowFilterDescriptorIsNotBetween, + RowFilterDescriptorIsLessOrEqual, + RowFilterDescriptorIsGreaterOrEqual +} from 'vs/workbench/browser/positronDataExplorer/components/dataExplorerPanel/components/addEditRowFilterModalPopup/rowFilterDescriptor'; /** * Creates row filters from row filter descriptors. @@ -35,67 +48,70 @@ const createRowFilters = (rowFilterDescriptors: RowFilterDescriptor[]) => { rowFilterDescriptor ) => { // + const sharedParams = { + filter_id: rowFilterDescriptor.identifier, + column_index: rowFilterDescriptor.columnSchema.column_index, + condition: RowFilterCondition.And + }; + + const getCompareFilter = (value: string, op: CompareFilterParamsOp): RowFilter => { + return { + filter_type: RowFilterType.Compare, + compare_params: { + op, + value + }, + ...sharedParams + }; + }; + if (rowFilterDescriptor instanceof RowFilterDescriptorIsEmpty) { rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, - filter_type: RowFilterType.IsNull, - column_index: rowFilterDescriptor.columnSchema.column_index + filter_type: RowFilterType.IsEmpty, + ...sharedParams }); } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsNotEmpty) { rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, - filter_type: RowFilterType.NotNull, - column_index: rowFilterDescriptor.columnSchema.column_index + filter_type: RowFilterType.NotEmpty, + ...sharedParams }); - } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsLessThan) { + } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsNull) { rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, - filter_type: RowFilterType.Compare, - column_index: rowFilterDescriptor.columnSchema.column_index, - compare_params: { - op: CompareFilterParamsOp.Lt, - value: rowFilterDescriptor.value - } + filter_type: RowFilterType.IsNull, + ...sharedParams }); - } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsGreaterThan) { + } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsNotNull) { rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, - filter_type: RowFilterType.Compare, - column_index: rowFilterDescriptor.columnSchema.column_index, - compare_params: { - op: CompareFilterParamsOp.Gt, - value: rowFilterDescriptor.value - } + filter_type: RowFilterType.NotNull, + ...sharedParams }); + } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsLessThan) { + rowFilters.push(getCompareFilter(rowFilterDescriptor.value, CompareFilterParamsOp.Lt)); + } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsLessOrEqual) { + rowFilters.push(getCompareFilter(rowFilterDescriptor.value, CompareFilterParamsOp.LtEq)); + } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsGreaterThan) { + rowFilters.push(getCompareFilter(rowFilterDescriptor.value, CompareFilterParamsOp.Gt)); + } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsGreaterOrEqual) { + rowFilters.push(getCompareFilter(rowFilterDescriptor.value, CompareFilterParamsOp.GtEq)); } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsEqualTo) { - rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, - filter_type: RowFilterType.Compare, - column_index: rowFilterDescriptor.columnSchema.column_index, - compare_params: { - op: CompareFilterParamsOp.Eq, - value: rowFilterDescriptor.value - } - }); + rowFilters.push(getCompareFilter(rowFilterDescriptor.value, CompareFilterParamsOp.Eq)); } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsBetween) { rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, filter_type: RowFilterType.Between, - column_index: rowFilterDescriptor.columnSchema.column_index, between_params: { left_value: rowFilterDescriptor.lowerLimit, right_value: rowFilterDescriptor.upperLimit - } + }, + ...sharedParams }); } else if (rowFilterDescriptor instanceof RowFilterDescriptorIsNotBetween) { rowFilters.push({ - filter_id: rowFilterDescriptor.identifier, filter_type: RowFilterType.NotBetween, - column_index: rowFilterDescriptor.columnSchema.column_index, between_params: { left_value: rowFilterDescriptor.lowerLimit, right_value: rowFilterDescriptor.upperLimit - } + }, + ...sharedParams }); } diff --git a/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts b/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts index 728fda8a6cd..2f7b25ec6f0 100644 --- a/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts +++ b/src/vs/workbench/services/languageRuntime/common/languageRuntimeDataExplorerClient.ts @@ -6,7 +6,19 @@ import { generateUuid } from 'vs/base/common/uuid'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable } from 'vs/base/common/lifecycle'; import { IRuntimeClientInstance } from 'vs/workbench/services/languageRuntime/common/languageRuntimeClientInstance'; -import { ColumnProfileRequest, ColumnProfileResult, ColumnSchema, ColumnSortKey, FilterResult, PositronDataExplorerComm, RowFilter, SchemaUpdateEvent, TableData, TableSchema, TableState } from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; +import { + BackendState, + ColumnProfileRequest, + ColumnProfileResult, + ColumnSchema, + ColumnSortKey, + FilterResult, + PositronDataExplorerComm, + RowFilter, + SchemaUpdateEvent, + TableData, + TableSchema +} from 'vs/workbench/services/languageRuntime/common/positronDataExplorerComm'; /** * TableSchemaSearchResult interface. This is here temporarily until searching the tabe schema @@ -97,7 +109,7 @@ export class DataExplorerClientInstance extends Disposable { * Get the current active state of the data explorer backend. * @returns A promose that resolves to the current table state. */ - async getState(): Promise { + async getState(): Promise { return this._positronDataExplorerComm.getState(); } diff --git a/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts b/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts index 0df6080ca69..a5b609e6506 100644 --- a/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts +++ b/src/vs/workbench/services/languageRuntime/common/positronDataExplorerComm.ts @@ -56,7 +56,7 @@ export interface FilterResult { /** * The current backend state for the data explorer */ -export interface DataExplorerState { +export interface BackendState { /** * Provides number of rows and columns in table */ @@ -166,6 +166,11 @@ export interface TableSchema { * Specifies a table row filter based on a single column's values */ export interface RowFilter { + /** + * Unique identifier for this filter + */ + filter_id: string; + /** * Type of row filter to apply */ @@ -760,7 +765,7 @@ export class PositronDataExplorerComm extends PositronBaseComm { * * @returns The current backend state for the data explorer */ - getState(): Promise { + getState(): Promise { return super.performRpc('get_state', [], []); }