-
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.
* Add file uploader Signed-off-by: Yuri Roncella <[email protected]> * s/Find/Search/, handle more errors in readJsonFile Bolster the fileReader.readJsonFile tests a bit. Signed-off-by: Joe Farro <[email protected]> * Update the changelog Signed-off-by: Joe Farro <[email protected]>
- Loading branch information
Showing
11 changed files
with
366 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// @flow | ||
|
||
// Copyright (c) 2019 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 { createAction } from 'redux-actions'; | ||
import fileReader from '../utils/fileReader'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const loadJsonTraces = createAction( | ||
'@FILE_READER_API/LOAD_JSON', | ||
fileList => fileReader.readJsonFile(fileList), | ||
fileList => ({ fileList }) | ||
); |
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,40 @@ | ||
// Copyright (c) 2019 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 sinon from 'sinon'; | ||
import isPromise from 'is-promise'; | ||
|
||
import * as fileReaderActions from './file-reader-api'; | ||
import fileReader from '../utils/fileReader'; | ||
|
||
it('loadJsonTraces should return a promise', () => { | ||
const fileList = { data: {}, filename: 'whatever' }; | ||
|
||
const { payload } = fileReaderActions.loadJsonTraces(fileList); | ||
expect(isPromise(payload)).toBeTruthy(); | ||
// prevent the unhandled rejection warnings | ||
payload.catch(() => {}); | ||
}); | ||
|
||
it('loadJsonTraces should call readJsonFile', () => { | ||
const fileList = { data: {}, filename: 'whatever' }; | ||
const mock = sinon.mock(fileReader); | ||
const called = mock | ||
.expects('readJsonFile') | ||
.once() | ||
.withExactArgs(fileList); | ||
fileReaderActions.loadJsonTraces(fileList); | ||
expect(called.verify()).toBeTruthy(); | ||
mock.restore(); | ||
}); |
36 changes: 36 additions & 0 deletions
36
packages/jaeger-ui/src/components/SearchTracePage/FileLoader.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,36 @@ | ||
// @flow | ||
|
||
// Copyright (c) 2019 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'; | ||
|
||
const Dragger = Upload.Dragger; | ||
|
||
type FileLoaderProps = { | ||
loadJsonTraces: (fileList: FileList) => void, | ||
}; | ||
|
||
export default function FileLoader(props: FileLoaderProps) { | ||
return ( | ||
<Dragger accept=".json" customRequest={props.loadJsonTraces} multiple> | ||
<p className="ant-upload-drag-icon"> | ||
<Icon type="file-add" /> | ||
</p> | ||
<p className="ant-upload-text">Click or drag files to this area.</p> | ||
<p className="ant-upload-hint">Support JSON files containig one or more traces.</p> | ||
</Dragger> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/jaeger-ui/src/components/SearchTracePage/FileLoader.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) 2019 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 { shallow } from 'enzyme'; | ||
|
||
import FileLoader from './FileLoader'; | ||
|
||
describe('<FileLoader />', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<FileLoader loadJsonTrace={jest.fn()} />); | ||
}); | ||
|
||
it('matches the snapshot', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/jaeger-ui/src/components/SearchTracePage/__snapshots__/FileLoader.test.js.snap
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,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<FileLoader /> matches the snapshot 1`] = ` | ||
<Dragger | ||
accept=".json" | ||
multiple={true} | ||
> | ||
<p | ||
className="ant-upload-drag-icon" | ||
> | ||
<Icon | ||
type="file-add" | ||
/> | ||
</p> | ||
<p | ||
className="ant-upload-text" | ||
> | ||
Click or drag files to this area. | ||
</p> | ||
<p | ||
className="ant-upload-hint" | ||
> | ||
Support JSON files containig one or more traces. | ||
</p> | ||
</Dragger> | ||
`; |
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
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
Oops, something went wrong.