Skip to content

Commit 8e9655f

Browse files
authored
feat(schema-hints): Adjust search bar width when drawer open (#90232)
Part of the search bar was hidden behind the drawer so you may not be able to see what you're putting into the search bar. I've adjusted the logic so that the search bar width conforms to be visible when the drawer is open and resized (to a certain extent otherwise the search bar becomes too small). This is what it looks like: <img width="1433" alt="image" src="https://github.com/user-attachments/assets/b61ea27c-96f9-41e7-a954-9b6b9c5765b1" />
1 parent 91498f4 commit 8e9655f

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

static/app/components/globalDrawer/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,14 @@ interface DrawerContextType {
9898
renderer: DrawerConfig['renderer'],
9999
options: DrawerConfig['options']
100100
) => void;
101+
panelRef: React.RefObject<HTMLDivElement | null>;
101102
}
102103

103104
const DrawerContext = createContext<DrawerContextType>({
104105
openDrawer: () => {},
105106
isDrawerOpen: false,
106107
closeDrawer: () => {},
108+
panelRef: {current: null},
107109
});
108110

109111
export function GlobalDrawer({children}: any) {
@@ -198,7 +200,7 @@ export function GlobalDrawer({children}: any) {
198200
: null;
199201

200202
return (
201-
<DrawerContext value={{closeDrawer, isDrawerOpen, openDrawer}}>
203+
<DrawerContext value={{closeDrawer, isDrawerOpen, openDrawer, panelRef}}>
202204
<ErrorBoundary mini message={t('There was a problem rendering the drawer.')}>
203205
<AnimatePresence>
204206
{isDrawerOpen && (

static/app/views/explore/components/schemaHints/schemaHintsList.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jest.mock('sentry/components/searchQueryBuilder/context', () => ({
2727
query: '',
2828
getTagValues: () => Promise.resolve(['tagValue1', 'tagValue2']),
2929
dispatch: mockDispatch,
30+
wrapperRef: {current: null},
3031
}),
3132
SearchQueryBuilderProvider: ({children}: {children: React.ReactNode}) => children,
3233
}));

static/app/views/explore/components/schemaHints/schemaHintsList.tsx

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ function SchemaHintsList({
102102
const schemaHintsContainerRef = useRef<HTMLDivElement>(null);
103103
const location = useLocation();
104104
const organization = useOrganization();
105-
const {openDrawer, isDrawerOpen} = useDrawer();
106-
const {dispatch, query} = useSearchQueryBuilder();
105+
const {openDrawer, isDrawerOpen, panelRef} = useDrawer();
106+
const {dispatch, query, wrapperRef: searchBarWrapperRef} = useSearchQueryBuilder();
107107

108108
// Create a ref to hold the latest query for the drawer
109109
const queryRef = useRef(query);
@@ -237,6 +237,25 @@ function SchemaHintsList({
237237
return () => resizeObserver.disconnect();
238238
}, [filterTagsSorted, isDrawerOpen, isLoading, tagListState]);
239239

240+
// ensures the search bar is the correct width when the drawer is open
241+
useEffect(() => {
242+
const adjustSearchBarWidth = () => {
243+
if (isDrawerOpen && searchBarWrapperRef.current && panelRef.current) {
244+
searchBarWrapperRef.current.style.width = `calc(100% - ${panelRef.current.clientWidth}px)`;
245+
}
246+
};
247+
248+
adjustSearchBarWidth();
249+
250+
const resizeObserver = new ResizeObserver(adjustSearchBarWidth);
251+
252+
if (panelRef.current) {
253+
resizeObserver.observe(panelRef.current);
254+
}
255+
256+
return () => resizeObserver.disconnect();
257+
}, [isDrawerOpen, panelRef, searchBarWrapperRef]);
258+
240259
const onHintClick = useCallback(
241260
(hint: Tag) => {
242261
if (hint.key === seeFullListTag.key) {
@@ -273,13 +292,20 @@ function SchemaHintsList({
273292
drawer_open: true,
274293
organization,
275294
});
295+
if (searchBarWrapperRef.current) {
296+
searchBarWrapperRef.current.style.minWidth = '20%';
297+
}
276298
},
277299

278300
onClose: () => {
279301
trackAnalytics('trace.explorer.schema_hints_drawer', {
280302
drawer_open: false,
281303
organization,
282304
});
305+
if (searchBarWrapperRef.current) {
306+
searchBarWrapperRef.current.style.width = '100%';
307+
searchBarWrapperRef.current.style.minWidth = '';
308+
}
283309
},
284310
}
285311
);
@@ -315,6 +341,7 @@ function SchemaHintsList({
315341
dispatch,
316342
organization,
317343
isDrawerOpen,
344+
searchBarWrapperRef,
318345
openDrawer,
319346
filterTagsSorted,
320347
location.pathname,

0 commit comments

Comments
 (0)