From 80e5b85977523f14c1bb14ea90cb0cc73f4aa59d Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Sep 2021 15:55:09 +0200 Subject: SONAR-15366 Add Settings Search feature --- .../settings/components/SettingsSearchRenderer.tsx | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 server/sonar-web/src/main/js/apps/settings/components/SettingsSearchRenderer.tsx (limited to 'server/sonar-web/src/main/js/apps/settings/components/SettingsSearchRenderer.tsx') diff --git a/server/sonar-web/src/main/js/apps/settings/components/SettingsSearchRenderer.tsx b/server/sonar-web/src/main/js/apps/settings/components/SettingsSearchRenderer.tsx new file mode 100644 index 00000000000..c52febbcb5c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/settings/components/SettingsSearchRenderer.tsx @@ -0,0 +1,103 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as classNames from 'classnames'; +import * as React from 'react'; +import { Link } from 'react-router'; +import { DropdownOverlay } from '../../../components/controls/Dropdown'; +import OutsideClickHandler from '../../../components/controls/OutsideClickHandler'; +import SearchBox from '../../../components/controls/SearchBox'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { scrollToElement } from '../../../helpers/scrolling'; +import { SettingCategoryDefinition } from '../../../types/settings'; +import { buildSettingLink, isRealSettingKey } from '../utils'; + +export interface SettingsSearchRendererProps { + className?: string; + results?: SettingCategoryDefinition[]; + searchQuery: string; + selectedResult?: string; + showResults: boolean; + onClickOutside: () => void; + onMouseOverResult: (key: string) => void; + onSearchInputChange: (query: string) => void; + onSearchInputFocus: () => void; + onSearchInputKeyDown: (event: React.KeyboardEvent) => void; +} + +export default function SettingsSearchRenderer(props: SettingsSearchRendererProps) { + const { className, results, searchQuery, selectedResult, showResults } = props; + + const scrollableNodeRef = React.useRef(null); + const selectedNodeRef = React.useRef(null); + + React.useEffect(() => { + const parent = scrollableNodeRef.current; + const selectedNode = selectedNodeRef.current; + if (selectedNode && parent) { + scrollToElement(selectedNode, { topOffset: 30, bottomOffset: 30, parent }); + } + }); + + return ( + +
+ + {showResults && ( + +
    + {results && results.length > 0 ? ( + results.map(r => ( +
  • + props.onMouseOverResult(r.key)} + to={buildSettingLink(r)}> +
    +

    {r.name || r.subCategory}

    +
    + {isRealSettingKey(r.key) && ( +
    + {translateWithParameters('settings.key_x', r.key)} +
    + )} + +
  • + )) + ) : ( +
    {translate('no_results')}
    + )} +
+
+ )} +
+
+ ); +} -- cgit v1.2.3