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

Commit

Permalink
Merge branch 'dev' into michael/IR-3667_scene_name_too_long
Browse files Browse the repository at this point in the history
* dev:
  IR-3602-Changing-CSM-cascade-count-or-tonemapping-spams-errors (#10926)
  hotfix gizmo zeroed position on rigidbody entities (#10943)
  Add download progress bar and optimize util files (#10914)
  [IR-3547] studio: show unsaved changes dialog when switching between scenes (#10921)
  added tailwind class to break the line in the middle of words to prevent overflowing the alocated space (#10944)
  Updating the description of hemisphere lights to better explain what they do and why. (#10945)
  Left aligning the text in the "Add Component" and "Add Entity" menus (#10946)
  studio: open context menu on file menu right click (#10908)
  Fixed a bug with project PUTs without commit SHAs (#10942)
  IR-2873 Fix disabled state for select dropdown arrow (#10950)
  IR-3700: Added search by sso/email in user table (#10929)
  IR-3053: Add project-history service (#10736)
  Component dependencies (#10916)
  [IR-3324] studio: drag-n-drop folders (#10737)
  prevent scene from disappearing when double-clicking on a HierarchyTreeNode (#10932)
  fix tooltip css applied to all popups (#10938)
  • Loading branch information
MbfloydIR committed Aug 13, 2024
2 parents aa92c34 + a3efe4d commit 8851071
Show file tree
Hide file tree
Showing 83 changed files with 2,815 additions and 455 deletions.
8 changes: 6 additions & 2 deletions packages/client-core/i18n/en/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@
"lastUpdatedBy": "Last updated by user id: {{userId}} on {{updatedAt}}",
"fillRequiredFields": "Please fill all required field",
"fixErrorFields": "Please fix all errors",
"logOut": "Log Out"
"logOut": "Log Out",
"newestFirst": "Newest First",
"oldestFirst": "Oldest First"
},
"analytics": {
"loading": "Loading analytics...",
Expand Down Expand Up @@ -214,8 +216,10 @@
"repo": "Repo",
"access": "Access",
"invalidateCache": "Invalidate Cache",
"update": "Update"
"update": "Update",
"history": "History"
},
"projectHistory": "Project History",
"addProject": "Add Project",
"updateProject": "Update Project",
"downloadProject": "Download Project",
Expand Down
10 changes: 7 additions & 3 deletions packages/client-core/i18n/en/editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@
},
"hemisphere": {
"name": "Hemisphere Light",
"description": "A light which illuminates the scene from directly overhead.",
"description": "A light which illuminates the scene with a sky color from above and a ground color from below.",
"lbl-skyColor": "Sky Color",
"lbl-groundColor": "Ground Color",
"lbl-intensity": "Intensity"
Expand Down Expand Up @@ -1177,7 +1177,7 @@
"point-light": "A light which emits in all directions from a single point.",
"spot-light": "Creates a light that shines in a specific direction.",
"directional-light": "Creates a light that emits evenly in a single direction.",
"hemisphere-light": "A light which illuminates the scene from directly overhead.",
"hemisphere-light": "A light which illuminates the scene with a sky color from above and a ground color from below.",
"particle-system": "Creates a particle emitter.",
"system": "Inserts code into the scene by creating a new Entity Component System based on the provided .ts file",
"visual-script": "Customizes state and behavior of entities through a visual node connections.",
Expand Down Expand Up @@ -1217,6 +1217,7 @@
"uploadFiles": "Upload Files",
"uploadFolder": "Upload Folder",
"uploadingFiles": "Uploading Files ({{completed}}/{{total}})",
"downloadingProject": "Downloading Project ({{completed}}/{{total}})",
"search-placeholder": "Search",
"generatingThumbnails": "Generating Thumbnails ({{count}} remaining)",
"file": "File",
Expand Down Expand Up @@ -1360,7 +1361,10 @@
"lbl-thumbnail": "Generate thumbnail & envmap",
"lbl-confirm": "Save Scene",
"info-confirm": "Are you sure you want to save the scene?",
"info-question": "Do you want to save the current scene?"
"info-question": "Do you want to save the current scene?",
"unsavedChanges": {
"title": "Unsaved Changes"
}
},
"saveNewScene": {
"title": "Save As",
Expand Down
302 changes: 302 additions & 0 deletions packages/client-core/src/admin/components/project/ProjectHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
/*
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 { projectHistoryPath } from '@etherealengine/common/src/schema.type.module'
import { ProjectHistoryType } from '@etherealengine/common/src/schemas/projects/project-history.schema'
import { useFind } from '@etherealengine/spatial/src/common/functions/FeathersHooks'

import { toDisplayDateTime } from '@etherealengine/common/src/utils/datetime-sql'
import AvatarImage from '@etherealengine/ui/src/primitives/tailwind/AvatarImage'
import Button from '@etherealengine/ui/src/primitives/tailwind/Button'
import { TablePagination } from '@etherealengine/ui/src/primitives/tailwind/Table'
import Text from '@etherealengine/ui/src/primitives/tailwind/Text'
import Tooltip from '@etherealengine/ui/src/primitives/tailwind/Tooltip'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { FaSortAmountDown, FaSortAmountUpAlt } from 'react-icons/fa'

const PROJECT_HISTORY_PAGE_LIMIT = 10

const getRelativeURLFromProject = (projectName: string, url: string) => {
const prefix = `projects/${projectName}/`
if (url.startsWith(prefix)) {
return url.replace(prefix, '')
}
return url
}

const getResourceURL = (projectName: string, url: string, resourceType: 'resource' | 'scene') => {
const relativeURL = getRelativeURLFromProject(projectName, url)
const resourceURL =
resourceType === 'resource'
? `/projects/${projectName}/${relativeURL}`
: `/studio?project=${projectName}&scenePath=${url}`
return {
relativeURL,
resourceURL
}
}

function HistoryLog({ projectHistory, projectName }: { projectHistory: ProjectHistoryType; projectName: string }) {
const { t } = useTranslation()

const RenderAction = () => {
if (projectHistory.action === 'LOCATION_PUBLISHED' || projectHistory.action === 'LOCATION_UNPUBLISHED') {
const actionDetail = JSON.parse(projectHistory.actionDetail) as {
locationName: string
sceneURL: string
sceneId: string
}

const verb = projectHistory.action === 'LOCATION_PUBLISHED' ? 'published' : 'unpublished'

const { relativeURL, resourceURL } = getResourceURL(projectName, actionDetail.sceneURL, 'scene')

return (
<>
<Text>{verb} the location</Text>

{verb === 'published' ? (
<a href={`/location/${actionDetail.locationName}`}>
<Text className="underline-offset-4 hover:underline" fontWeight="semibold">
{actionDetail.locationName}
</Text>
</a>
) : (
<Text className="underline-offset-4 hover:underline" fontWeight="semibold">
{actionDetail.locationName}
</Text>
)}

<Text>from the scene</Text>

<Text href={resourceURL} component="a" className="underline-offset-4 hover:underline" fontWeight="semibold">
{relativeURL}.
</Text>
</>
)
} else if (projectHistory.action === 'LOCATION_MODIFIED') {
const actionDetail = JSON.parse(projectHistory.actionDetail) as {
locationName: string
}

return (
<>
<Text>modified the location</Text>

<a href={`/location/${actionDetail.locationName}`}>
<Text className="underline-offset-4 hover:underline" fontWeight="semibold">
{actionDetail.locationName}
</Text>
</a>
</>
)
} else if (projectHistory.action === 'PERMISSION_CREATED' || projectHistory.action === 'PERMISSION_REMOVED') {
const actionDetail = JSON.parse(projectHistory.actionDetail) as {
userName: string
userId: string
permissionType: string
}

const verb = projectHistory.action === 'PERMISSION_CREATED' ? 'added' : 'removed'

return (
<>
<Text>{verb} the</Text>
<Text fontWeight="semibold">{actionDetail.permissionType}</Text>

<Text>access to</Text>

<Tooltip content={`UserId: ${actionDetail.userId}`}>
<Text>{actionDetail.userName}</Text>
</Tooltip>
</>
)
} else if (projectHistory.action === 'PERMISSION_MODIFIED') {
const actionDetail = JSON.parse(projectHistory.actionDetail) as {
userName: string
userId: string
oldPermissionType: string
newPermissionType: string
}

return (
<>
<Text>updated the permission of the user</Text>
<Tooltip content={`UserId: ${actionDetail.userId}`}>
<Text>{actionDetail.userName}</Text>
</Tooltip>
<Text>from</Text>
<Text fontWeight="semibold">{actionDetail.oldPermissionType}</Text>
<Text>to</Text>
<Text fontWeight="semibold">{actionDetail.newPermissionType}</Text>
</>
)
} else if (projectHistory.action === 'PROJECT_CREATED') {
return <Text>created the project</Text>
} else if (
projectHistory.action === 'RESOURCE_CREATED' ||
projectHistory.action === 'RESOURCE_REMOVED' ||
projectHistory.action === 'SCENE_CREATED' ||
projectHistory.action === 'SCENE_REMOVED'
) {
const verb =
projectHistory.action === 'RESOURCE_CREATED' || projectHistory.action === 'SCENE_CREATED'
? 'created'
: 'removed'
const object =
projectHistory.action === 'RESOURCE_CREATED' || projectHistory.action === 'RESOURCE_REMOVED'
? 'resource'
: 'scene'

const actionDetail = JSON.parse(projectHistory.actionDetail) as {
url: string
}

const { relativeURL, resourceURL } = getResourceURL(projectName, actionDetail.url, object)

return (
<>
<Text>
{verb} the {object}
</Text>
<Text href={resourceURL} component="a" fontWeight="semibold" className="underline-offset-4 hover:underline">
{relativeURL}
</Text>
</>
)
} else if (projectHistory.action === 'RESOURCE_RENAMED' || projectHistory.action === 'SCENE_RENAMED') {
const object = projectHistory.action === 'RESOURCE_RENAMED' ? 'resource' : 'scene'
const actionDetail = JSON.parse(projectHistory.actionDetail) as {
oldURL: string
newURL: string
}

const { relativeURL: oldRelativeURL } = getResourceURL(projectName, actionDetail.oldURL, object)
const { relativeURL: newRelativeURL, resourceURL: newResourceURL } = getResourceURL(
projectName,
actionDetail.newURL,
object
)

return (
<>
<Text>renamed a {object} from</Text>

<Text fontWeight="semibold">{oldRelativeURL}</Text>
<Text>to</Text>
<Text
href={newResourceURL}
component="a"
fontWeight="semibold"
className="underline-offset-4 hover:underline"
>
{getRelativeURLFromProject(projectName, newRelativeURL)}
</Text>
</>
)
} else if (projectHistory.action === 'RESOURCE_MODIFIED' || projectHistory.action === 'SCENE_MODIFIED') {
const object = projectHistory.action === 'RESOURCE_MODIFIED' ? 'resource' : 'scene'
const actionDetail = JSON.parse(projectHistory.actionDetail) as {
url: string
}

const { relativeURL, resourceURL } = getResourceURL(projectName, actionDetail.url, object)

return (
<>
<Text>modified the {object}</Text>
<Text href={resourceURL} component="a" fontWeight="semibold" className="underline-offset-4 hover:underline">
{relativeURL}
</Text>
</>
)
}

return null
}

return (
<div className="mb-3 flex w-full items-center justify-between rounded-lg bg-[#191B1F] px-5 py-2">
<div className="grid grid-flow-col place-items-center gap-x-2 [&>*]:text-nowrap">
<AvatarImage
className="inline-grid min-h-10 min-w-10 rounded-full"
src={projectHistory.userAvatarURL}
name={projectHistory.userName}
/>

<Text className="text-nowrap">{projectHistory.userName}</Text>

<RenderAction />
</div>

<Text className="text-nowrap">{toDisplayDateTime(projectHistory.createdAt)}</Text>
</div>
)
}

export const ProjectHistory = ({ projectId, projectName }: { projectId: string; projectName: string }) => {
const { t } = useTranslation()
const projectHistoryQuery = useFind(projectHistoryPath, {
query: {
projectId: projectId,
$sort: {
createdAt: -1
},
$limit: PROJECT_HISTORY_PAGE_LIMIT
}
})

const sortOrder = projectHistoryQuery.sort.createdAt

const toggleSortOrder = () => {
projectHistoryQuery.setSort({
createdAt: sortOrder === -1 ? 1 : -1
})
}

return (
<div className="w-full flex-row justify-between gap-5 px-2">
<Button
className="mb-4"
onClick={toggleSortOrder}
endIcon={sortOrder === -1 ? <FaSortAmountDown /> : <FaSortAmountUpAlt />}
>
{sortOrder === -1 ? t('admin:components.common.newestFirst') : t('admin:components.common.oldestFirst')}
</Button>

{projectHistoryQuery.data &&
projectHistoryQuery.data.map((projectHistory, index) => (
<HistoryLog key={index} projectHistory={projectHistory} projectName={projectName} />
))}

<TablePagination
totalPages={Math.ceil(projectHistoryQuery.total / projectHistoryQuery.limit)}
currentPage={projectHistoryQuery.page}
onPageChange={(newPage) => projectHistoryQuery.setPage(newPage)}
/>
</div>
)
}
Loading

0 comments on commit 8851071

Please sign in to comment.