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

Meditor 910 history reporting incorrectly #66

Merged
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
18 changes: 15 additions & 3 deletions packages/app/components/document/document-history.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
}

.pastState {
color: grey;
display: flex;
padding-top: 10px;
padding-left: 20px;
Expand All @@ -78,7 +77,6 @@

.pastState:first-child:before {
content: '';
border-left: 1px solid grey;
position: absolute;
top: -4px;
height: 20px;
Expand All @@ -89,10 +87,24 @@
display: none;
}

.pastState svg {
.dotCircleIcon {
position: absolute;
top: 10px;
left: 0;
color: grey;
}

.arrowRightIcon {
color: grey;
margin: 0 3px;
}

.stateTransition {
margin-bottom: 4px;
}

.stateModifier {
color: grey;
}

.activeHistory {
Expand Down
48 changes: 32 additions & 16 deletions packages/app/components/document/document-history.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
import Button from 'react-bootstrap/Button'
import Card from 'react-bootstrap/Card'
import { FaRegDotCircle } from 'react-icons/fa'
import { FaRegDotCircle, FaArrowRight } from 'react-icons/fa'
import { IoMdEye, IoMdEyeOff } from 'react-icons/io'
import { useLocalStorage } from '../../lib/use-localstorage.hook'
import styles from './document-history.module.css'
import DocumentStateBadge from './document-state-badge'

const sortByLastModifiedDesc = (a, b) => {
// Used to sort the history details in descending order. NO LONGER USED
let dateA = new Date(a.modifiedOn)
let dateB = new Date(b.modifiedOn)

return dateA > dateB ? -1 : dateA < dateB ? 1 : 0
}

const formatDate = date => {
date = new Date(date)

// Format the date to a more readable format
const formattedDate = date.toLocaleString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})
return formattedDate
}

const PastState = ({ state }) => (
<div className={styles.pastState}>
<div>
<FaRegDotCircle />

<FaRegDotCircle className={styles.dotCircleIcon} />
<div>
<div>{state.source}</div>
<div>
<div className={styles.stateTransition}>
{state.source} <FaArrowRight className={styles.arrowRightIcon} />{' '}
{state.target}
</div>
<div className={styles.stateModifier}>
<em>
{state.modifiedBy} on {state.modifiedOn}
{state.modifiedBy} on {formatDate(state.modifiedOn)}
</em>
</div>
</div>
Expand All @@ -39,7 +57,7 @@ const DocumentHistory = ({
const [historyPreferences, setHistoryPreferences] = useLocalStorage(
'historyPreferences',
{
showDetails: false,
showDetails: true, // Initial value if historyPreferences.showDetails not set on local storage.
}
)

Expand Down Expand Up @@ -112,7 +130,7 @@ const DocumentHistory = ({
<Card.Body>
<div className={styles.body}>
<div className={styles.meta}>
<a>{item.modifiedOn}</a>
<a>{formatDate(item.modifiedOn)}</a>
{item.modifiedBy}
</div>

Expand All @@ -129,14 +147,12 @@ const DocumentHistory = ({
: ''
}`}
>
{item.states
?.sort(sortByLastModifiedDesc)
.map(state => (
<PastState
state={state}
key={state.source + state.modifiedOn}
/>
))}
{item.states.map(state => (
<PastState
state={state}
key={state.source + state.modifiedOn}
/>
))}
</div>
)}
</Card.Body>
Expand Down
15 changes: 10 additions & 5 deletions packages/app/documents/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function createDocument(
)
}

// validate that there is at least one edge going from "Init" to to the initialState
// validate that there is at least one edge going from "Init" to the initialState
if (
!workflow.edges.some(
edge => edge.source === INIT_STATE && edge.target === initialState
Expand Down Expand Up @@ -95,11 +95,16 @@ export async function createDocument(
}

//* This logic (and associated TODO) is ported from Meditor.js, saveDocument. Minimal modifications were made.
const rootState = { source: INIT_STATE, target: initialState }
const modifiedDate = new Date().toISOString()

// @ts-ignore
rootState.modifiedOn = document['x-meditor'].modifiedOn
document['x-meditor'].modifiedOn = new Date().toISOString()
//* Create the INITAL state history for a NEW document or an Edited/Saved document which creates a new DB object of the document.
const rootState = {
source: INIT_STATE,
target: initialState,
modifiedOn: modifiedDate,
}

document['x-meditor'].modifiedOn = modifiedDate
document['x-meditor'].modifiedBy = user.uid
// TODO: replace with actual model init state
document['x-meditor'].states = [rootState]
Expand Down
Loading