Skip to content

Commit

Permalink
[Console] Convert lib/mappings to TypeScript (#4008)
Browse files Browse the repository at this point in the history
* Convert mappings.js to TypeScript

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Convert mappings.test.js to TypeScript

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Update CHANGELOG.md

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Add test for getTypes with multi-index mode

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* type update

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* update typing

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* CHANGELOG fix

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Changelog update

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

* Update Changelog

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>

---------

Signed-off-by: Sirazh Gabdullin <sirazh.gabdullin@nu.edu.kz>
Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Signed-off-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Kawika Avilla <kavilla414@gmail.com>
Co-authored-by: Qingyang(Abby) Hu <abigailhu2000@gmail.com>
Co-authored-by: Ashwin P Chandran <ashwinpc@amazon.com>
Co-authored-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
  • Loading branch information
6 people authored Jul 5, 2023
1 parent 1560a6c commit e07c5e6
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Vis Colors] [Timeline] Replace `vis_type_timeline` colors with `ouiPaletteColorBlind()` ([#4366](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4366))
- [Vis Colors] Update legacy seed colors to use `ouiPaletteColorBlind()` ([#4348](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4348))
- [Vis colors] Update legacy mapped colors in charts plugin to use `ouiPaletteColorBlind()`, Update default color in legacy visualizations to use `ouiPaletteColorBlind()[0]` ([#4398](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4398))
- [Console] Migrate `/lib/mappings/` module to TypeScript ([#4008](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4008))

### 🔩 Tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { Field } from '../mappings';
import '../../../application/models/sense_editor/sense_editor.test.mocks';
import * as mappings from '../mappings';

Expand All @@ -39,7 +40,7 @@ describe('Mappings', () => {
mappings.clear();
});

function fc(f1, f2) {
function fc(f1: Field, f2: Field) {
if (f1.name < f2.name) {
return -1;
}
Expand All @@ -49,8 +50,8 @@ describe('Mappings', () => {
return 0;
}

function f(name, type) {
return { name: name, type: type || 'string' };
function f(name: string, type?: string) {
return { name, type: type || 'string' };
}

test('Multi fields 1.0 style', function () {
Expand Down Expand Up @@ -256,10 +257,37 @@ describe('Mappings', () => {
'test_index2',
]);
expect(mappings.getIndices(false).sort()).toEqual(['test_index1', 'test_index2']);
expect(mappings.expandAliases(['alias1', 'test_index2']).sort()).toEqual([
expect((mappings.expandAliases(['alias1', 'test_index2']) as string[]).sort()).toEqual([
'test_index1',
'test_index2',
]);
expect(mappings.expandAliases('alias2')).toEqual('test_index2');
});

test('Multi types', function () {
mappings.loadMappings({
index: {
properties: {
name1: {
type: 'object',
path: 'just_name',
properties: {
first1: { type: 'string' },
last1: { type: 'string', index_name: 'i_last_1' },
},
},
name2: {
type: 'object',
path: 'full',
properties: {
first2: { type: 'string' },
last2: { type: 'string', index_name: 'i_last_2' },
},
},
},
},
});

expect(mappings.getTypes()).toEqual(['properties']);
});
});
Loading

0 comments on commit e07c5e6

Please sign in to comment.