mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
keep ordering on search (#7520)
This commit is contained in:
@@ -10,6 +10,10 @@ export interface PaginationOptions {
|
||||
itemsPerPage?: number;
|
||||
}
|
||||
|
||||
export interface SearchOptions {
|
||||
isServerSideFTS?: boolean;
|
||||
}
|
||||
|
||||
export interface Controller<I, P = any> {
|
||||
params: P; // TODO: Find out what params is (except merging with props)
|
||||
|
||||
@@ -18,7 +22,7 @@ export interface Controller<I, P = any> {
|
||||
|
||||
// search
|
||||
searchTerm?: string;
|
||||
updateSearch: (searchTerm: string) => void;
|
||||
updateSearch: (searchTerm: string, searchOptions?: SearchOptions) => void;
|
||||
|
||||
// tags
|
||||
selectedTags: string[];
|
||||
|
||||
@@ -135,13 +135,13 @@ export class ItemsSource {
|
||||
this._changed({ sorting: true });
|
||||
};
|
||||
|
||||
updateSearch = (searchTerm) => {
|
||||
updateSearch = (searchTerm, options) => {
|
||||
// here we update state directly, but later `fetchData` will update it properly
|
||||
this._searchTerm = searchTerm;
|
||||
// in search mode ignore the ordering and use the ranking order
|
||||
// provided by the server-side FTS backend instead, unless it was
|
||||
// requested by the user by actively ordering in search mode
|
||||
if (searchTerm === "") {
|
||||
if (searchTerm === "" || !options?.isServerSideFTS) {
|
||||
this._sorter.setField(this._savedOrderByField); // restore ordering
|
||||
} else {
|
||||
this._sorter.setField(null);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import React, { useCallback, useEffect, useRef } from "react";
|
||||
import cx from "classnames";
|
||||
|
||||
import routeWithUserSession from "@/components/ApplicationArea/routeWithUserSession";
|
||||
@@ -20,7 +20,7 @@ import ItemsTable, { Columns } from "@/components/items-list/components/ItemsTab
|
||||
import Layout from "@/components/layouts/ContentWithSidebar";
|
||||
|
||||
import { Query } from "@/services/query";
|
||||
import { currentUser } from "@/services/auth";
|
||||
import { clientConfig, currentUser } from "@/services/auth";
|
||||
import location from "@/services/location";
|
||||
import routes from "@/services/routes";
|
||||
|
||||
@@ -95,18 +95,25 @@ function QueriesList({ controller }) {
|
||||
const controllerRef = useRef();
|
||||
controllerRef.current = controller;
|
||||
|
||||
const updateSearch = useCallback(
|
||||
(searchTemm) => {
|
||||
controller.updateSearch(searchTemm, { isServerSideFTS: !clientConfig.multiByteSearchEnabled });
|
||||
},
|
||||
[controller]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const unlistenLocationChanges = location.listen((unused, action) => {
|
||||
const searchTerm = location.search.q || "";
|
||||
if (action === "PUSH" && searchTerm !== controllerRef.current.searchTerm) {
|
||||
controllerRef.current.updateSearch(searchTerm);
|
||||
updateSearch(searchTerm);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
unlistenLocationChanges();
|
||||
};
|
||||
}, []);
|
||||
}, [updateSearch]);
|
||||
|
||||
const {
|
||||
areExtraActionsAvailable,
|
||||
@@ -135,7 +142,7 @@ function QueriesList({ controller }) {
|
||||
placeholder="Search Queries..."
|
||||
label="Search queries"
|
||||
value={controller.searchTerm}
|
||||
onChange={controller.updateSearch}
|
||||
onChange={updateSearch}
|
||||
/>
|
||||
<Sidebar.Menu items={sidebarMenu} selected={controller.params.currentPage} />
|
||||
<Sidebar.Tags url="api/queries/tags" onChange={controller.updateSelectedTags} showUnselectAll />
|
||||
|
||||
@@ -278,6 +278,7 @@ def client_config():
|
||||
"showPermissionsControl": current_org.get_setting("feature_show_permissions_control"),
|
||||
"hidePlotlyModeBar": current_org.get_setting("hide_plotly_mode_bar"),
|
||||
"disablePublicUrls": current_org.get_setting("disable_public_urls"),
|
||||
"multiByteSearchEnabled": current_org.get_setting("multi_byte_search_enabled"),
|
||||
"allowCustomJSVisualizations": settings.FEATURE_ALLOW_CUSTOM_JS_VISUALIZATIONS,
|
||||
"autoPublishNamedQueries": settings.FEATURE_AUTO_PUBLISH_NAMED_QUERIES,
|
||||
"extendedAlertOptions": settings.FEATURE_EXTENDED_ALERT_OPTIONS,
|
||||
|
||||
Reference in New Issue
Block a user