-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]> (cherry picked from commit f30ac98) Co-authored-by: Tyler Ohlsen <[email protected]>
- Loading branch information
1 parent
cc5fd06
commit 0b3fe2d
Showing
10 changed files
with
163 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* A base component class. | ||
*/ | ||
export abstract class BaseComponent { | ||
// 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() { | ||
return Object.assign({}, this); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './utils'; |
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,92 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
WorkspaceFlowState, | ||
UseCaseTemplate, | ||
Workflow, | ||
USE_CASE, | ||
ReactFlowComponent, | ||
} from '../../../../common'; | ||
|
||
export function saveWorkflow(workflow: Workflow, rfInstance: any): void { | ||
let curFlowState = rfInstance.toObject(); | ||
|
||
curFlowState = { | ||
...curFlowState, | ||
nodes: processNodes(curFlowState.nodes), | ||
}; | ||
|
||
const isValid = validateFlowState(curFlowState); | ||
if (isValid) { | ||
const updatedWorkflow = { | ||
...workflow, | ||
workspaceFlowState: curFlowState, | ||
template: generateUseCaseTemplate(curFlowState), | ||
} as Workflow; | ||
if (workflow.id) { | ||
// TODO: implement connection to update workflow API | ||
} else { | ||
// TODO: implement connection to create workflow API | ||
} | ||
} else { | ||
return; | ||
} | ||
} | ||
|
||
// TODO: implement this. Need more info on UX side to finalize what we need | ||
// to persist, what validation to do, etc. | ||
// Note we don't have to validate connections since that is done via input/output handlers. | ||
function validateFlowState(flowState: WorkspaceFlowState): boolean { | ||
return true; | ||
} | ||
|
||
// TODO: implement this | ||
function generateUseCaseTemplate( | ||
flowState: WorkspaceFlowState | ||
): UseCaseTemplate { | ||
return { | ||
name: 'example-name', | ||
description: 'example description', | ||
type: USE_CASE.SEMANTIC_SEARCH, | ||
userInputs: {}, | ||
workflows: { | ||
provision: { | ||
userParams: {}, | ||
nodes: [], | ||
edges: [], | ||
}, | ||
ingest: { | ||
userParams: {}, | ||
nodes: [], | ||
edges: [], | ||
}, | ||
query: { | ||
userParams: {}, | ||
nodes: [], | ||
edges: [], | ||
}, | ||
}, | ||
} as UseCaseTemplate; | ||
} | ||
|
||
// Process the raw ReactFlow nodes to only persist the fields we need | ||
function processNodes(nodes: ReactFlowComponent[]): ReactFlowComponent[] { | ||
return nodes | ||
.map((node: ReactFlowComponent) => { | ||
return Object.fromEntries( | ||
['id', 'data', 'type', 'width', 'height'].map((key: string) => [ | ||
key, | ||
node[key], | ||
]) | ||
) as ReactFlowComponent; | ||
}) | ||
.map((node: ReactFlowComponent) => { | ||
return { | ||
...node, | ||
selected: false, | ||
}; | ||
}); | ||
} |
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