From c4e06ea3d08c3524febee10b29910f96b25e1d95 Mon Sep 17 00:00:00 2001 From: AAfghahi Date: Tue, 2 Aug 2022 14:32:27 -0400 Subject: [PATCH] beginning the reducer --- .../CRUD/data/dataset/DatasetPage/index.tsx | 44 +++++++++++++++ .../CRUD/data/dataset/DatasetPage/types.tsx | 53 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx 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 974091f1efe9c..42de041fa03fd 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 | null, + action: DSReducerActionType, +): Partial | 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 | null, DSReducerActionType> + // >(datasetReducer, null); + return (
diff --git a/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx b/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx new file mode 100644 index 0000000000000..3d5d67f7e144d --- /dev/null +++ b/superset-frontend/src/views/CRUD/data/dataset/DatasetPage/types.tsx @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +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; +} + +interface DatasetReducerPayloadType { + name: string; + value?: string; +} + +export type DSReducerActionType = + | { + type: + | DatasetActionType.selectDatabase + | DatasetActionType.selectSchema + | DatasetActionType.selectTable; + payload: Partial; + } + | { + type: DatasetActionType.changeDataset; + payload: DatasetReducerPayloadType; + };