Skip to content
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

[Console] Converted all /lib/autocomplete/**/*.js files to typescript #4148

Merged
merged 26 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
71c8ece
Convert autocomplete part to TS
curq May 26, 2023
f9e615d
Merge branch 'opensearch-project:main' into console-autocomplete-ts
curq May 26, 2023
c372e1c
Merge branch 'opensearch-project:main' into console-autocomplete-ts
curq May 26, 2023
78bed2b
Update CHANGELOG.md
curq May 26, 2023
bf6a7e4
Merge branch 'main' into console-autocomplete-ts
curq May 29, 2023
75c7d94
Merge branch 'main' into console-autocomplete-ts
curq May 31, 2023
07598c4
Merge branch 'main' into console-autocomplete-ts
curq Jun 14, 2023
f6a8cee
reafactor and improve typing
curq Jun 14, 2023
9375923
clean comments for compileBodyDescription
curq Jun 14, 2023
40ed198
CHANGELOG fix
curq Jun 21, 2023
5156d6e
License Update
curq Jun 21, 2023
d9e3e0e
Merge branch 'main' into console-autocomplete-ts
curq Jun 21, 2023
31b40ad
Changelog update
curq Jun 21, 2023
ad97705
revert mistake license change
curq Jun 21, 2023
2d172ff
Merge branch 'main' into console-autocomplete-ts
curq Jun 23, 2023
1205e53
remove redundant line
curq Jun 23, 2023
ec4a3ea
Merge branch 'main' into console-autocomplete-ts
curq Jun 26, 2023
84fb3f9
Merge branch 'main' into console-autocomplete-ts
curq Jun 26, 2023
801f4af
fix changelog redundant lines
curq Jun 26, 2023
148202c
Merge branch 'main' into console-autocomplete-ts
curq Jun 26, 2023
6a70af1
Update CHANGELOG.md
curq Jun 26, 2023
570e901
Merge branch 'main' into console-autocomplete-ts
curq Jun 26, 2023
5c24c38
Merge branch 'main' into console-autocomplete-ts
joshuarrrr Jul 5, 2023
75ca742
Merge branch 'main' into console-autocomplete-ts
joshuarrrr Jul 19, 2023
b6aedd1
Merge branch 'main' into console-autocomplete-ts
curq Jul 21, 2023
e9581d8
refactor getTemplate
curq Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [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))
- [Saved Objects Management] Add new or remove extra tags and styles ([#4069](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4069))
- [Console] Migrate `/lib/mappings/` module to TypeScript ([#4008](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4008))
- [Console] Migrate `/lib/autocomplete/` module to TypeScript ([#4148](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4148))
- [Dashboard] Restructure the `Dashboard` plugin folder to be more cohesive with the project ([#4575](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4575))

### 🔩 Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@ import {
URL_PATH_END_MARKER,
UrlPatternMatcher,
ListComponent,
SharedComponent,
} from '../../autocomplete/components';

import { populateContext } from '../../autocomplete/engine';
import { PartialAutoCompleteContext } from '../components/autocomplete_component';
import { ComponentFactory, ParametrizedComponentFactories } from '../../osd';

describe('Url autocomplete', () => {
function patternsTest(name, endpoints, tokenPath, expectedContext, globalUrlComponentFactories) {
function patternsTest(
name: string,
endpoints: Record<number | string, any>,
tokenPath: string | Array<string | string[]>,
expectedContext: PartialAutoCompleteContext,
globalUrlComponentFactories?: ParametrizedComponentFactories
) {
test(name, function () {
const patternMatcher = new UrlPatternMatcher(globalUrlComponentFactories);
_.each(endpoints, function (e, id) {
e.id = id;
e.id = id.toString();
_.each(e.patterns, function (p) {
patternMatcher.addEndpoint(p, e);
});
Expand All @@ -52,39 +61,40 @@ describe('Url autocomplete', () => {
tokenPath = tokenPath.substr(0, tokenPath.length - 1) + '/' + URL_PATH_END_MARKER;
}
tokenPath = _.map(tokenPath.split('/'), function (p) {
p = p.split(',');
if (p.length === 1) {
return p[0];
const pSplit = p.split(',');
if (pSplit.length === 1) {
return pSplit[0];
}
return p;
return pSplit;
});
}

if (expectedContext.autoCompleteSet) {
expectedContext.autoCompleteSet = _.map(expectedContext.autoCompleteSet, function (t) {
if (_.isString(t)) {
t = { name: t };
expectedContext.autoCompleteSet = _.map(expectedContext.autoCompleteSet, function (term) {
if (_.isString(term)) {
term = { name: term };
}
return t;
return term;
});
expectedContext.autoCompleteSet = _.sortBy(expectedContext.autoCompleteSet, 'name');
}

const context = {};
const context: PartialAutoCompleteContext = {};
if (expectedContext.method) {
context.method = expectedContext.method;
}

populateContext(
tokenPath,
context,
null,
expectedContext.autoCompleteSet,
patternMatcher.getTopLevelComponents(context.method)
expectedContext.autoCompleteSet ? true : false,
patternMatcher.getTopLevelComponents(context.method!)
);

// override context to just check on id
if (context.endpoint) {
context.endpoint = context.endpoint.id;
context.endpoint = (context as any).endpoint.id;
}

if (context.autoCompleteSet) {
Expand All @@ -95,9 +105,9 @@ describe('Url autocomplete', () => {
});
}

function t(name, meta) {
function t(name: string, meta: string) {
if (meta) {
return { name: name, meta: meta };
return { name, meta };
}
return name;
}
Expand Down Expand Up @@ -265,11 +275,11 @@ describe('Url autocomplete', () => {
},
};
const globalFactories = {
p: function (name, parent) {
p(name: string, parent: SharedComponent) {
return new ListComponent(name, ['g1', 'g2'], parent);
},
getComponent(name) {
return this[name];
getComponent(name: string): ComponentFactory {
return (this as any)[name];
},
};

Expand Down Expand Up @@ -355,7 +365,7 @@ describe('Url autocomplete', () => {
})();

(function () {
const endpoints = {
const endpoints: Record<string, any> = {
'1_param': {
patterns: ['a/{p}'],
methods: ['GET'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,64 +31,72 @@
import _ from 'lodash';
import { UrlParams } from '../../autocomplete/url_params';
import { populateContext } from '../../autocomplete/engine';
import { Term } from '../types';
import { PartialAutoCompleteContext } from '../components/autocomplete_component';
import { SharedComponent } from '../components';

describe('Url params', () => {
function paramTest(name, description, tokenPath, expectedContext, globalParams) {
function paramTest(
name: string,
description: Record<string, unknown>,
tokenPath: string | Array<string | string[]>,
expectedContext: PartialAutoCompleteContext,
globalParams?: Record<string, unknown>
) {
test(name, function () {
const urlParams = new UrlParams(description, globalParams || {});
if (typeof tokenPath === 'string') {
tokenPath = _.map(tokenPath.split('/'), function (p) {
p = p.split(',');
if (p.length === 1) {
return p[0];
const pSplit = p.split(',');
if (pSplit.length === 1) {
return pSplit[0];
}
return p;
return pSplit;
});
}

if (expectedContext.autoCompleteSet) {
expectedContext.autoCompleteSet = _.map(expectedContext.autoCompleteSet, function (t) {
if (_.isString(t)) {
t = { name: t };
expectedContext.autoCompleteSet = _.map(expectedContext.autoCompleteSet, function (term) {
if (_.isString(term)) {
term = { name: term };
}
return t;
return term;
});
expectedContext.autoCompleteSet = _.sortBy(expectedContext.autoCompleteSet, 'name');
}

const context = {};
const context: PartialAutoCompleteContext = {};

populateContext(
tokenPath,
context,
null,
expectedContext.autoCompleteSet,
urlParams.getTopLevelComponents()
expectedContext.autoCompleteSet ? true : false,
urlParams.getTopLevelComponents() as SharedComponent[]
);

if (context.autoCompleteSet) {
context.autoCompleteSet = _.sortBy(context.autoCompleteSet, 'name');
const populatedContext = context;

if (populatedContext.autoCompleteSet) {
populatedContext.autoCompleteSet = _.sortBy(populatedContext.autoCompleteSet, 'name');
}

expect(context).toEqual(expectedContext);
expect(populatedContext).toEqual(expectedContext);
});
}

function t(name, meta, insertValue) {
let r = name;
function createTerm(name: string, meta?: string, insertValue?: string) {
const term: Term = { name };
if (meta) {
r = { name: name, meta: meta };
term.meta = meta;
if (meta === 'param' && !insertValue) {
insertValue = name + '=';
}
}
if (insertValue) {
if (_.isString(r)) {
r = { name: name };
}
r.insertValue = insertValue;
term.insertValue = insertValue;
}
return r;
return term;
}

(function () {
Expand All @@ -99,25 +107,31 @@ describe('Url params', () => {
paramTest('settings params', params, 'a/1', { a: ['1'] });

paramTest('autocomplete top level', params, [], {
autoCompleteSet: [t('a', 'param'), t('b', 'flag')],
autoCompleteSet: [createTerm('a', 'param'), createTerm('b', 'flag')],
});

paramTest(
'autocomplete top level, with defaults',
params,
[],
{ autoCompleteSet: [t('a', 'param'), t('b', 'flag'), t('c', 'param')] },
{
autoCompleteSet: [
createTerm('a', 'param'),
createTerm('b', 'flag'),
createTerm('c', 'param'),
],
},
{
c: [2],
}
);

paramTest('autocomplete values', params, 'a', {
autoCompleteSet: [t('1', 'a'), t('2', 'a')],
autoCompleteSet: [createTerm('1', 'a'), createTerm('2', 'a')],
});

paramTest('autocomplete values flag', params, 'b', {
autoCompleteSet: [t('true', 'b'), t('false', 'b')],
autoCompleteSet: [createTerm('true', 'b'), createTerm('false', 'b')],
});
})();
});
Loading
Loading