Refactoring

This commit is contained in:
2024-06-25 11:32:06 +02:00
parent 1e8a12789d
commit a492bf4ac0
7 changed files with 36 additions and 45 deletions

View File

@@ -9,6 +9,7 @@ type TableGenOptions = {
type Props = {
headings:Array<string>;
children:ReactNode;
entityName:string;
options?:TableGenOptions
}
@@ -16,6 +17,7 @@ export default function EntityManagementTable(props:Props){
const options = props.options ? props.options : {editButton: true, deleteButton: true}
console.log(props.headings)
return <>
<span className="flex flex-row flex-grow w-[100%] pl-2 pr-2"><h1 className="p-2 inline-block">{props.entityName} Management</h1><section className="flex-grow"></section><button className='btn btn-success h-12 mt-auto mb-auto self-end'>New</button></span>
<table className="table overflow-scroll">
<thead>
<tr>

View File

@@ -20,7 +20,7 @@ import { useState } from "react";
import { Project, Post, Bucket } from "@/model/Models";
import { ActionResult } from "@/app/lib/actions/ActionResult";
import { handleActionResult } from "@/app/lib/actions/clientActionHandler";
import { getPostsWithBuckets } from "@/app/lib/actions/entityManagement/postActions";
import { getPostsWithBucketsAndProject } from "@/app/lib/actions/entityManagement/postActions";
import { PostAttributesWithBuckets } from "@/model/Post";
type Actions = {
@@ -100,7 +100,7 @@ export default function PostTable(props: Props) {
project_id: e.project_id
})
.then(res => handleActionResult(res))
.then(getPostsWithBuckets)
.then(getPostsWithBucketsAndProject)
.then(res => {
if (!res.error && res.result) setPosts(res.result);
})
@@ -169,7 +169,7 @@ export default function PostTable(props: Props) {
}
return <>
<EntityManagementTable key="der-table" headings={props.headings}>
<EntityManagementTable entityName="Post" key="der-table" headings={props.headings}>
{posts.map((postData: Partial<PostAttributesWithBuckets>) => <TableRow headings={props.headings}
postData={postData}
key={postData.id}/> )}

View File

@@ -5,7 +5,7 @@ import { constructAPIUrl } from "@/util/Utils";
import { ReactNode, useEffect } from "react";
import EntityManagementTable from "../../../client/EntityManagementTable";
import PostTable from "@/components/client/admin/PostTable";
import { deletePost, getPostsWithBuckets, updatePost } from "@/app/lib/actions/entityManagement/postActions";
import { deletePost, getPostsWithBucketsAndProject, updatePost } from "@/app/lib/actions/entityManagement/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/model/Models";
import { tryCreateAttachment } from "@/app/api/attachment/route";
@@ -13,22 +13,20 @@ import { tryCreateAttachment } from "@/app/api/attachment/route";
type Props = {
children?:ReactNode
}
async function getHeadings(){
let headings:string[] = ['#', 'Title', 'Content', 'Project', 'CreatedAt', 'UpdatedAt']
return headings
}
export default async function PostView(props:Props){
await dbSync;
const sync = await dbSync;
const headings = await getHeadings();
const headings = [
'#',
'Title',
'Content',
'Project',
'Date Created',
'Date Modified',
]
const actions = {
deletePost: deletePost,
getPosts:getPostsWithBuckets,
getPosts:getPostsWithBucketsAndProject,
getProjects:getProjects,
savePost:updatePost,
// uploadAttachment:tryCreateAttachment
@@ -39,7 +37,6 @@ export default async function PostView(props:Props){
return (
<div className="w-[100%] min-h-fit bg-gray-100 overflow-scroll">
<span className="flex flex-row flex-grow w-[100%] pl-2 pr-2"><h1 className="p-2 inline-block">Post Management</h1><section className="flex-grow"></section><button className='btn btn-success h-12 mt-auto mb-auto self-end'>New</button></span>
<div className="w-[100%] m-auto">
<PostTable data={posts}
projects={projects}

View File

@@ -5,7 +5,7 @@ import { constructAPIUrl } from "@/util/Utils";
import { ReactNode, useEffect } from "react";
import EntityManagementTable from "../../../client/EntityManagementTable";
import PostTable from "@/components/client/admin/PostTable";
import { deletePost, getPostsWithBuckets, updatePost } from "@/app/lib/actions/entityManagement/postActions";
import { deletePost, getPostsWithBucketsAndProject, updatePost } from "@/app/lib/actions/entityManagement/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/model/Models";
import { tryCreateAttachment } from "@/app/api/attachment/route";
@@ -16,9 +16,17 @@ type Props = {
children?:ReactNode
}
async function getHeadings(){
let headings:string[] = []
for (const key in Project.getAttributes())
{
headings.push(key)
}
return headings
}
export default async function ProjectView(props:Props){
await dbSync;
const sync = await dbSync;
// const headings = [
// '#',
@@ -30,7 +38,6 @@ export default async function ProjectView(props:Props){
// 'Edit',
// 'Delete',
// ]
const headings = Project.getAttributes();
// const actions = {
// deletePost: deletePost,
// getPosts:getPostsWithBuckets,
@@ -41,19 +48,11 @@ export default async function ProjectView(props:Props){
const posts:Post[] = await Post.findAll({include: {model: Bucket, include: {model: Attachment}}}).then(posts=>posts.map((e)=>JSON.parse(JSON.stringify(e))));
const projects = await Project.findAll().then(projects=>projects.map((e)=>JSON.parse(JSON.stringify(e))));
const headings = await getHeadings();
return <>
<div className="w-[100%] min-h-fit bg-gray-100 overflow-scroll">
<div className="w-[100%] m-auto">
{(()=>{
let a:string[] = []
for (const key in headings)
{
a.push(key)
}
// return a.map((e)=> <div key={e}>{e}</div> );
return <EntityManagementTable headings={a}><></></EntityManagementTable>
})()}
<EntityManagementTable entityName="Project" headings={headings}><></></EntityManagementTable>
{/* <PostTable data={posts}
projects={projects}
headings={headings}