Skip to content

Commit f2279a4

Browse files
authored
Revert "feat: make redirects via the input component case-insensitive" (#877)
This reverts commit 30eefe2 / #875. Reason being I made it a minor bump when it should probably be major, considering that the changes to the component may change the current behaviour of users' redirects if they rely on case-sensitivity of their redirects.
1 parent 63dc758 commit f2279a4

File tree

7 files changed

+15
-83
lines changed

7 files changed

+15
-83
lines changed

.changeset/dry-lions-clean.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'sajari-sdk-docs': patch
3+
'@sajari/react-search-ui': patch
4+
---
5+
6+
chore: revert "feat: make redirects via the input component case-insensitive"

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"react/react-in-jsx-scope": "off",
1414

1515
// TODO: We should re-enable this if we think it's worthwhile
16-
"@typescript-eslint/explicit-module-boundary-types": "off",
17-
"no-plusplus": "off"
16+
"@typescript-eslint/explicit-module-boundary-types": "off"
1817
},
1918
"settings": {
2019
"react": {

docs/pages/search-ui/input.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ function Example() {
133133
}
134134
```
135135
136-
### Note
137-
138-
The `Input` component treats redirects as _case-insensitive_, meaning the user-inputted value `Computer` returns the redirect for the query `computer` and vice versa.
139-
140-
The component does not support the handling of multiple redirects for queries of the same word with varied letter casing. For example, if you have created redirects for each of the queries `computer`, `Computer`, and `COMPUTER`, only one of them is used (dependent upon your browser).
141-
142136
## Results
143137
144138
```jsx

packages/search-ui/src/Input/index.test.tsx

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ const redirectTarget = {
1616
token:
1717
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwdXJwb3NlIjoic2VhcmNoIiwiZGVzdGluYXRpb24iOiJodHRwOi8vdGFyZ2V0LmNvbS5hdS9zaGVldHMiLCJ2YWx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SUQiOlsiMjJ3MFZGdkdWYVlhQ1Jzc0NBUm11YkQ2bGdUIl0sInJlZGlyZWN0LlRhcmdldCI6WyJodHRwOi8vdGFyZ2V0LmNvbS5hdS9zaGVldHMiXX19.BhcAVPB4z9LjlIoV42CUaEW-H0qCJ2JKngs6OGAXTf9',
24-
};
2519
const iPhoneResult = {
2620
values: {
2721
_id: {
@@ -55,11 +49,10 @@ const server = setupServer(
5549
values: {
5650
q: 'sheets',
5751
'q.original': 'sheets',
58-
'q.suggestions': 'suggestion',
52+
'q.suggestions': 'sheets',
5953
},
6054
redirects: {
6155
sheets: redirectTarget,
62-
Sheets: redirectTarget2,
6356
},
6457
searchResponse: {
6558
reads: '141',
@@ -84,7 +77,6 @@ describe('Input', () => {
8477
});
8578
afterEach(() => {
8679
jest.clearAllMocks();
87-
jest.resetAllMocks();
8880
server.resetHandlers();
8981
});
9082
afterAll(() => {
@@ -100,12 +92,12 @@ describe('Input', () => {
10092
const input = screen.getByTestId('mysearch');
10193
input.focus(); // need this else we get TypeError: element.ownerDocument.getSelection is not a function
10294
await user.keyboard('sheets');
103-
await waitFor(() => expect(screen.getByRole('option')).toHaveTextContent('suggestion'));
95+
await waitFor(() => expect(screen.getByText('sheets')).toBeInTheDocument());
10496
await user.keyboard('{enter}');
10597

10698
expect(onRedirectSpy).toHaveBeenCalledWith({
107-
...redirectTarget2,
108-
token: `https://re.sajari.com/token/${redirectTarget2.token}`, // sdk-js appends the clickTokenURL
99+
...redirectTarget,
100+
token: `https://re.sajari.com/token/${redirectTarget.token}`, // sdk-js prepends the clickTokenURL
109101
});
110102
});
111103

@@ -164,31 +156,3 @@ describe('Input', () => {
164156
await waitFor(() => expect(input.attributes.getNamedItem('readonly')).toBeNull());
165157
});
166158
});
167-
168-
describe('redirects', () => {
169-
beforeAll(() => {
170-
server.listen({ onUnhandledRequest: 'warn' });
171-
});
172-
afterAll(() => {
173-
jest.restoreAllMocks();
174-
server.close();
175-
});
176-
177-
it('ignores letter casing of input query on redirect lookup', async () => {
178-
const onRedirectSpy = jest.spyOn(eventTrackingPipeline.getTracking(), 'onRedirect');
179-
customRender(<Input data-testid="mysearch" mode="suggestions" />, {
180-
search: { pipeline: eventTrackingPipeline },
181-
});
182-
const input = screen.getByTestId('mysearch');
183-
input.focus(); // need this else we get TypeError: element.ownerDocument.getSelection is not a function
184-
await userEvent.type(input, 'ShEeTs');
185-
await waitFor(() => expect(screen.getByRole('option')).toHaveTextContent('suggestion'));
186-
await userEvent.keyboard('{enter}');
187-
await waitFor(() => {
188-
expect(onRedirectSpy).toHaveBeenCalledWith({
189-
...redirectTarget2,
190-
token: `https://re.sajari.com/token/${redirectTarget2.token}`, // sdk-js appends the clickTokenURL
191-
});
192-
});
193-
});
194-
});

packages/search-ui/src/Input/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { useSearchUIContext } from '../ContextProvider';
1010
import { ResultValues } from '../Results/types';
1111
import mapResultFields from '../utils/mapResultFields';
1212
import { InputProps } from './types';
13-
import { lowercaseObjectKeys } from './utils';
1413

1514
const Input = React.forwardRef((props: InputProps<any>, ref: React.ForwardedRef<HTMLInputElement>) => {
1615
const { t } = useTranslation('input');
@@ -37,9 +36,8 @@ const Input = React.forwardRef((props: InputProps<any>, ref: React.ForwardedRef<
3736
redirects,
3837
searching: autocompleteSearching,
3938
} = useAutocomplete();
40-
const lowercasedRedirects = lowercaseObjectKeys(redirects);
41-
const redirectsRef = useRef(lowercasedRedirects);
42-
redirectsRef.current = lowercasedRedirects;
39+
const redirectsRef = useRef(redirects);
40+
redirectsRef.current = redirects;
4341
const { customClassNames, disableDefaultStyles = false, tracking } = useSearchUIContext();
4442
const { query } = useQuery();
4543
const [internalSuggestions, setInternalSuggestions] = useState<Array<any>>([]);
@@ -176,7 +174,7 @@ const Input = React.forwardRef((props: InputProps<any>, ref: React.ForwardedRef<
176174
if (!retainFilters) {
177175
resetFilters();
178176
}
179-
const redirectValue = redirectsRef.current[value.toLowerCase()];
177+
const redirectValue = redirectsRef.current[value];
180178
if (!disableRedirects && redirectValue) {
181179
tracking.onRedirect(redirectValue);
182180
window.location.assign(redirectValue.token || redirectValue.target);
@@ -185,7 +183,7 @@ const Input = React.forwardRef((props: InputProps<any>, ref: React.ForwardedRef<
185183
// If we're performing an autocomplete search, wait a tick to recheck redirects before unloading
186184
e.preventDefault();
187185
setTimeout(() => {
188-
const redirectTarget = redirectsRef.current[value.toLowerCase()];
186+
const redirectTarget = redirectsRef.current[value];
189187
if (redirectTarget) {
190188
tracking.onRedirect(redirectTarget);
191189
window.location.assign(redirectTarget.token || redirectTarget.target);

packages/search-ui/src/Input/utils/index.test.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/search-ui/src/Input/utils/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)