Skip to content

Commit

Permalink
Merge pull request #171 from avored/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
indpurvesh authored Jun 16, 2024
2 parents 0c4ca40 + da7b610 commit a496c70
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 107 deletions.
9 changes: 7 additions & 2 deletions react-admin/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,18 @@
"role": {
"permissions": {
"dashboard": "Dashboard",
"setting": "Setting",
"get_setting": "Get Settings",
"save_setting": "Save Setting",
"page_table": "Page table",
"page_create": "Page create",
"page_edit": "Page edit",
"page_delete": "Page delete",
"get_page": "Get Page",
"component_table": "Component table",
"component_create": "Component create",
"component_edit": "Component edit",
"component_delete": "Component delete",
"get_component": "Get Component",
"asset_table": "Asset table",
"asset_create": "Asset create",
"asset_edit": "Asset edit",
Expand All @@ -105,10 +108,12 @@
"admin_user_create": "Admin user create",
"admin_user_edit": "Admin user edit",
"admin_user_delete": "Admin user delete",
"get_admin_user": "Get admin user",
"role_table": "Role table",
"role_create": "Role create",
"role_edit": "Role edit",
"role_delete": "Role delete"
"role_delete": "Role delete",
"get_role": "Get role"
}
}
},
Expand Down
22 changes: 13 additions & 9 deletions react-admin/src/pages/admin-user/AdminUserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {createColumnHelper, getCoreRowModel, useReactTable} from "@tanstack/reac
import {getFormattedDate} from "../../lib/common";
import AvoRedTable from "../../components/AvoRedTable"
import IRoleModel from "../../types/admin-user/IRoleModel";
import HasPermission from "../../components/HasPermission"

function AdminUserTable() {

Expand Down Expand Up @@ -83,8 +84,7 @@ function AdminUserTable() {
})

const getRoleNames = ((roles: Array<IRoleModel>) => {
if(roles.length === 0) {
console.log('sdfsdf')
if (roles.length === 0) {
return (<></>)
}
return roles.map((role) => {
Expand All @@ -103,16 +103,20 @@ function AdminUserTable() {
<div className="p-5 text-2xl font-semibold text-primary-500">
{t("admin_user.admin_users")}
</div>
<Link
className="ml-auto bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
to="/admin/admin-user-create"
>
{t("common.create")}
</Link>
<HasPermission displayDenied={false} identifier="admin_user_create">
<Link
className="ml-auto bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
to="/admin/admin-user-create"
>
{t("common.create")}
</Link>
</HasPermission>
</div>
<div className="w-full block overflow-hidden">
<div className="overflow-x-scroll">
<AvoRedTable table={table}/>
<HasPermission identifier="admin_user_table">
<AvoRedTable table={table}/>
</HasPermission>
</div>
</div>
</div>
Expand Down
158 changes: 86 additions & 72 deletions react-admin/src/pages/component/ComponentTable.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {Link} from "react-router-dom";
import {useComponentTable} from "./hooks/useComponentTable";
import _ from "lodash";
import { useTranslation } from "react-i18next";
import {useTranslation} from "react-i18next";
import IComponentModel from "../../types/component/IComponentModel";
import {createColumnHelper, getCoreRowModel, useReactTable} from "@tanstack/react-table";
import IPageModel from "../../types/page/IPageModel";
import {getFormattedDate} from "../../lib/common";
import HasPermission from "../../components/HasPermission";
import AvoRedTable from "../../components/AvoRedTable";

function ComponentTable() {
const comoonent_api_table_response = useComponentTable()
Expand All @@ -15,82 +20,91 @@ function ComponentTable() {
return `${date_obj.getFullYear()}-${date_obj.getMonth() + 1}-${date_obj.getDate()}`;
})

return (
<div className="flex-1 bg-white">
<div className="px-5 ml-64">
<div className="flex items-center">
<div className="p-5 text-2xl font-semibold text-primary-500">
{t("component.components")}
</div>
<Link
className="ml-auto bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
to="/admin/component-create"
>
{t("common.create")}
</Link>
</div>
const columnHelper = createColumnHelper<IPageModel>()
const columns = [
columnHelper.accessor('id', {
cell: info => info.getValue(),
header: t("common.id")
}),
columnHelper.accessor('name', {
cell: info => info.getValue(),
header: t("common.name")
}),
columnHelper.accessor('identifier', {
cell: info => info.getValue(),
header: t("common.identifier")
}),
columnHelper.accessor('created_at', {
id: "created_at",
cell: info => getFormattedDate(info.getValue()),
header: t("common.created_at")
}),
columnHelper.accessor('created_by', {
cell: info => info.getValue(),
header: t("common.created_by")
}),
columnHelper.accessor('updated_at', {
cell: info => getFormattedDate(info.getValue()),
header: t("common.updated_at")
}),
columnHelper.accessor('updated_by', {
cell: info => info.getValue(),
header: t("common.updated_by")
}),
columnHelper.accessor('action', {
cell: info => {
return (
<HasPermission displayDenied={false} identifier="component_edit">
<Link
className="font-medium text-primary-600 hover:text-primary-800"
to={`/admin/component-edit/${info.row.original.id}`}
>
{t("common.edit")}
</Link>
</HasPermission>
)
},
header: t("common.action"),
enableHiding: false
}),
]

<div className="overflow-x-hidden">
<table className="min-w-full bg-white shadow-md rounded">
<thead>
<tr className="bg-gray-700 text-white">
<th className="py-3 px-4 rounded-l font-semibold text-left">
{t("common.id")}
</th>
<th className="py-3 px-4 font-semibol text-left">
{t("common.name")}
</th>
<th className="py-3 px-4 font-semibol text-left">
{t("common.identifier")}
</th>
<th className="py-3 px-4 font-semibol text-left">
{t("common.created_at")}
</th>
<th className="py-3 px-4 font-semibol text-left">
{t("common.updated_at")}
</th>
<th className="py-3 px-4 font-semibol text-left">
{t("common.created_by")}
</th>
<th className="py-3 px-4 font-semibol text-left">
{t("common.updated_by")}
</th>
<th className="py-3 px-4 rounded-r font-semibol text-left">
{t("common.action")}
</th>
</tr>
</thead>
<tbody className="">
{components.map((component: IComponentModel) => {
return (
<tr key={component.id} className="border-b">
<td className="py-3 px-4">{component.id}</td>
<td className="py-3 px-4">{component.name}</td>
<td className="py-3 px-4">{component.identifier}</td>
<td className="py-3 px-4">
{getFormattedDate(component.created_at)}
</td>
<td className="py-3 px-4">
{getFormattedDate(component.updated_at)}
</td>
<td className="py-3 px-4">{component.created_by}</td>
<td className="py-3 px-4">{component.updated_by}</td>
<td className="py-3 px-4">
const table = useReactTable({
data: components,
columns,
getCoreRowModel: getCoreRowModel(),
initialState: {
columnVisibility: {
created_at: false,
created_by: false
}
}
})

return (
<div className="flex-1 bg-white">
<div className="px-5 ml-64">
<div className="flex items-center">
<div className="p-5 text-2xl font-semibold text-primary-500">
{t("component.components")}
</div>
<HasPermission displayDenied={false} identifier="component_create">
<Link
className="font-medium text-primary-600 hover:text-primary-800"
to={`/admin/component-edit/${component.id}`}
className="ml-auto bg-primary-600 py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500"
to="/admin/component-create"
>
{t("common.edit")}
{t("common.create")}
</Link>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</HasPermission>
</div>

<div className="overflow-x-hidden">
<HasPermission identifier="component_table">
<AvoRedTable table={table}/>
</HasPermission>
</div>
</div>
</div>
</div>
);
}

Expand Down
8 changes: 6 additions & 2 deletions react-admin/src/pages/role/RoleCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function RoleCreate() {
resolver: joiResolver(RoleCreateSchema, {allowUnknown: true}),
});


const switchOnChange = ((key: string) => {

let permissions = getValues('permissions') ?? [];
Expand Down Expand Up @@ -126,7 +125,8 @@ function RoleCreate() {
<div className="p-3">
{renderSwitch('dashboard')}

{renderSwitch('setting')}
{renderSwitch('get_setting')}
{renderSwitch('save_setting')}
</div>
</div>

Expand All @@ -139,6 +139,7 @@ function RoleCreate() {
{renderSwitch('page_create')}
{renderSwitch('page_edit')}
{renderSwitch('page_delete')}
{renderSwitch('get_page')}
</div>
</div>

Expand All @@ -151,6 +152,7 @@ function RoleCreate() {
{renderSwitch('component_create')}
{renderSwitch('component_edit')}
{renderSwitch('component_delete')}
{renderSwitch('get_component')}
</div>
</div>
</div>
Expand Down Expand Up @@ -178,6 +180,7 @@ function RoleCreate() {
{renderSwitch('admin_user_create')}
{renderSwitch('admin_user_edit')}
{renderSwitch('admin_user_delete')}
{renderSwitch('get_admin_user')}
</div>
</div>

Expand All @@ -191,6 +194,7 @@ function RoleCreate() {
{renderSwitch('role_create')}
{renderSwitch('role_edit')}
{renderSwitch('role_delete')}
{renderSwitch('get_role')}
</div>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion react-admin/src/pages/role/RoleEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ function RoleEdit() {
<div className="p-3">
{renderSwitch('dashboard')}

{renderSwitch('setting')}
{renderSwitch('get_setting')}
{renderSwitch('save_setting')}
</div>
</div>

Expand All @@ -144,6 +145,7 @@ function RoleEdit() {
{renderSwitch('page_create')}
{renderSwitch('page_edit')}
{renderSwitch('page_delete')}
{renderSwitch('get_page')}
</div>
</div>

Expand All @@ -156,6 +158,7 @@ function RoleEdit() {
{renderSwitch('component_create')}
{renderSwitch('component_edit')}
{renderSwitch('component_delete')}
{renderSwitch('get_component')}
</div>
</div>
</div>
Expand Down Expand Up @@ -183,6 +186,7 @@ function RoleEdit() {
{renderSwitch('admin_user_create')}
{renderSwitch('admin_user_edit')}
{renderSwitch('admin_user_delete')}
{renderSwitch('get_admin_user')}
</div>
</div>

Expand All @@ -196,6 +200,7 @@ function RoleEdit() {
{renderSwitch('role_create')}
{renderSwitch('role_edit')}
{renderSwitch('role_delete')}
{renderSwitch('get_role')}
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit a496c70

Please sign in to comment.