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

Feat/db migration student tbl #2

Merged
merged 12 commits into from
Jan 7, 2025
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
42 changes: 42 additions & 0 deletions .github/workflows/supabase-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy to Supabase on merge

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18' # Ensure compatibility with Supabase CLI

- name: Install dependencies
run: npm install

- name: Install Supabase CLI locally
run: npm install supabase

- name: Authenticate Supabase CLI
run: npx supabase login --token "${{ secrets.SUPABASE_ACCESS_TOKEN }}"

- name: Link Supabase Project
run: npx supabase link --project-ref "${{ secrets.SUPABASE_PROJECT_REF }}" --password "${{ secrets.SUPABASE_DB_PWD }}"

- name: Deploy migrations
run: npx supabase db push --password "${{ secrets.SUPABASE_DB_PWD }}" --include-all

- name: Deploy Edge Functions
run: |
if [ -d "supabase/functions" ] && [ "$(ls -A supabase/functions)" ]; then
npx supabase functions deploy
else
echo "No functions to deploy."
fi
39 changes: 39 additions & 0 deletions .github/workflows/supabase-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy to Supabase on PR

on: pull_request

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18' # Ensure compatibility with Supabase CLI

- name: Install dependencies
run: npm install

- name: Install Supabase CLI locally
run: npm install supabase

- name: Authenticate Supabase CLI
run: npx supabase login --token "${{ secrets.SUPABASE_ACCESS_TOKEN }}"

- name: Link Supabase Project
run: npx supabase link --project-ref "${{ secrets.SUPABASE_PROJECT_REF }}" --password "${{ secrets.SUPABASE_DB_PWD }}"

- name: Deploy migrations
run: npx supabase db push --password "${{ secrets.SUPABASE_DB_PWD }}" --include-all

- name: Deploy Edge Functions
run: |
if [ -d "supabase/functions" ] && [ "$(ls -A supabase/functions)" ]; then
npx supabase functions deploy
else
echo "No functions to deploy."
fi
3 changes: 3 additions & 0 deletions src/api/cePlanService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CEPlanService {
student: {
id: '',
name: 'Student 1',
age: null,
email: '',
city: '',
state: '',
Expand All @@ -40,6 +41,7 @@ class CEPlanService {
student: {
id: '',
name: 'Student 2',
age: null,
email: '',
city: '',
state: '',
Expand All @@ -55,6 +57,7 @@ class CEPlanService {
student: {
id: '',
name: 'Student 3',
age: null,
email: '',
city: '',
state: '',
Expand Down
3 changes: 3 additions & 0 deletions src/api/ceSessionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const TEST_PLAN = {
student: {
id: '',
name: 'Student 1',
age: null,
email: '',
city: '',
state: '',
Expand All @@ -35,6 +36,7 @@ const TEST_PLAN = {
student: {
id: '',
name: 'Student 2',
age: null,
email: '',
city: '',
state: '',
Expand All @@ -50,6 +52,7 @@ const TEST_PLAN = {
student: {
id: '',
name: 'Student 3',
age: null,
email: '',
city: '',
state: '',
Expand Down
62 changes: 34 additions & 28 deletions src/api/ceStudentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,46 @@
* @copyright 2024 Digital Aid Seattle
*
*/

import { PageInfo, QueryModel } from "../services/supabaseClient";
import { supabaseClient } from '../services/supabaseClient';

interface Student {
id: string; // Adjust based on database schema
name: string;
age: number;
email: string;
city: string;
state: string;
country: string;
availabilities: any[]; // Adjust based on schema
}


class CEStudentService {

async find(_queryModel: QueryModel): Promise<PageInfo<Student>> {
return {
totalRowCount: 2,
rows: [
{
id: 'sess1',
name: 'Student 1',
email: '[email protected]',
city: "Seattle",
state: "Washington",
country: "US",
availabilities: []
},
{
id: 'sess2',
name: 'Student 1',
email: '[email protected]',
city: "Essen",
state: "",
country: "Germany",
availabilities: []
}
]
}
}

try {
const { data, error } = await supabaseClient.from('student').select('*');

if (error) {
console.error('Error fetching students:', error.message);
throw new Error('Failed to fetch students');
}

if (data) {
return {
totalRowCount: data.length,
rows: data as Student[],
};
}

return { totalRowCount: 0, rows: [] };
} catch (err) {
console.error('Unexpected error:', err);
throw err;
}
}
}

const studentService = new CEStudentService()
const studentService = new CEStudentService();
export { studentService };

1 change: 1 addition & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Availability = {
type Student = {
id: string;
name: string;
age: number | null;
email: string;
city: string;
state: string;
Expand Down
80 changes: 80 additions & 0 deletions src/pages/students/StudentsDetailsTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { useContext, useEffect, useState } from 'react';

import Box from '@mui/material/Box';
import {
DataGrid,
GridColDef,
GridSortModel,
} from '@mui/x-data-grid';

import { PageInfo, QueryModel } from '../../services/supabaseClient';
import { studentService } from '../../api/ceStudentService';
import { LoadingContext } from '../../components/contexts/LoadingContext';

const PAGE_SIZE = 10;

const getColumns = (): GridColDef[] => {
return [
{
field: 'name',
headerName: 'Name',
width: 150,
},
{
field: 'age',
headerName: 'Age',
width: 150,
},
{
field: 'country',
headerName: 'Country',
width: 150,
},
]
}

const StudentsDetailsTable: React.FC = () => {
const [paginationModel, setPaginationModel] = useState({ page: 0, pageSize: PAGE_SIZE });
const [sortModel, setSortModel] = useState<GridSortModel>([{ field: 'name', sort: 'asc' }]);
const [pageInfo, setPageInfo] = useState<PageInfo<Student>>({ rows: [], totalRowCount: 0 });
const { setLoading } = useContext(LoadingContext);

useEffect(() => {
if (paginationModel && sortModel) {
setLoading(true);
const queryModel = {
page: paginationModel.page,
pageSize: paginationModel.pageSize,
sortField: sortModel.length === 0 ? 'name' : sortModel[0].field,
sortDirection: sortModel.length === 0 ? 'asc' : sortModel[0].sort
} as QueryModel
studentService.find(queryModel)
.then((pi) => setPageInfo(pi))
.catch((err) => console.error(err))
.finally(() => setLoading(false))
}
}, [paginationModel, sortModel])


return (
<Box>
<DataGrid
rows={pageInfo.rows}
columns={getColumns()}

paginationMode='server'
paginationModel={paginationModel}
rowCount={pageInfo.totalRowCount}
onPaginationModelChange={setPaginationModel}

sortingMode='server'
sortModel={sortModel}
onSortModelChange={setSortModel}

pageSizeOptions={[5, 10, 25, 100]}
/>
</Box>
)
}

export default StudentsDetailsTable;
2 changes: 2 additions & 0 deletions src/pages/students/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// project import
import { Typography } from '@mui/material';
import MainCard from '../../components/MainCard';
import StudentsDetailsTable from './StudentsDetailsTable';

// ================================|| 404 ||================================ //

Expand All @@ -13,6 +14,7 @@ const StudentsPage: React.FC = () => {
<Typography>List/Table of students enrolled in the program.</Typography>
<Typography>Should include method to upload a spreadsheet</Typography>
<Typography>Investigate integration with Google Docs to obtain data</Typography>
<StudentsDetailsTable />
</MainCard>
)
};
Expand Down
Loading
Loading