Skip to content

Commit

Permalink
Set up redux infrastructure
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Sep 21, 2023
1 parent ac60ae0 commit 7ba0245
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
10 changes: 9 additions & 1 deletion public/pages/workflow_builder/workflow_builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import React, { useEffect } from 'react';
// import { useSelector, useDispatch } from 'react-redux';
import {
EuiPageHeader,
EuiFlexGroup,
Expand All @@ -14,8 +15,15 @@ import {
} from '@elastic/eui';
import { BREADCRUMBS } from '../../utils';
import { getCore } from '../../services';
// import { AppState, removeDirty, setComponents } from '../../store';

export function WorkflowBuilder() {
// TODO: below commented out lines can be used for fetching & setting global redux state
// const dispatch = useDispatch();
// const { isDirty, components } = useSelector(
// (state: AppState) => state.workspace
// );

useEffect(() => {
getCore().chrome.setBreadcrumbs([
BREADCRUMBS.AI_APPLICATION_BUILDER,
Expand All @@ -36,7 +44,7 @@ export function WorkflowBuilder() {
</EuiPageHeader>
<EuiSpacer size="l" />
<EuiFlexItem>
<EuiText>Placeholder for workflow builder page...</EuiText>
<EuiText>Workspace</EuiText>
</EuiFlexItem>
</div>
);
Expand Down
10 changes: 7 additions & 3 deletions public/render_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { Provider } from 'react-redux';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { AiFlowDashboardsApp } from './app';
import { store } from './store';

export const renderApp = (
coreStart: CoreStart,
{ appBasePath, element }: AppMountParameters
) => {
ReactDOM.render(
<Router basename={appBasePath + '#/'}>
<Route render={(props) => <AiFlowDashboardsApp {...props} />} />
</Router>,
<Provider store={store}>
<Router basename={appBasePath + '#/'}>
<Route render={(props) => <AiFlowDashboardsApp {...props} />} />
</Router>
</Provider>,
element
);

Expand Down
7 changes: 7 additions & 0 deletions public/store/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export * from './store';
export * from './reducers';
6 changes: 6 additions & 0 deletions public/store/reducers/index.ts
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 './workspace_reducer';
31 changes: 31 additions & 0 deletions public/store/reducers/workspace_reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { createSlice } from '@reduxjs/toolkit';

const initialState = {
isDirty: false,
components: [],
};

const workspaceSlice = createSlice({
name: 'workspace',
initialState,
reducers: {
setDirty(state) {
state.isDirty = true;
},
removeDirty(state) {
state.isDirty = false;
},
setComponents(state, action) {
state.components = action.payload;
state.isDirty = true;
},
},
});

export const workspaceReducer = workspaceSlice.reducer;
export const { setDirty, removeDirty, setComponents } = workspaceSlice.actions;
17 changes: 17 additions & 0 deletions public/store/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { configureStore } from '@reduxjs/toolkit';
import { combineReducers } from 'redux';
import { workspaceReducer } from './reducers';

const rootReducer = combineReducers({
workspace: workspaceReducer,
});
export const store = configureStore({
reducer: rootReducer,
});

export type AppState = ReturnType<typeof rootReducer>;

0 comments on commit 7ba0245

Please sign in to comment.