forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds shared context and simplifies app structure
- Loading branch information
Showing
23 changed files
with
443 additions
and
432 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
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
24 changes: 24 additions & 0 deletions
24
src/plugins/discover/public/application/utils/columns.test.ts
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,24 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { buildColumns } from './columns'; | ||
|
||
describe('buildColumns', () => { | ||
it('returns ["_source"] if columns is empty', () => { | ||
expect(buildColumns([])).toEqual(['_source']); | ||
}); | ||
|
||
it('returns columns if there is only one column', () => { | ||
expect(buildColumns(['foo'])).toEqual(['foo']); | ||
}); | ||
|
||
it('removes "_source" if there are more than one columns', () => { | ||
expect(buildColumns(['foo', '_source', 'bar'])).toEqual(['foo', 'bar']); | ||
}); | ||
|
||
it('returns columns if there are more than one columns but no "_source"', () => { | ||
expect(buildColumns(['foo', 'bar'])).toEqual(['foo', 'bar']); | ||
}); | ||
}); |
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,43 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Any modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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. | ||
*/ | ||
|
||
/** | ||
* Helper function to provide a fallback to a single _source column if the given array of columns | ||
* is empty, and removes _source if there are more than 1 columns given | ||
* @param columns | ||
*/ | ||
export function buildColumns(columns: string[]) { | ||
if (columns.length > 1 && columns.indexOf('_source') !== -1) { | ||
return columns.filter((col) => col !== '_source'); | ||
} else if (columns.length !== 0) { | ||
return columns; | ||
} | ||
return ['_source']; | ||
} |
67 changes: 67 additions & 0 deletions
67
src/plugins/discover/public/application/utils/state_management/discover_slice.test.tsx
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,67 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { discoverSlice, DiscoverState } from './discover_slice'; | ||
|
||
describe('discoverSlice', () => { | ||
let initialState: DiscoverState; | ||
|
||
beforeEach(() => { | ||
initialState = { | ||
columns: [], | ||
sort: [], | ||
}; | ||
}); | ||
|
||
it('should handle setState', () => { | ||
const newState = { | ||
columns: ['column1', 'column2'], | ||
sort: [['field1', 'asc']], | ||
}; | ||
const action = { type: 'discover/setState', payload: newState }; | ||
const result = discoverSlice.reducer(initialState, action); | ||
expect(result).toEqual(newState); | ||
}); | ||
|
||
it('should handle addColumn', () => { | ||
const action1 = { type: 'discover/addColumn', payload: { column: 'column1' } }; | ||
const result1 = discoverSlice.reducer(initialState, action1); | ||
expect(result1.columns).toEqual(['column1']); | ||
|
||
const action2 = { type: 'discover/addColumn', payload: { column: 'column2', index: 0 } }; | ||
const result2 = discoverSlice.reducer(result1, action2); | ||
expect(result2.columns).toEqual(['column2', 'column1']); | ||
}); | ||
|
||
it('should handle removeColumn', () => { | ||
initialState = { | ||
columns: ['column1', 'column2'], | ||
sort: [], | ||
}; | ||
const action = { type: 'discover/removeColumn', payload: 'column1' }; | ||
const result = discoverSlice.reducer(initialState, action); | ||
expect(result.columns).toEqual(['column2']); | ||
}); | ||
|
||
it('should handle reorderColumn', () => { | ||
initialState = { | ||
columns: ['column1', 'column2', 'column3'], | ||
sort: [], | ||
}; | ||
const action = { type: 'discover/reorderColumn', payload: { source: 0, destination: 2 } }; | ||
const result = discoverSlice.reducer(initialState, action); | ||
expect(result.columns).toEqual(['column2', 'column3', 'column1']); | ||
}); | ||
|
||
it('should handle updateState', () => { | ||
initialState = { | ||
columns: ['column1', 'column2'], | ||
sort: [['field1', 'asc']], | ||
}; | ||
const action = { type: 'discover/updateState', payload: { sort: [['field2', 'desc']] } }; | ||
const result = discoverSlice.reducer(initialState, action); | ||
expect(result.sort).toEqual([['field2', 'desc']]); | ||
}); | ||
}); |
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
39 changes: 0 additions & 39 deletions
39
src/plugins/discover/public/application/view_components/canvas/canvas.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.