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

Refactor component types and component inheritance #110

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"ui": true,
"requiredBundles": [],
"requiredPlugins": [
"navigation"
"navigation",
"opensearchDashboardsUtils"
Copy link
Member Author

@ohltyler ohltyler Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed for createGetterSetter() used in services.ts. Was recently removed from requiredBundles due to it causing build errors, but without it it causes runtime errors. Correct pattern is to include this in requiredPlugins.

],
"optionalPlugins": []
}
26 changes: 24 additions & 2 deletions public/component_types/base_component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../utils';
import {
IComponent,
IComponentField,
IComponentInput,
IComponentOutput,
} from './interfaces';

/**
* A base component class.
* A base UI drag-and-drop component class.
*/
export abstract class BaseComponent {
export abstract class BaseComponent implements IComponent {
type: COMPONENT_CLASS;
label: string;
description: string;
categories: COMPONENT_CATEGORY[];
allowsCreation: boolean;
baseClasses: COMPONENT_CLASS[];
inputs?: IComponentInput[];
fields?: IComponentField[];
createFields?: IComponentField[];
outputs?: IComponentOutput[];

// No-op constructor. If there are general / defaults for field values, add in here.
constructor() {}

// Persist a standard toObj() fn that all component classes can use. This is necessary
// so we have standard JS Object when serializing comoponent state in redux.
toObj() {
Expand Down
4 changes: 2 additions & 2 deletions public/component_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
*/

export * from './interfaces';
export * from './processors';
export * from './indices';
export * from './transformer';
export * from './indexer';
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* SPDX-License-Identifier: Apache-2.0
*/

export * from './knn_index';
export * from './indexer';
export * from './knn_indexer';
65 changes: 65 additions & 0 deletions public/component_types/indexer/indexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { BaseComponent } from '../base_component';

/**
* A base indexer UI component
*/
export class Indexer extends BaseComponent {
constructor() {
super();
this.type = COMPONENT_CLASS.INDEXER;
this.label = 'Indexer';
this.description = 'A general indexer';
this.categories = [COMPONENT_CATEGORY.INGEST, COMPONENT_CATEGORY.SEARCH];
this.allowsCreation = true;
this.baseClasses = [this.type];
this.inputs = [
{
id: 'transformer',
label: 'Transformer',
// TODO: may need to change to be looser. it should be able to take
// in other component types
baseClass: COMPONENT_CLASS.TRANSFORMER,
optional: false,
acceptMultiple: false,
},
];
this.fields = [
{
label: 'Index Name',
name: 'indexName',
type: 'select',
optional: false,
advanced: false,
},
];
this.createFields = [
{
label: 'Index Name',
name: 'indexName',
type: 'string',
optional: false,
advanced: false,
},
{
label: 'Mappings',
name: 'indexMappings',
type: 'json',
placeholder: 'Enter an index mappings JSON blob...',
optional: false,
advanced: false,
},
];
this.outputs = [
{
label: this.label,
baseClasses: this.baseClasses,
},
];
}
}
30 changes: 30 additions & 0 deletions public/component_types/indexer/knn_indexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { Indexer } from './indexer';

/**
* A specialized indexer component for vector/K-NN indices
*/
export class KnnIndexer extends Indexer {
constructor() {
super();
this.label = 'K-NN Indexer';
this.description = 'A specialized indexer for K-NN indices';
this.createFields = [
// @ts-ignore
...this.createFields,
// TODO: finalize what to expose / what to have for defaults here
{
label: 'K-NN Settings',
name: 'knnSettings',
type: 'json',
placeholder: 'Enter K-NN settings JSON blob...',
optional: false,
advanced: false,
},
];
}
}
92 changes: 0 additions & 92 deletions public/component_types/indices/knn_index.ts

This file was deleted.

10 changes: 2 additions & 8 deletions public/component_types/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../utils';
/**
* ************ Types *************************
*/
export type UIFlow = string;
export type FieldType = 'string' | 'json' | 'select';
// TODO: this may expand to more types in the future. Formik supports 'any' so we can too.
// For now, limiting scope to expected types.
Expand Down Expand Up @@ -68,17 +67,12 @@ export interface IComponent {
label: string;
description: string;
// will be used for grouping together in the drag-and-drop component library
category: COMPONENT_CATEGORY;
// and determining which flows the component can be drug into the workspace flows
categories: COMPONENT_CATEGORY[];
// determines if this component allows for new creation. this means to
// allow a "create" option on the UI component, as well as potentially
// include in the use case template construction ('provisioning' flow)
allowsCreation: boolean;
// determines if this is something that will be included in the use
// case template construction (query or ingest flows). provisioning flow
// is handled by the allowsCreation flag above.
isApplicationStep: boolean;
// the set of allowed flows this component can be drug into the workspace
allowedFlows: UIFlow[];
// the list of base classes that will be used in the component output
baseClasses?: COMPONENT_CLASS[];
inputs?: IComponentInput[];
Expand Down
76 changes: 0 additions & 76 deletions public/component_types/processors/text_embedding_processor.ts

This file was deleted.

21 changes: 21 additions & 0 deletions public/component_types/transformer/base_transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { COMPONENT_CATEGORY, COMPONENT_CLASS } from '../../utils';
import { BaseComponent } from '../base_component';

/**
* A base transformer UI component
*/
export abstract class BaseTransformer extends BaseComponent {
constructor() {
super();
this.type = COMPONENT_CLASS.TRANSFORMER;
this.label = 'Transformer';
this.categories = [COMPONENT_CATEGORY.INGEST, COMPONENT_CATEGORY.SEARCH];
this.allowsCreation = false;
this.baseClasses = [this.type];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* SPDX-License-Identifier: Apache-2.0
*/

export * from './text_embedding_processor';
export * from './ml_transformer';
export * from './text_embedding_transformer';
Loading
Loading