Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Admin Page UI components (#9727)
Browse files Browse the repository at this point in the history
* Add Table Component

* adjust spacing in story

* put classes directly into tailwind table

* add table test

* added `xadmin` route for accessing the new admin panel

* added surface main theme

* improvements in tailwind table

* Improve modal styles

* Add Callout Text component

* remove engine canvas and fix table style

* Use popover state for modal

* fix conflicts

* Added copy text component

* added project table data and fix pagination

* added confirm dialog and fix border styles

* added AddEditProjectModal dialog and Label component

* added layout for update engine

* added checkbox, select components

wire up UpdateEngineModal

* added functionalities for AddProject

* add project submit

* add multiple modal support

* update project functionality

* correct multiple modal rendering behavior

* added toggle tailwind

* added user permission modal

* Add scrollbar to table

* Add tooltip component

tailwind doesnot seem to support nested pseudo element in styles, for eg: `hover:before:`. Hence, raw CSS is used here. TODO: to be updated with alternative implementation when found.

* Show loading indicator when projects are being loaded

* Improve Sidebar styles

* regression on loading spinner

* additional styles to table to accomodate max width

---------

Co-authored-by: aditya-mitra <[email protected]>
  • Loading branch information
CITIZENDOT and aditya-mitra authored Feb 20, 2024
1 parent 4a41fbf commit 508e17c
Show file tree
Hide file tree
Showing 44 changed files with 3,038 additions and 88 deletions.
23 changes: 19 additions & 4 deletions packages/client-core/i18n/en/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"ban": "Ban",
"yes": "Yes",
"no": "No",
"all": "All",
"refresh": "Refresh",
"fillRequiredFields": "Please fill all required field",
"fixErrorFields": "Please fix all errors"
Expand Down Expand Up @@ -132,6 +133,20 @@
"name": "Channel Name"
},
"project": {
"columns": {
"name": "Name",
"projectVersion": "Version",
"commitSHA": "Commit SHA",
"commitDate": "Commit Date",
"actions": "Actions"
},
"actions": {
"push": "Push",
"repo": "Repo",
"access": "Access",
"invalidateCache": "Invalidate Cache",
"update": "Update"
},
"addProject": "Add Project",
"updateProject": "Update Project",
"downloadProject": "Download Project",
Expand All @@ -143,7 +158,7 @@
"updateAndRebuild": "Update Engine/Rebuild",
"checking": "Checking Rebuild",
"project": "Project",
"githubUrl": "Github URL",
"githubUrl": "GitHub URL",
"urlRequired": "URL is required",
"urlCantEmpty": "URL can't be empty",
"updateGithubRepoLink": "Update GitHub Repo Link",
Expand Down Expand Up @@ -180,9 +195,9 @@
"sourceProjectName": "Project in source repo",
"destinationProjectName": "Project in destination repo",
"destinationRepoEmpty": "The destination repo is empty",
"destinationURLValid": "Destination URL valid and accessible?",
"sourceURLValid": "Source URL valid and accessible?",
"sourceMatchesDestination": "Source Project matches destination, or destination empty?",
"destinationURLValid": "Is Destination URL valid and accessible?",
"sourceURLValid": "Is Source URL valid and accessible?",
"sourceMatchesDestination": "Does Source Project match destination, or destination empty?",
"changeDestination": "Change Destination Repo",
"copyDestination": "Copy Destination",
"autoUpdate": "Auto Update",
Expand Down
4 changes: 3 additions & 1 deletion packages/client-core/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"select": "Select",
"enter": "Enter",
"processing": "Processing",
"retry": "Retry"
"retry": "Retry",
"close": "Close",
"submit": "Submit"
},
"tooltip": {
"pressKey": "Press {{tip}} to {{message}}"
Expand Down
16 changes: 14 additions & 2 deletions packages/client-core/src/common/services/PopoverState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { defineState } from '@etherealengine/hyperflux'
import { defineState, getMutableState } from '@etherealengine/hyperflux'

/**
* Popover state for tailwind routes
*/
export const PopoverState = defineState({
name: 'ee.client.PopoverState',
initial: {
element: null as JSX.Element | null
elements: [] as (JSX.Element | null)[]
},

/**shows a popupover. if a previous popover was already present, the `element` popover will be current showed */
showPopupover: (element: JSX.Element) => {
getMutableState(PopoverState).elements.merge([element])
},
/**close the current popover. if a previous popover was present, the previous one will be shown */
hidePopupover: () => {
getMutableState(PopoverState).elements.set((prevElements) => {
prevElements.pop()
return prevElements
})
}
})
8 changes: 6 additions & 2 deletions packages/client-core/src/common/services/ThemeService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ const lightTheme = {
'bg-primary': '#F5F5F5',
'bg-secondary': '#FFFFFF',
'bg-highlight': '#FFFFFF',
'bg-surface-main': '#F5F5F5',
'text-primary': '#262626',
'text-secondary': '#6B7280',
'text-highlight': '#FFFFFF'
'text-highlight': '#FFFFFF',
'border-primary': '#E5E7EB'
}

const darkTheme = {
'bg-primary': '#111113',
'bg-secondary': '#1A1B1E',
'bg-highlight': '#212226',
'bg-surface-main': '#1A1B1E',
'text-primary': '#F5F5F5',
'text-secondary': '#D4D4D4',
'text-highlight': '#FFFFFF'
'text-highlight': '#FFFFFF',
'border-primary': '#2B2C30'
}

const themes = {
Expand Down
116 changes: 116 additions & 0 deletions packages/client/src/pages/admin2/admin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import { ThemeState } from '@etherealengine/client-core/src/common/services/ThemeService'
import { useRemoveEngineCanvas } from '@etherealengine/client-core/src/hooks/useRemoveEngineCanvas'
import PopupMenu from '@etherealengine/ui/src/primitives/tailwind/PopupMenu'
import React, { useEffect } from 'react'
import {
HiArrowRightOnRectangle,
HiCog8Tooth,
HiCube,
HiFolder,
HiOutlineHome,
HiOutlineMapPin,
HiOutlineTableCells,
HiPlay,
HiServer,
HiSquaresPlus,
HiUser,
HiUserCircle
} from 'react-icons/hi2'
import { RiSendPlaneFill } from 'react-icons/ri'
import AdminProject from './components/project'

const sideBarItems = [
{ label: 'Dashboard', icon: <HiOutlineHome /> },
{ label: 'Projects', icon: <HiOutlineTableCells /> },
{ label: 'Location', icon: <HiOutlineMapPin /> },
{ label: 'Instances', icon: <HiCube /> },
{ label: 'Servers', icon: <HiServer /> },
{ label: 'Avatars', icon: <HiUserCircle /> },
{ label: 'Plugins', icon: <HiSquaresPlus /> },
// {label: 'Teams', icon: <HiUsers />},
{ label: 'Users', icon: <HiUser /> },
{ label: 'Invites', icon: <RiSendPlaneFill /> },
{ label: 'Recordings', icon: <HiPlay /> },
{ label: 'Files', icon: <HiFolder /> },
{ label: 'Settings', icon: <HiCog8Tooth /> }
]

const AdminSidebar = () => {
return (
<aside className="bg-theme-surfaceMain mx-8 min-w-[15vw] rounded-lg px-2 py-4">
<ul className="space-y-2">
{sideBarItems.map((item) => (
<li key={item.label}>
<a
href="#"
className="text-theme-secondary flex items-center gap-3 rounded-xl px-2 py-3 hover:bg-[#212226]"
>
{item.icon}
{item.label}
</a>
</li>
))}
<li>
<a href="#" className="text-theme-secondary my-2 flex items-center rounded-sm px-2 py-3 hover:bg-[#212226]">
<HiArrowRightOnRectangle />
Log Out
</a>
</li>
</ul>
</aside>
)
}

const Admin = () => {
useRemoveEngineCanvas()
useEffect(() => {
ThemeState.setTheme('dark')
}, [])
return (
<main className="pointer-events-auto mt-6 flex gap-1.5">
{/* only for multitenancy
<nav className="w-full px-8 py-4 mb-1.5 flex items-center justify-between bg-theme-surfaceMain">
<img src={EELogo} className="h-8 w-8" />
<div className="h-full flex items-center gap-8">
<Text theme='secondary'>Dashboard</Text>
<div className='flex items-center border-b border-b-blue-400'><Text>Admin</Text></div>
<Text theme='secondary'>Store</Text>
<Text theme='secondary'>Documentation</Text>
</div>
<img src={EELogo} className="h-8 w-8" />
</nav> */}
<AdminSidebar />
<div className="w-[80%]">
<AdminProject />
</div>
<PopupMenu />
</main>
)
}

export default Admin
122 changes: 122 additions & 0 deletions packages/client/src/pages/admin2/common/Table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import React, { ReactNode } from 'react'
import { HiArrowSmallDown, HiArrowSmallUp } from 'react-icons/hi2'

import { FeathersOrder, useFind } from '@etherealengine/spatial/src/common/functions/FeathersHooks'
import LoadingCircle from '@etherealengine/ui/src/primitives/tailwind/LoadingCircle'
import Table, {
TableBody,
TableCell,
TableHeadRow,
TableHeaderCell,
TablePagination,
TableRow
} from '@etherealengine/ui/src/primitives/tailwind/Table'

export interface ITableHeadCell {
id: string | number
label: string
sortable?: boolean
className?: string
}

interface TableHeadProps {
onRequestSort: (property: string | number, order: FeathersOrder) => void
order: FeathersOrder
orderBy: string | number
columns: ITableHeadCell[]
}

const TableHead = ({ order, orderBy, onRequestSort, columns }: TableHeadProps) => {
const SortArrow = ({ columnId }: { columnId: string | number }) => {
if (columnId === orderBy) {
if (order === 1) {
return <HiArrowSmallUp onClick={() => onRequestSort(columnId, -1)} />
}
return <HiArrowSmallDown onClick={() => onRequestSort(columnId, 1)} />
}
return <HiArrowSmallUp className={'opacity-0 hover:opacity-50'} />
}

return (
<TableHeadRow>
{columns.map((column) => (
<TableHeaderCell key={column.id} className={column.className}>
{column.sortable ? (
<span className="flex items-center gap-2">
{column.label}
{<SortArrow columnId={column.id} />}
</span>
) : (
column.label
)}
</TableHeaderCell>
))}
</TableHeadRow>
)
}

interface DataTableProps {
query: ReturnType<typeof useFind>
rows: Record<string | 'className' | 'id', string | ReactNode>[]
columns: ITableHeadCell[]
}

const DataTable = ({ query, columns, rows }: DataTableProps) => {
const [orderBy, order] = (Object.entries(query.sort)[0] as [string | number, FeathersOrder]) ?? ['', 0]

return query.status !== 'success' ? (
<div className="flex h-96 w-full items-center justify-center">
<LoadingCircle className="flex w-1/4 items-center justify-center" />
</div>
) : (
<Table>
<TableHead
order={order}
orderBy={orderBy}
onRequestSort={(property, order) => query.setSort({ [property]: order })}
columns={columns}
/>
<TableBody>
{rows.map((row, rowIdx) => (
<TableRow key={typeof row['id'] === 'string' ? row['id'] : rowIdx}>
{columns.map((column, columnIdx) => (
<TableCell key={columnIdx}>{row[column.id]}</TableCell>
))}
</TableRow>
))}
</TableBody>
<TablePagination
totalPages={Math.ceil(query.total / query.limit)}
currentPage={query.page}
onPageChange={(newPage) => query.setPage(newPage)}
/>
</Table>
)
}

export default DataTable
43 changes: 43 additions & 0 deletions packages/client/src/pages/admin2/common/constants/project.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
CPAL-1.0 License
The contents of this file are subject to the Common Public Attribution License
Version 1.0. (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
https://github.com/EtherealEngine/etherealengine/blob/dev/LICENSE.
The License is based on the Mozilla Public License Version 1.1, but Sections 14
and 15 have been added to cover use of software over a computer network and
provide for limited attribution for the Original Developer. In addition,
Exhibit A has been modified to be consistent with Exhibit B.
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is Ethereal Engine.
The Original Developer is the Initial Developer. The Initial Developer of the
Original Code is the Ethereal Engine team.
All portions of the code written by the Ethereal Engine team are Copyright © 2021-2023
Ethereal Engine. All Rights Reserved.
*/

import { t } from 'i18next'
import { ITableHeadCell } from '../Table'

type IdType = 'name' | 'projectVersion' | 'commitSHA' | 'commitDate' | 'actions'

export type ProjectRowType = Record<IdType, string | JSX.Element | undefined>

interface IProjectColumn extends ITableHeadCell {
id: IdType
}

export const projectsColumns: IProjectColumn[] = [
{ id: 'name', sortable: true, label: t('admin:components.project.columns.name') },
{ id: 'projectVersion', label: t('admin:components.project.columns.projectVersion') },
{ id: 'commitSHA', label: t('admin:components.project.columns.commitSHA') },
{ id: 'commitDate', sortable: true, label: t('admin:components.project.columns.commitDate') },
{ id: 'actions', label: t('admin:components.project.columns.actions') }
]
Loading

0 comments on commit 508e17c

Please sign in to comment.