Skip to content

Commit

Permalink
fix: sidebar search should use relevance instead of alphabetical (pin…
Browse files Browse the repository at this point in the history
…terest#1096)

* fix: table sort should be by importance score by default

* Change importance score to relevance

* fix precommit

* add comment about asc
  • Loading branch information
czgu authored Dec 7, 2022
1 parent 8b5b78f commit a18cc93
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- prettier@2.7.1
# - '@trivago/prettier-plugin-sort-imports@3.2.0' # removing it since pre-commit install fails

- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.14.2",
"version": "3.14.3",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,16 @@ export const DataTableNavigatorSearch: React.FC<{
<OrderByButton
className="mr4"
asc={sortTableAsc}
hideAscToggle={sortTableKey === 'importance_score'}
hideAscToggle={sortTableKey === 'relevance'}
orderByField={startCase(sortTableKey)}
orderByFieldSymbol={sortTableKey === 'name' ? 'Aa' : 'Is'}
orderByFieldSymbol={sortTableKey === 'name' ? 'Aa' : 'Rl'}
onAscToggle={() => {
dispatch(updateTableSort(null, !sortTableAsc));
}}
onOrderByFieldToggle={() => {
dispatch(
updateTableSort(
sortTableKey === 'name'
? 'importance_score'
: 'name'
sortTableKey === 'name' ? 'relevance' : 'name'
)
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ export const SchemaTableItem: React.FC<{
</div>
<OrderByButton
asc={sortOrder.asc}
hideAscToggle={sortOrder.key === 'importance_score'}
hideAscToggle={sortOrder.key === 'relevance'}
orderByField={startCase(sortOrder.key)}
orderByFieldSymbol={sortOrder.key === 'name' ? 'Aa' : 'Is'}
orderByFieldSymbol={sortOrder.key === 'name' ? 'Aa' : 'Rl'}
onAscToggle={() => onSortChanged(null, !sortOrder.asc)}
onOrderByFieldToggle={() =>
onSortChanged(
sortOrder.key === 'name'
? 'importance_score'
: 'name'
sortOrder.key === 'name' ? 'relevance' : 'name'
)
}
/>
Expand Down
2 changes: 1 addition & 1 deletion querybook/webapp/const/metastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ export interface ITableColumnStats {
}

export type SchemaSortKey = 'name' | 'table_count';
export type SchemaTableSortKey = 'name' | 'importance_score';
export type SchemaTableSortKey = 'name' | 'relevance';
export const tableNameDraggableType = 'TableName-';
export const tableNameDataTransferName = 'tableName';
8 changes: 3 additions & 5 deletions querybook/webapp/redux/dataTableSearch/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function searchDataTable(): ThunkResult<Promise<ITableSearchResult[]>> {
const tableSortAsc = tableSort.asc ? 'asc' : 'desc';
search['sort_key'] = ['schema', 'name'];
search['sort_order'] = [tableSortAsc, tableSortAsc];
} else if (tableSort.key === 'importance_score') {
} else if (tableSort.key === 'relevance') {
search['sort_key'] = '_score';
search['sort_order'] = 'desc';
}
Expand Down Expand Up @@ -201,10 +201,8 @@ export function searchTableBySchema(
schema: schemaName,
},
}),
sort_key:
orderBy.key === 'importance_score' ? '_score' : orderBy.key,
sort_order:
orderBy.key === 'importance_score' ? 'desc' : sortOrder,
sort_key: orderBy.key === 'relevance' ? '_score' : orderBy.key,
sort_order: orderBy.key === 'relevance' ? 'desc' : sortOrder,
offset: resultsCount,
});
dispatch({
Expand Down
6 changes: 6 additions & 0 deletions querybook/webapp/redux/dataTableSearch/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ export const defaultSortSchemaTableBy: SchemaSortByIds[keyof SchemaSortByIds] =
asc: true,
key: 'name',
};

export const defaultSortSearchTableBy: SchemaSortByIds[keyof SchemaSortByIds] =
{
key: 'relevance',
asc: true, // Ignored for relevance, but when user switch to name asc would be true
};
8 changes: 6 additions & 2 deletions querybook/webapp/redux/dataTableSearch/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { produce } from 'immer';

import { defaultSortSchemaBy, defaultSortSchemaTableBy } from './const';
import {
defaultSortSchemaBy,
defaultSortSearchTableBy,
defaultSortSchemaTableBy,
} from './const';
import {
DataTableSearchAction,
IDataTableSearchPaginationState,
Expand All @@ -25,7 +29,7 @@ const initialState: IDataTableSearchState = {
searchString: '',
searchRequest: null,
metastoreId: null,
sortTablesBy: defaultSortSchemaTableBy,
sortTablesBy: defaultSortSearchTableBy,
...initialResultState,
};

Expand Down

0 comments on commit a18cc93

Please sign in to comment.