Skip to content

Commit 5cac244

Browse files
authored
fix: explorer field filter input cursor reset (#7061)
1 parent 93967de commit 5cac244

File tree

3 files changed

+67
-38
lines changed

3 files changed

+67
-38
lines changed

.changeset/stale-mice-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'hive': patch
3+
---
4+
5+
fix explorer field input cursor reset

packages/web/app/src/components/target/explorer/filter.tsx

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from 'react';
1+
import React, { ChangeEvent, useCallback, useMemo } from 'react';
22
import { FilterIcon } from 'lucide-react';
33
import { useQuery } from 'urql';
44
import { Button } from '@/components/ui/button';
@@ -111,24 +111,33 @@ export function TypeFilter(props: {
111111
[allNamedTypes],
112112
);
113113

114+
const onChange = useCallback(
115+
(option: SelectOption | null) => {
116+
void router.navigate({
117+
search: router.latestLocation.search,
118+
to: '/$organizationSlug/$projectSlug/$targetSlug/explorer/$typename',
119+
params: {
120+
organizationSlug: props.organizationSlug,
121+
projectSlug: props.projectSlug,
122+
targetSlug: props.targetSlug,
123+
typename: option?.value ?? '',
124+
},
125+
});
126+
},
127+
[router],
128+
);
129+
130+
const defaultValue = useMemo(() => {
131+
return props.typename ? { value: props.typename, label: props.typename } : null;
132+
}, [props.typename]);
133+
114134
return (
115135
<Autocomplete
116136
className="min-w-[200px] grow cursor-text"
117137
placeholder="Search for a type"
118-
defaultValue={props.typename ? { value: props.typename, label: props.typename } : null}
138+
defaultValue={defaultValue}
119139
options={types}
120-
onChange={(option: SelectOption | null) => {
121-
void router.navigate({
122-
search: router.latestLocation.search,
123-
to: '/$organizationSlug/$projectSlug/$targetSlug/explorer/$typename',
124-
params: {
125-
organizationSlug: props.organizationSlug,
126-
projectSlug: props.projectSlug,
127-
targetSlug: props.targetSlug,
128-
typename: option?.value ?? '',
129-
},
130-
});
131-
}}
140+
onChange={onChange}
132141
loading={query.fetching}
133142
/>
134143
);
@@ -137,37 +146,48 @@ export function TypeFilter(props: {
137146
export function FieldByNameFilter() {
138147
const router = useRouter();
139148

149+
const onChange = useCallback(
150+
(e: ChangeEvent<HTMLInputElement>) => {
151+
void router.navigate({
152+
search: {
153+
...router.latestLocation.search,
154+
search: e.target.value === '' ? undefined : e.target.value,
155+
},
156+
replace: true,
157+
});
158+
},
159+
[router],
160+
);
161+
162+
const initialValue =
163+
'search' in router.latestLocation.search &&
164+
typeof router.latestLocation.search.search === 'string'
165+
? router.latestLocation.search.search
166+
: '';
167+
140168
return (
141169
<Input
142170
className="w-[200px] grow cursor-text"
143171
placeholder="Filter by field name"
144-
onChange={e => {
145-
void router.navigate({
146-
search: {
147-
...router.latestLocation.search,
148-
search: e.target.value === '' ? undefined : e.target.value,
149-
},
150-
});
151-
}}
152-
value={
153-
'search' in router.latestLocation.search &&
154-
typeof router.latestLocation.search.search === 'string'
155-
? router.latestLocation.search.search
156-
: ''
157-
}
172+
onChange={onChange}
173+
defaultValue={initialValue}
158174
/>
159175
);
160176
}
161177

162178
export function DateRangeFilter() {
163179
const periodSelector = usePeriodSelector();
180+
const onUpdate = useCallback(
181+
(value: { preset: { range: { from: string; to: string } } }) => {
182+
periodSelector.setPeriod(value.preset.range);
183+
},
184+
[periodSelector],
185+
);
164186

165187
return (
166188
<DateRangePicker
167189
validUnits={['y', 'M', 'w', 'd']}
168-
onUpdate={value => {
169-
periodSelector.setPeriod(value.preset.range);
170-
}}
190+
onUpdate={onUpdate}
171191
selectedRange={periodSelector.period}
172192
startDate={periodSelector.startDate}
173193
align="end"

packages/web/app/src/components/target/explorer/provider.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ export function useArgumentListToggle() {
152152
}
153153

154154
export function usePeriodSelector() {
155-
const { period, setPeriod, startDate, refreshResolvedPeriod } = useSchemaExplorerContext();
156-
return {
157-
setPeriod,
158-
period,
159-
startDate,
160-
refreshResolvedPeriod,
161-
};
155+
const ctx = useSchemaExplorerContext();
156+
const selector = useMemo(() => {
157+
const { period, setPeriod, startDate, refreshResolvedPeriod } = ctx;
158+
return {
159+
setPeriod,
160+
period,
161+
startDate,
162+
refreshResolvedPeriod,
163+
};
164+
}, [ctx]);
165+
return selector;
162166
}

0 commit comments

Comments
 (0)