-
Notifications
You must be signed in to change notification settings - Fork 5
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
Save version history #96
base: main
Are you sure you want to change the base?
Changes from all commits
ef04443
1dd5076
fb76813
3a1c2b1
8b8f338
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,74 @@ import { LinkForm } from './LinkForm'; | |
import { AddLink } from './AddLink'; | ||
import { ActionCloseIcon } from '../../svgs/ActionCloseIcon'; | ||
import { displayDate } from '../../utilities/Utils'; | ||
import { LinkType } from '../../types/LinkTypes'; | ||
|
||
const { widget } = figma; | ||
const { widget, saveVersionHistoryAsync } = figma; | ||
const { AutoLayout, Text } = widget; | ||
|
||
async function saveToVersionHistory( | ||
name: string, | ||
type: string, | ||
description: string, | ||
links: LinkType[] | undefined, | ||
showName: boolean, | ||
showTypes: boolean, | ||
showVersion: boolean, | ||
version?: string, | ||
) { | ||
const formattedLinks = links?.map(link => `${link.label}\n${link.url}`).join('\n\n') || ''; | ||
if (!description.trim() && !formattedLinks.trim()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be able to add formatting around the links as well, maybe check here against Also, why does the lack of description or links stop a version history point from being created? Shouldn't a version history point always be created with a new log, even if it doesn't include a description? |
||
return; | ||
} | ||
|
||
let typeFormatted = ''; | ||
if (showTypes) { | ||
switch (type) { | ||
case 'none': | ||
break; | ||
case 'added': // catch legacy logs with "added" as default type | ||
typeFormatted = ''; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to set this to an empty string, it already is one, you can stack the 'none' and 'added' cases together and just break. Also, I wish we didn't need to repeat this logic since we are using something super similar in the Type component, but not sure if that is worth the refactor at this moment. |
||
case 'newAdd': | ||
typeFormatted = 'Added'; | ||
break; | ||
case 'breaking': | ||
typeFormatted = 'Breaking'; | ||
break; | ||
case 'changed': | ||
typeFormatted = 'Changed'; | ||
break; | ||
case 'deprecated': | ||
typeFormatted = 'Deprecated'; | ||
break; | ||
case 'fixed': | ||
typeFormatted = 'Fixed'; | ||
break; | ||
case 'removed': | ||
typeFormatted = 'Removed'; | ||
break; | ||
default: | ||
typeFormatted = 'Other'; | ||
break; | ||
} | ||
} | ||
|
||
const nameParts = ['FigLog']; | ||
const innerParts = [ | ||
showName && name, | ||
showVersion && version && `${version}`, | ||
showTypes && `(${typeFormatted})`, | ||
].filter(Boolean); | ||
|
||
if (innerParts.length > 0) { | ||
nameParts.push(` | ${innerParts.join(' ')}`); | ||
} | ||
|
||
const nameFormatted = nameParts.join(''); | ||
const descriptionFormatted = `${description}\n\n- - - -\n\n${formattedLinks}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
await saveVersionHistoryAsync(nameFormatted, descriptionFormatted); | ||
} | ||
|
||
interface ChangeLogEditingProps { | ||
changeLog: ChangeLog; | ||
updateChange: (changes: Partial<ChangeLog>) => void; | ||
|
@@ -22,6 +86,10 @@ interface ChangeLogEditingProps { | |
setUpdatedDate: (updatedDate: number) => void; | ||
showTypes: boolean; | ||
isLastRow: boolean; | ||
nameText: string; | ||
showName: boolean; | ||
showVersion: boolean; | ||
version: string; | ||
} | ||
|
||
export const ChangeLogEditing = ({ | ||
|
@@ -32,6 +100,10 @@ export const ChangeLogEditing = ({ | |
setUpdatedDate, | ||
showTypes, | ||
isLastRow, | ||
nameText, | ||
showName, | ||
showVersion, | ||
version, | ||
}: ChangeLogEditingProps) => { | ||
return ( | ||
<AutoLayout | ||
|
@@ -166,7 +238,21 @@ export const ChangeLogEditing = ({ | |
}, | ||
}, | ||
}); | ||
|
||
setUpdatedDate(Date.now()); | ||
|
||
saveToVersionHistory( | ||
nameText, | ||
saveType, | ||
saveChange, | ||
saveLinks, | ||
showName, | ||
showTypes, | ||
showVersion, | ||
version, | ||
) | ||
.then(val => console.log('Version History Saved', val)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
.catch(e => console.log('Error saving version history', e)); | ||
} | ||
}} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with some older widgets and it seems fine.