diff --git a/package.json b/package.json index 1042a9daa..3e11ce40f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@devtron-labs/devtron-fe-common-lib", - "version": "0.0.58-beta-8", + "version": "0.0.58-beta-21", "description": "Supporting common component library", "main": "dist/index.js", "scripts": { diff --git a/src/Common/SearchBar/SearchBar.component.tsx b/src/Common/SearchBar/SearchBar.component.tsx index 0386a60f2..c749ed3be 100644 --- a/src/Common/SearchBar/SearchBar.component.tsx +++ b/src/Common/SearchBar/SearchBar.component.tsx @@ -55,9 +55,11 @@ const SearchBar = ({ debounceTimeout, ]) - // In most case would reset the state by doing history.push('/') + // assuming initialSearchText will change if we are changing history otherwise will be constant and will not change + // since on changing history we expect to make api call using useAsync so not applying handleEnter useEffect(() => { inputRef.current.value = initialSearchText + setShowClearButton(!!initialSearchText) }, [initialSearchText]) const _applySearch = (value: string) => { @@ -75,11 +77,6 @@ const SearchBar = ({ const { value } = e.target setShowClearButton(!!value) - if (!value) { - clearSearch() - return - } - if (shouldDebounce) { debouncedSearchChange(value) } else { @@ -91,6 +88,7 @@ const SearchBar = ({ const { key } = e if (key === 'Enter') { + e.preventDefault() const inputTarget = e.target as HTMLInputElement const value = inputTarget.value.trim() _applySearch(value) diff --git a/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx b/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx index bbdc65ff6..ea0de2fca 100644 --- a/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx +++ b/src/Pages/GlobalConfigurations/BuildInfra/constants.tsx @@ -29,7 +29,7 @@ export const BUILD_INFRA_TEXT = { DESCRIPTION_LABEL: 'Description', DESCRIPTION_PLACEHOLDER: 'Enter a description here', PROFILE_LABEL: 'Profile name', - PROFILE_PLACEHOLDER: 'Eg. Java or Node', + PROFILE_PLACEHOLDER: 'Eg. java or node', INHERITING_HEADING_DESCRIPTION: 'Inheriting from default', SUBMIT_BUTTON_TIPPY: { INVALID_INPUT: 'Valid input is required for all mandatory fields.', diff --git a/src/Shared/Helpers.tsx b/src/Shared/Helpers.tsx new file mode 100644 index 000000000..4f1ad9ccd --- /dev/null +++ b/src/Shared/Helpers.tsx @@ -0,0 +1,29 @@ +interface HighlightSearchTextProps { + /** + * The text to be highlighted + */ + searchText: string + /** + * The whole text string + */ + text: string + /** + * The classes to be applied to the highlighted text + */ + highlightClasses?: string +} + +// Disabling default export since this is a helper function and we would have to export a lot of functions in future. +// eslint-disable-next-line import/prefer-default-export +export const highlightSearchText = ({ searchText, text, highlightClasses }: HighlightSearchTextProps): string => { + if (!searchText) { + return text + } + + try { + const regex = new RegExp(searchText, 'gi') + return text.replace(regex, (match) => `${match}`) + } catch (error) { + return text + } +} diff --git a/src/Shared/index.ts b/src/Shared/index.ts index 1877c8e0f..23a06016b 100644 --- a/src/Shared/index.ts +++ b/src/Shared/index.ts @@ -1,2 +1,3 @@ export * from './Components' export * from './validations' +export * from './Helpers'