(Server) Fix Unresponsive Header Input
Summary: Before this diff, the input bar is unresponsive to the user input; when one typed fast enough the input doesn't reflect that as shown in the before video (the console printed the log directly when `onChange` was fired). This diff tried to store value locally and use that to render. When the component is closed, the state update will take place. This tried to solve too many state update. Reviewed By: mweststrate Differential Revision: D20489142 fbshipit-source-id: c118adc61d9234daec17782e4bbf8e4ea3dd369f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ddf5df98c7
commit
d60125bd5e
@@ -78,7 +78,7 @@ const StyledInput = styled(Input)({
|
|||||||
flexGrow: 5,
|
flexGrow: 5,
|
||||||
});
|
});
|
||||||
|
|
||||||
const HeaderInput = styled(Input)({
|
const HeaderStyledInput = styled(Input)({
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: 20,
|
height: 20,
|
||||||
marginTop: 6,
|
marginTop: 6,
|
||||||
@@ -139,14 +139,32 @@ const HeadersColumns = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const selectedHighlight = {backgroundColor: colors.highlight};
|
||||||
|
|
||||||
|
function HeaderInput(props: {
|
||||||
|
initialValue: string;
|
||||||
|
isSelected: boolean;
|
||||||
|
onUpdate: (newValue: string) => void;
|
||||||
|
}) {
|
||||||
|
const [value, setValue] = useState(props.initialValue);
|
||||||
|
return (
|
||||||
|
<HeaderStyledInput
|
||||||
|
type="text"
|
||||||
|
placeholder="Name"
|
||||||
|
value={value}
|
||||||
|
style={props.isSelected ? selectedHighlight : undefined}
|
||||||
|
onChange={event => setValue(event.target.value)}
|
||||||
|
onBlur={() => props.onUpdate(value)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function _buildMockResponseHeaderRows(
|
function _buildMockResponseHeaderRows(
|
||||||
routeId: string,
|
routeId: string,
|
||||||
route: Route,
|
route: Route,
|
||||||
selectedHeaderId: string | null,
|
selectedHeaderId: string | null,
|
||||||
networkRouteManager: NetworkRouteManager,
|
networkRouteManager: NetworkRouteManager,
|
||||||
) {
|
) {
|
||||||
const selectedHighlight = {backgroundColor: colors.highlight};
|
|
||||||
|
|
||||||
return Object.entries(route.responseHeaders).map(([id, header]) => {
|
return Object.entries(route.responseHeaders).map(([id, header]) => {
|
||||||
const selected = selectedHeaderId === id;
|
const selected = selectedHeaderId === id;
|
||||||
return {
|
return {
|
||||||
@@ -154,18 +172,13 @@ function _buildMockResponseHeaderRows(
|
|||||||
name: {
|
name: {
|
||||||
value: (
|
value: (
|
||||||
<HeaderInput
|
<HeaderInput
|
||||||
type="text"
|
initialValue={header.key}
|
||||||
placeholder="Name"
|
isSelected={selected}
|
||||||
value={header.key}
|
onUpdate={(newValue: string) => {
|
||||||
style={selected ? selectedHighlight : {}}
|
|
||||||
onChange={event => {
|
|
||||||
if (!selected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newHeaders = produce(
|
const newHeaders = produce(
|
||||||
route.responseHeaders,
|
route.responseHeaders,
|
||||||
draftHeaders => {
|
draftHeaders => {
|
||||||
draftHeaders[id].key = event.target.value;
|
draftHeaders[id].key = newValue;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
networkRouteManager.modifyRoute(routeId, {
|
networkRouteManager.modifyRoute(routeId, {
|
||||||
@@ -178,18 +191,13 @@ function _buildMockResponseHeaderRows(
|
|||||||
value: {
|
value: {
|
||||||
value: (
|
value: (
|
||||||
<HeaderInput
|
<HeaderInput
|
||||||
type="text"
|
initialValue={header.value}
|
||||||
placeholder="Value"
|
isSelected={selected}
|
||||||
value={header.value}
|
onUpdate={(newValue: string) => {
|
||||||
style={selected ? selectedHighlight : {}}
|
|
||||||
onChange={event => {
|
|
||||||
if (!selected) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newHeaders = produce(
|
const newHeaders = produce(
|
||||||
route.responseHeaders,
|
route.responseHeaders,
|
||||||
draftHeaders => {
|
draftHeaders => {
|
||||||
draftHeaders[id].value = event.target.value;
|
draftHeaders[id].value = newValue;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
networkRouteManager.modifyRoute(routeId, {
|
networkRouteManager.modifyRoute(routeId, {
|
||||||
|
|||||||
Reference in New Issue
Block a user