This is an automated email from the ASF dual-hosted git repository.
aafghahi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new f89ba0c7c1 beginning the reducer (#20945)
f89ba0c7c1 is described below
commit f89ba0c7c17457bc1051ae24290a49cf358386ba
Author: AAfghahi <[email protected]>
AuthorDate: Fri Aug 5 11:53:55 2022 -0400
beginning the reducer (#20945)
---
.../views/CRUD/data/dataset/DatasetPage/index.tsx | 44 +++++++++++++++++++
.../dataset/DatasetPage/{index.tsx => types.tsx} | 51 ++++++++++++++--------
2 files changed, 77 insertions(+), 18 deletions(-)
diff --git
a/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
b/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
index 974091f1ef..42de041fa0 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
@@ -17,13 +17,57 @@
* under the License.
*/
import React from 'react';
+// import React, { useReducer, Reducer } from 'react';
import Header from './Header';
import DatasetPanel from './DatasetPanel';
import LeftPanel from './LeftPanel';
import RightPanel from './RightPanel';
import Footer from './Footer';
+import { DatasetActionType, DatasetObject, DSReducerActionType } from
'./types';
+
+export function datasetReducer(
+ state: Partial<DatasetObject> | null,
+ action: DSReducerActionType,
+): Partial<DatasetObject> | null {
+ const trimmedState = {
+ ...(state || {}),
+ };
+ switch (action.type) {
+ case DatasetActionType.selectDatabase:
+ return {
+ ...trimmedState,
+ ...action.payload,
+ schema: null,
+ table_name: null,
+ };
+ case DatasetActionType.selectSchema:
+ return {
+ ...trimmedState,
+ ...action.payload,
+ table_name: null,
+ };
+ case DatasetActionType.selectTable:
+ return {
+ ...trimmedState,
+ ...action.payload,
+ };
+ case DatasetActionType.changeDataset:
+ return {
+ ...trimmedState,
+ [action.payload.name]: action.payload.value,
+ };
+ default:
+ return null;
+ }
+}
export default function DatasetPage() {
+ // this is commented out for now, but can be commented in as the component
+ // is built up. Uncomment the useReducer in imports too
+ // const [dataset, setDataset] = useReducer<
+ // Reducer<Partial<DatasetObject> | null, DSReducerActionType>
+ // >(datasetReducer, null);
+
return (
<div>
<Header />
diff --git
a/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
b/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx
similarity index 53%
copy from superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
copy to superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx
index 974091f1ef..3d5d67f7e1 100644
--- a/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/index.tsx
+++ b/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx
@@ -16,23 +16,38 @@
* specific language governing permissions and limitations
* under the License.
*/
-import React from 'react';
-import Header from './Header';
-import DatasetPanel from './DatasetPanel';
-import LeftPanel from './LeftPanel';
-import RightPanel from './RightPanel';
-import Footer from './Footer';
+export enum DatasetActionType {
+ selectDatabase,
+ selectSchema,
+ selectTable,
+ changeDataset,
+}
+
+export interface DatasetObject {
+ database: {
+ id: string;
+ database_name: string;
+ };
+ owners: number[];
+ schema?: string | null;
+ dataset_name: string;
+ table_name?: string | null;
+}
-export default function DatasetPage() {
- return (
- <div>
- <Header />
- <LeftPanel />
- <div css={{ display: 'flex' }}>
- <DatasetPanel />
- <Footer />
- </div>
- <RightPanel />
- </div>
- );
+interface DatasetReducerPayloadType {
+ name: string;
+ value?: string;
}
+
+export type DSReducerActionType =
+ | {
+ type:
+ | DatasetActionType.selectDatabase
+ | DatasetActionType.selectSchema
+ | DatasetActionType.selectTable;
+ payload: Partial<DatasetObject>;
+ }
+ | {
+ type: DatasetActionType.changeDataset;
+ payload: DatasetReducerPayloadType;
+ };