Skip to content

Commit

Permalink
beginning the reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Aug 5, 2022
1 parent 9350bba commit c4e06ea
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DatasetObject>;
}
| {
type: DatasetActionType.changeDataset;
payload: DatasetReducerPayloadType;
};

0 comments on commit c4e06ea

Please sign in to comment.