-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yuri Roncella <[email protected]>
- Loading branch information
Yuri Roncella
committed
Feb 8, 2019
1 parent
0f71029
commit 2301364
Showing
7 changed files
with
209 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/jaeger-ui/src/components/SearchTracePage/FileUploader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import * as React from 'react'; | ||
import { Upload, Icon } from 'antd'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { bindActionCreators } from 'redux'; | ||
|
||
import * as jaegerApiActions from '../../actions/jaeger-api'; | ||
|
||
const Dragger = Upload.Dragger; | ||
|
||
export function FileUploaderImpl(props) { | ||
const { loadTracesFromFile } = props; | ||
return ( | ||
<Dragger accept=".json" customRequest={loadTracesFromFile}> | ||
<p className="ant-upload-drag-icon"> | ||
<Icon type="inbox" /> | ||
</p> | ||
<p className="ant-upload-text">Click or drag file to this area to upload</p> | ||
<p className="ant-upload-hint">Support a JSON file containig one or more traces.</p> | ||
</Dragger> | ||
); | ||
} | ||
|
||
FileUploaderImpl.propTypes = { | ||
loadTracesFromFile: PropTypes.func.isRequired, | ||
}; | ||
|
||
function mapDispatchToProps(dispatch) { | ||
const { loadTracesFromFile } = bindActionCreators(jaegerApiActions, dispatch); | ||
return { | ||
loadTracesFromFile, | ||
}; | ||
} | ||
|
||
export default connect(null, mapDispatchToProps)(FileUploaderImpl); |
30 changes: 30 additions & 0 deletions
30
packages/jaeger-ui/src/components/SearchTracePage/FileUploader.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
|
||
import { FileUploaderImpl as FileUploader } from './FileUploader'; | ||
|
||
describe('<FileUploader />', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<FileUploader />); | ||
}); | ||
|
||
it('does not explode', () => { | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
const fileReader = { | ||
readJSONFile(fileList) { | ||
return new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.onloadend = () => { | ||
resolve(reader.result); | ||
}; | ||
reader.onerror = () => { | ||
reject(); | ||
}; | ||
reader.onabort = () => { | ||
reject(); | ||
}; | ||
reader.readAsText(fileList.file); | ||
}).then(result => JSON.parse(result)); | ||
}, | ||
}; | ||
|
||
export default fileReader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import isPromise from 'is-promise'; | ||
import sinon from 'sinon'; | ||
|
||
import fileReader from './fileReader.js'; | ||
|
||
it('readJSONFile returns a promise', () => { | ||
const fileList = { data: {}, filename: 'whatever' }; | ||
|
||
const promise = fileReader.readJSONFile(fileList); | ||
expect(isPromise(promise)).toBeTruthy(); | ||
}); | ||
|
||
it('readJSONFile fails to load a fail', async () => { | ||
expect.assertions(1); | ||
const fileList = { data: {}, filename: 'whatever' }; | ||
try { | ||
await fileReader.readJSONFile(fileList); | ||
} catch (e) { | ||
expect(true).toBeTruthy(); | ||
} | ||
}); | ||
|
||
it('readJSONFile fails when fileList is wrong', async () => { | ||
expect.assertions(2); | ||
|
||
const mock = sinon.mock(window); | ||
const called = mock.expects('FileReader').once(); | ||
const fileList = { | ||
action: '', | ||
filename: 'file', | ||
file: { uid: '1234' }, | ||
data: {}, | ||
headers: {}, | ||
withCredentials: false, | ||
}; | ||
|
||
try { | ||
await fileReader.readJSONFile(fileList); | ||
} catch (e) { | ||
expect(true).toBeTruthy(); | ||
expect(called.verify()).toBeTruthy(); | ||
} | ||
mock.restore(); | ||
}); |