Skip to content

Commit 052b416

Browse files
Refactor component types and component inheritance (#110) (#111)
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> (cherry picked from commit 616b1cb) Co-authored-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent 73e80ae commit 052b416

15 files changed

+271
-243
lines changed

opensearch_dashboards.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"ui": true,
77
"requiredBundles": [],
88
"requiredPlugins": [
9-
"navigation"
9+
"navigation",
10+
"opensearchDashboardsUtils"
1011
],
1112
"optionalPlugins": []
1213
}

public/component_types/base_component.tsx

+24-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../utils';
7+
import {
8+
IComponent,
9+
IComponentField,
10+
IComponentInput,
11+
IComponentOutput,
12+
} from './interfaces';
13+
614
/**
7-
* A base component class.
15+
* A base UI drag-and-drop component class.
816
*/
9-
export abstract class BaseComponent {
17+
export abstract class BaseComponent implements IComponent {
18+
type: COMPONENT_CLASS;
19+
label: string;
20+
description: string;
21+
categories: COMPONENT_CATEGORY[];
22+
allowsCreation: boolean;
23+
baseClasses: COMPONENT_CLASS[];
24+
inputs?: IComponentInput[];
25+
fields?: IComponentField[];
26+
createFields?: IComponentField[];
27+
outputs?: IComponentOutput[];
28+
29+
// No-op constructor. If there are general / defaults for field values, add in here.
30+
constructor() {}
31+
1032
// Persist a standard toObj() fn that all component classes can use. This is necessary
1133
// so we have standard JS Object when serializing comoponent state in redux.
1234
toObj() {

public/component_types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
*/
55

66
export * from './interfaces';
7-
export * from './processors';
8-
export * from './indices';
7+
export * from './transformer';
8+
export * from './indexer';

public/component_types/indices/index.ts public/component_types/indexer/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export * from './knn_index';
6+
export * from './indexer';
7+
export * from './knn_indexer';
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
7+
import { BaseComponent } from '../base_component';
8+
9+
/**
10+
* A base indexer UI component
11+
*/
12+
export class Indexer extends BaseComponent {
13+
constructor() {
14+
super();
15+
this.type = COMPONENT_CLASS.INDEXER;
16+
this.label = 'Indexer';
17+
this.description = 'A general indexer';
18+
this.categories = [COMPONENT_CATEGORY.INGEST, COMPONENT_CATEGORY.SEARCH];
19+
this.allowsCreation = true;
20+
this.baseClasses = [this.type];
21+
this.inputs = [
22+
{
23+
id: 'transformer',
24+
label: 'Transformer',
25+
// TODO: may need to change to be looser. it should be able to take
26+
// in other component types
27+
baseClass: COMPONENT_CLASS.TRANSFORMER,
28+
optional: false,
29+
acceptMultiple: false,
30+
},
31+
];
32+
this.fields = [
33+
{
34+
label: 'Index Name',
35+
name: 'indexName',
36+
type: 'select',
37+
optional: false,
38+
advanced: false,
39+
},
40+
];
41+
this.createFields = [
42+
{
43+
label: 'Index Name',
44+
name: 'indexName',
45+
type: 'string',
46+
optional: false,
47+
advanced: false,
48+
},
49+
{
50+
label: 'Mappings',
51+
name: 'indexMappings',
52+
type: 'json',
53+
placeholder: 'Enter an index mappings JSON blob...',
54+
optional: false,
55+
advanced: false,
56+
},
57+
];
58+
this.outputs = [
59+
{
60+
label: this.label,
61+
baseClasses: this.baseClasses,
62+
},
63+
];
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { Indexer } from './indexer';
7+
8+
/**
9+
* A specialized indexer component for vector/K-NN indices
10+
*/
11+
export class KnnIndexer extends Indexer {
12+
constructor() {
13+
super();
14+
this.label = 'K-NN Indexer';
15+
this.description = 'A specialized indexer for K-NN indices';
16+
this.createFields = [
17+
// @ts-ignore
18+
...this.createFields,
19+
// TODO: finalize what to expose / what to have for defaults here
20+
{
21+
label: 'K-NN Settings',
22+
name: 'knnSettings',
23+
type: 'json',
24+
placeholder: 'Enter K-NN settings JSON blob...',
25+
optional: false,
26+
advanced: false,
27+
},
28+
];
29+
}
30+
}

public/component_types/indices/knn_index.ts

-92
This file was deleted.

public/component_types/interfaces.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../utils';
1010
/**
1111
* ************ Types *************************
1212
*/
13-
export type UIFlow = string;
1413
export type FieldType = 'string' | 'json' | 'select';
1514
// TODO: this may expand to more types in the future. Formik supports 'any' so we can too.
1615
// For now, limiting scope to expected types.
@@ -68,17 +67,12 @@ export interface IComponent {
6867
label: string;
6968
description: string;
7069
// will be used for grouping together in the drag-and-drop component library
71-
category: COMPONENT_CATEGORY;
70+
// and determining which flows the component can be drug into the workspace flows
71+
categories: COMPONENT_CATEGORY[];
7272
// determines if this component allows for new creation. this means to
7373
// allow a "create" option on the UI component, as well as potentially
7474
// include in the use case template construction ('provisioning' flow)
7575
allowsCreation: boolean;
76-
// determines if this is something that will be included in the use
77-
// case template construction (query or ingest flows). provisioning flow
78-
// is handled by the allowsCreation flag above.
79-
isApplicationStep: boolean;
80-
// the set of allowed flows this component can be drug into the workspace
81-
allowedFlows: UIFlow[];
8276
// the list of base classes that will be used in the component output
8377
baseClasses?: COMPONENT_CLASS[];
8478
inputs?: IComponentInput[];

public/component_types/processors/text_embedding_processor.ts

-76
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
7+
import { BaseComponent } from '../base_component';
8+
9+
/**
10+
* A base transformer UI component
11+
*/
12+
export abstract class BaseTransformer extends BaseComponent {
13+
constructor() {
14+
super();
15+
this.type = COMPONENT_CLASS.TRANSFORMER;
16+
this.label = 'Transformer';
17+
this.categories = [COMPONENT_CATEGORY.INGEST, COMPONENT_CATEGORY.SEARCH];
18+
this.allowsCreation = false;
19+
this.baseClasses = [this.type];
20+
}
21+
}

public/component_types/processors/index.ts public/component_types/transformer/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export * from './text_embedding_processor';
6+
export * from './ml_transformer';
7+
export * from './text_embedding_transformer';

0 commit comments

Comments
 (0)