Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(app overview): enable search for numeric and special characters #1179

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
- **Technical User Management**
- enhanced technical user details [#1030](https://github.com/eclipse-tractusx/portal-frontend/pull/1030), [#1093](https://github.com/eclipse-tractusx/portal-frontend/pull/1093)
- added Usertype column to technical user management list [#1090](https://github.com/eclipse-tractusx/portal-frontend/pull/1090)
- **Numeric and Special Characters for Search in AppOverview**
- updated the regex for search validation[#1179] (https://github.com/eclipse-tractusx/portal-frontend/pull/1179)
Usmanfee marked this conversation as resolved.
Show resolved Hide resolved

### Change

Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/AppOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { fetchImageWithToken } from 'services/ImageService'
import { setCurrentActiveStep } from 'features/appManagement/slice'
import { setAppId, setAppStatus } from 'features/appManagement/actions'
import NoItems from '../NoItems'
import { isValidAppOverviewSearch } from 'types/Patterns'

export default function AppOverview() {
const { t } = useTranslation()
Expand Down Expand Up @@ -222,8 +223,7 @@ export default function AppOverview() {

const doSearch = useCallback(
(expr: string) => {
const validateExpr = /^[ A-Za-z]*$/.test(expr)
if (!validateExpr) {
if (!isValidAppOverviewSearch(expr)) {
return
}
setSearchExpr(expr)
Expand Down
13 changes: 13 additions & 0 deletions src/types/Patterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isClientID,
isPersonName,
isSearchUserEmail,
isValidAppOverviewSearch,
} from './Patterns'

const TESTDATA = {
Expand Down Expand Up @@ -255,6 +256,10 @@ const TESTDATA = {
],
invalid: ['()*&^%$#/\\?><,`~'],
},
appOverview: {
valid: ['sa-12', '1234', 'Test123!@#'],
invalid: ['🚀 Rocket!', 'Invalid\nNewLine'],
},
}

describe('Input Pattern Tests', () => {
Expand Down Expand Up @@ -354,4 +359,12 @@ describe('Input Pattern Tests', () => {
expect(isSearchUserEmail(expr)).toBe(false)
})
})
it('validate appoverview search', () => {
TESTDATA.appOverview.valid.forEach((expr) => {
expect(isValidAppOverviewSearch(expr)).toBe(true)
})
TESTDATA.appOverview.invalid.forEach((expr) => {
expect(isValidAppOverviewSearch(expr)).toBe(false)
})
})
})
5 changes: 5 additions & 0 deletions src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ export const Patterns = {
/^(?!.*\s$)(?=[a-zA-Z\d-]{0,10}[-\s]?[a-zA-Z\d-]{0,10}$)[a-zA-Z\d\s-]{2,10}$/,
},
EMAIL_SEARCH: /^[ A-Za-z0-9._!@+-]*$/,
appOverview: {
SEARCH: /^[ A-Za-z0-9!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]*$/,
},
}

export const isEmpty = (expr: string) => !expr || expr.trim() === ''
Expand Down Expand Up @@ -208,5 +211,7 @@ export const isPostalCode = (expr: string) =>
Patterns.companyData.POSTAL_CODE.test(expr)
export const isSearchUserEmail = (expr: string) =>
Patterns.EMAIL_SEARCH.test(expr)
export const isValidAppOverviewSearch = (expr: string) =>
Patterns.appOverview.SEARCH.test(expr)

export default Patterns
Loading