-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat: deprecate support for 15, support react 16 features #1107
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -14,32 +14,26 @@ import HistoryQuery from './HistoryQuery'; | |||
const MAX_QUERY_SIZE = 100000; | ||||
const MAX_HISTORY_LENGTH = 20; | ||||
|
||||
const shouldSaveQuery = (nextProps, current, lastQuerySaved) => { | ||||
if (nextProps.queryID === current.queryID) { | ||||
return false; | ||||
} | ||||
const shouldSaveQuery = (query, variables, lastQuerySaved) => { | ||||
try { | ||||
parse(nextProps.query); | ||||
parse(query); | ||||
} catch (e) { | ||||
return false; | ||||
} | ||||
// Don't try to save giant queries | ||||
if (nextProps.query.length > MAX_QUERY_SIZE) { | ||||
if (query.length > MAX_QUERY_SIZE) { | ||||
return false; | ||||
} | ||||
if (!lastQuerySaved) { | ||||
return true; | ||||
} | ||||
if ( | ||||
JSON.stringify(nextProps.query) === JSON.stringify(lastQuerySaved.query) | ||||
) { | ||||
if (JSON.stringify(query) === JSON.stringify(lastQuerySaved.query)) { | ||||
if ( | ||||
JSON.stringify(nextProps.variables) === | ||||
JSON.stringify(lastQuerySaved.variables) | ||||
JSON.stringify(variables) === JSON.stringify(lastQuerySaved.variables) | ||||
) { | ||||
return false; | ||||
} | ||||
if (!nextProps.variables && !lastQuerySaved.variables) { | ||||
if (variables && !lastQuerySaved.variables) { | ||||
return false; | ||||
} | ||||
} | ||||
|
@@ -71,25 +65,6 @@ export class QueryHistory extends React.Component { | |||
this.state = { queries }; | ||||
} | ||||
|
||||
componentWillReceiveProps(nextProps) { | ||||
if ( | ||||
shouldSaveQuery(nextProps, this.props, this.historyStore.fetchRecent()) | ||||
) { | ||||
const item = { | ||||
query: nextProps.query, | ||||
variables: nextProps.variables, | ||||
operationName: nextProps.operationName, | ||||
}; | ||||
this.historyStore.push(item); | ||||
const historyQueries = this.historyStore.items; | ||||
const favoriteQueries = this.favoriteStore.items; | ||||
const queries = historyQueries.concat(favoriteQueries); | ||||
this.setState({ | ||||
queries, | ||||
}); | ||||
} | ||||
} | ||||
|
||||
render() { | ||||
const queries = this.state.queries.slice().reverse(); | ||||
const queryNodes = queries.map((query, i) => { | ||||
|
@@ -114,6 +89,24 @@ export class QueryHistory extends React.Component { | |||
); | ||||
} | ||||
|
||||
// Public API | ||||
updateHistory = (query, variables, operationName) => { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed in other areas that public methods were marked with a e.g.:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure yes! we are about to deprecate this “plugin api” possibly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I figured this would go away once we moved to more React 16 patterns anyways but good to make it clear and consistent until then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep! this reminded me i need to add a deprecation notice |
||||
if (shouldSaveQuery(query, variables, this.historyStore.fetchRecent())) { | ||||
this.historyStore.push({ | ||||
query, | ||||
variables, | ||||
operationName, | ||||
}); | ||||
const historyQueries = this.historyStore.items; | ||||
const favoriteQueries = this.favoriteStore.items; | ||||
const queries = historyQueries.concat(favoriteQueries); | ||||
this.setState({ | ||||
queries, | ||||
}); | ||||
} | ||||
}; | ||||
|
||||
// Public API | ||||
toggleFavorite = (query, variables, operationName, label, favorite) => { | ||||
const item = { | ||||
query, | ||||
|
@@ -133,6 +126,7 @@ export class QueryHistory extends React.Component { | |||
}); | ||||
}; | ||||
|
||||
// Public API | ||||
editLabel = (query, variables, operationName, label, favorite) => { | ||||
const item = { | ||||
query, | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright (c) 2019 GraphQL Contributors. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import HistoryQuery from '../HistoryQuery'; | ||
import { mockOperationName1, mockQuery1, mockVariables1 } from './fixtures'; | ||
|
||
const noOp = () => {}; | ||
|
||
const baseMockProps = { | ||
favorite: false, | ||
handleEditLabel: noOp, | ||
handleToggleFavorite: noOp, | ||
onSelect: noOp, | ||
query: mockQuery1, | ||
variables: mockVariables1, | ||
}; | ||
|
||
function getMockProps(customProps) { | ||
return { | ||
...baseMockProps, | ||
...customProps, | ||
}; | ||
} | ||
|
||
describe('HistoryQuery', () => { | ||
it('renders operationName if label is not provided', () => { | ||
const otherMockProps = { operationName: mockOperationName1 }; | ||
const props = getMockProps(otherMockProps); | ||
const W = mount(<HistoryQuery {...props} />); | ||
expect( | ||
W.find('button.history-label') | ||
.first() | ||
.text(), | ||
).toBe(mockOperationName1); | ||
}); | ||
|
||
it('renders a string version of the query if label or operation name are not provided', () => { | ||
const W = mount(<HistoryQuery {...getMockProps()} />); | ||
expect( | ||
W.find('button.history-label') | ||
.first() | ||
.text(), | ||
).toBe( | ||
mockQuery1 | ||
.split('\n') | ||
.filter(line => line.indexOf('#') !== 0) | ||
.join(''), | ||
); | ||
}); | ||
|
||
it('calls onSelect with the correct arguments when history label button is clicked', () => { | ||
const onSelectSpy = jest.spyOn(baseMockProps, 'onSelect'); | ||
const otherMockProps = { | ||
operationName: mockOperationName1, | ||
}; | ||
const W = mount(<HistoryQuery {...getMockProps(otherMockProps)} />); | ||
W.find('button.history-label').simulate('click'); | ||
W.update(); | ||
expect(onSelectSpy).toHaveBeenCalledWith( | ||
mockQuery1, | ||
mockVariables1, | ||
mockOperationName1, | ||
undefined, | ||
); | ||
}); | ||
|
||
it('renders label input if the edit label button is clicked', () => { | ||
const W = mount(<HistoryQuery {...getMockProps()} />); | ||
W.find({ 'aria-label': 'Edit label' }) | ||
.first() | ||
.simulate('click'); | ||
W.update(); | ||
expect(W.find('li.editable').length).toBe(1); | ||
expect(W.find('input').length).toBe(1); | ||
expect(W.find('button.history-label').length).toBe(0); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error is misleading; e.g. if they were to use React 17 or 18 in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will likely remove this before react 17. i can add a todo for that