Skip to content

Commit

Permalink
Merge pull request #214 from DocShow-AI/data-profiling
Browse files Browse the repository at this point in the history
change upload page, change database url
  • Loading branch information
liberty-rising authored Jan 19, 2024
2 parents 19bfdd0 + a62d5dd commit d187b5a
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 144 deletions.
10 changes: 10 additions & 0 deletions backend/database/data_profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ def get_all_data_profiles(self):
"""Retrieve all DataProfiles."""
return self.session.query(DataProfile).all()

def get_all_data_profile_names_by_org_id(self, org_id):
"""Retrieve all DataProfiles."""
result = (
self.session.query(DataProfile.name)
.filter(DataProfile.organization_id == org_id)
.all()
)
data_profile_names = [name for (name,) in result]
return data_profile_names

def create_dataprofile(self, data_profile_data: DataProfileCreateRequest):
"""Create a new DataProfile."""
new_data_profile = DataProfile(
Expand Down
3 changes: 2 additions & 1 deletion backend/database/database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
APP_ENV,
DATABASE_POOL_MAX_OVERFLOW,
DATABASE_POOL_SIZE,
DATABASE_POOL_URL,
DATABASE_URL,
)
from sqlalchemy import create_engine
Expand All @@ -13,7 +14,7 @@ class DatabaseManager:
def __init__(self):
if APP_ENV == "prod":
self.engine = create_engine(
DATABASE_URL,
DATABASE_POOL_URL,
poolclass=QueuePool,
pool_size=DATABASE_POOL_SIZE,
max_overflow=DATABASE_POOL_MAX_OVERFLOW,
Expand Down
10 changes: 10 additions & 0 deletions backend/routes/data_profile_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ async def get_data_profiles(current_user: User = Depends(get_current_user)):
return data_profiles


@data_profile_router.get("/data-profiles/org/")
async def get_data_profiles_by_org_id(current_user: User = Depends(get_current_user)):
with DatabaseManager() as session:
data_profile_manager = DataProfileManager(session)
data_profile_names = data_profile_manager.get_all_data_profile_names_by_org_id(
current_user.organization_id
)
return data_profile_names


@data_profile_router.post("/data-profile/")
async def save_data_profiles(
request: DataProfileCreateRequest, current_user: User = Depends(get_current_user)
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/auth/RequireAuth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function RequireAuth({ children }) {

if (isAuthenticated && !isEmailVerified) {
// Redirect to the verify-email page if email is not verified
console.log("triggered");
return <Navigate to="/verify-email" />;
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/navigation/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Navigation = () => {
let menuItems = [
{ text: "Dashboards", icon: <DashboardIcon />, path: "/dashboards" },
{ text: "Data Upload", icon: <UploadFileIcon />, path: "/upload" },
{ text: "Data Analytics", icon: <AnalyticsIcon />, path: "/analytics" },
{ text: "AI Analyst", icon: <AnalyticsIcon />, path: "/analytics" },
{
text: "Data Profiling",
icon: <AnalyticsIcon />,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/analytics/AnalyticsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function AnalyticsPage() {
return (
<Box>
<Typography variant="h4" gutterBottom>
📊 Data Analytics
📊 AI Analyst
</Typography>
<Grid container spacing={2}>
<Grid item xs={12}>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/pages/data-profiling/DataProfilingPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { API_URL } from "../../utils/constants";

function DataProfilingPage() {
const [dataProfiles, setDataProfiles] = useState([]);
const [selectedFile, setSelectedFile] = useState(null);
const [selectedFileName, setSelectedFileName] = useState("");
const [instructions, setInstructions] = useState("");
const [isUploading, setIsUploading] = useState(false);
const [previewData, setPreviewData] = useState(null);
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/pages/upload/DataProfileSelector.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { FormControl, InputLabel, MenuItem, Select } from "@mui/material";

const DataProfileSelector = ({ dataProfiles, dataProfile, setDataProfile }) => {
const isValidDataProfile = dataProfiles.includes(dataProfile);
const safeDataProfile = isValidDataProfile ? dataProfile : "";

return (
<FormControl fullWidth>
<InputLabel id="data-profile-label">Choose a data profile</InputLabel>
<Select
labelId="data-profile-label"
value={safeDataProfile}
label="Choose a data profile"
onChange={(e) => setDataProfile(e.target.value)}
>
{dataProfiles.map((profile, index) => (
<MenuItem key={index} value={profile}>
{profile}
</MenuItem>
))}
</Select>
</FormControl>
);
};

export default DataProfileSelector;
14 changes: 0 additions & 14 deletions frontend/src/pages/upload/DescriptionField.jsx

This file was deleted.

22 changes: 0 additions & 22 deletions frontend/src/pages/upload/EncodingSelector.jsx

This file was deleted.

30 changes: 0 additions & 30 deletions frontend/src/pages/upload/FileTypeSelector.jsx

This file was deleted.

24 changes: 0 additions & 24 deletions frontend/src/pages/upload/NewTableSelector.jsx

This file was deleted.

69 changes: 21 additions & 48 deletions frontend/src/pages/upload/UploadPage.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import React, { useState, useEffect } from "react";
import { Box, Button, Stack, Typography } from "@mui/material";
import axios from "axios";
import FileTypeSelector from "./FileTypeSelector";
import EncodingSelector from "./EncodingSelector";
import DescriptionField from "./DescriptionField";
import NewTableSelector from "./NewTableSelector";
import FileUploader from "./FileUploader";
import AlertSnackbar from "./AlertSnackbar";
import DataProfileSelector from "./DataProfileSelector";
import { API_URL } from "../../utils/constants";

function UploadPage() {
const [fileTypes, setFileTypes] = useState([]);
const [encodings, setEncodings] = useState([]);
const [fileType, setFileType] = useState("");
const [encoding, setEncoding] = useState("");
const [description, setDescription] = useState("");
const [isNewTable, setIsNewTable] = useState("no");
const [file, setFile] = useState(null);
const [files, setFiles] = useState(null);
const [dataProfile, setDataProfile] = useState([]);
const [dataProfiles, setDataProfiles] = useState([]);
const [analyzed, setAnalyzed] = useState(false);
const [alertInfo, setAlertInfo] = useState({
open: false,
Expand All @@ -25,31 +17,22 @@ function UploadPage() {
});

useEffect(() => {
// Fetch file types
axios
.get(`${API_URL}file_types/`)
.then((response) => setFileTypes(response.data))
.catch((error) => console.error("Error fetching file types", error));
.get(`${API_URL}data-profiles/org/`)
.then((response) => {
setDataProfiles(response.data);
})
.catch((error) => console.error("Error fetching data profiles:", error));
}, []);

useEffect(() => {
if (fileType === "csv") {
// Fetch encodings
axios
.get(`${API_URL}encodings/`, { params: { file_type: fileType } })
.then((response) => setEncodings(response.data))
.catch((error) => console.error("Error fetching encodings", error));
}
}, [fileType]);

const handleAnalyze = () => {
// Placeholder for analyze functionality
setAnalyzed(true);
};

const handleSubmit = async () => {
const formData = new FormData();
formData.append("file", file);
formData.append("file", files);
formData.append("extra_desc", description);
formData.append("is_new_table", isNewTable === "yes");
formData.append("encoding", encoding);
Expand Down Expand Up @@ -92,35 +75,25 @@ function UploadPage() {
</Typography>
</Box>

<FileTypeSelector
fileTypes={fileTypes}
fileType={fileType}
setFileType={setFileType}
/>
{/* <FileUploader fileType={fileType} setFile={setFile} /> */}

{fileType === "csv" && (
<EncodingSelector
encodings={encodings}
encoding={encoding}
setEncoding={setEncoding}
<Stack direction="row" spacing={2} alignItems="center">
<DataProfileSelector
dataProfiles={dataProfiles}
dataProfile={dataProfile}
setDataProfile={setDataProfile}
/>
)}

<DescriptionField
description={description}
setDescription={setDescription}
/>

<NewTableSelector isNewTable={isNewTable} setIsNewTable={setIsNewTable} />

<FileUploader fileType={fileType} setFile={setFile} />
<Button variant="contained" color="primary">
Create a data profile
</Button>
</Stack>

<Stack direction="row" spacing={2} mt={2}>
<Button
variant="contained"
color="secondary"
onClick={handleAnalyze}
disabled={!file}
disabled={!files}
>
Analyze
</Button>
Expand Down

0 comments on commit d187b5a

Please sign in to comment.