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

Set up redux infrastructure #33

Merged
merged 1 commit into from
Sep 21, 2023
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
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
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
// 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({
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
name: 'workspace',
initialState,
reducers: {
setDirty(state) {
state.isDirty = true;
},
removeDirty(state) {
state.isDirty = false;
},
owaiskazi19 marked this conversation as resolved.
Show resolved Hide resolved
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>;
Loading