-
Notifications
You must be signed in to change notification settings - Fork 102
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
feat: enable passing of documentation link to form properties panel #1201
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 44 additions & 59 deletions
103
packages/form-js-editor/src/features/properties-panel/PropertiesPanelHeaderProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,50 @@ | ||
import { textToLabel } from './Util'; | ||
|
||
import { iconsByType } from '../../render/components/icons'; | ||
|
||
import { getPaletteIcon } from '../palette/components/Palette'; | ||
|
||
import { useService } from './hooks'; | ||
|
||
const headerlessTypes = ['spacer', 'separator', 'expression', 'html']; | ||
|
||
export const PropertiesPanelHeaderProvider = { | ||
getElementLabel: (field) => { | ||
const { type } = field; | ||
|
||
if (headerlessTypes.includes(type)) { | ||
return ''; | ||
} | ||
|
||
if (type === 'text') { | ||
return textToLabel(field.text); | ||
} | ||
|
||
if (type === 'image') { | ||
return field.alt; | ||
} | ||
|
||
if (type === 'default') { | ||
return field.id; | ||
} | ||
|
||
return field.label; | ||
}, | ||
|
||
getElementIcon: (field) => { | ||
const { type } = field; | ||
|
||
// @Note: We know that we are inside the properties panel context, | ||
// so we can savely use the hook here. | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const fieldDefinition = useService('formFields').get(type).config; | ||
|
||
const Icon = fieldDefinition.icon || iconsByType(type); | ||
|
||
if (Icon) { | ||
return () => <Icon width="36" height="36" viewBox="0 0 54 54" />; | ||
} else if (fieldDefinition.iconUrl) { | ||
return getPaletteIcon({ iconUrl: fieldDefinition.iconUrl, label: fieldDefinition.label }); | ||
} | ||
}, | ||
|
||
getTypeLabel: (field) => { | ||
const { type } = field; | ||
|
||
if (type === 'default') { | ||
return 'Form'; | ||
} | ||
|
||
// @Note: We know that we are inside the properties panel context, | ||
// so we can savely use the hook here. | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
const fieldDefinition = useService('formFields').get(type).config; | ||
|
||
return fieldDefinition.label || type; | ||
}, | ||
}; | ||
export function getPropertiesPanelHeaderProvider(options = {}) { | ||
const { getDocumentationRef, formFields } = options; | ||
|
||
return { | ||
getElementLabel: (field) => { | ||
const { type } = field; | ||
if (headerlessTypes.includes(type)) { | ||
return ''; | ||
} | ||
if (type === 'text') { | ||
return textToLabel(field.text); | ||
} | ||
if (type === 'image') { | ||
return field.alt; | ||
} | ||
if (type === 'default') { | ||
return field.id; | ||
} | ||
return field.label; | ||
}, | ||
|
||
getElementIcon: (field) => { | ||
const { type } = field; | ||
const fieldDefinition = formFields.get(type).config; | ||
const Icon = fieldDefinition.icon || iconsByType(type); | ||
if (Icon) { | ||
return () => <Icon width="36" height="36" viewBox="0 0 54 54" />; | ||
} else if (fieldDefinition.iconUrl) { | ||
return getPaletteIcon({ iconUrl: fieldDefinition.iconUrl, label: fieldDefinition.label }); | ||
} | ||
}, | ||
|
||
getTypeLabel: (field) => { | ||
const { type } = field; | ||
if (type === 'default') { | ||
return 'Form'; | ||
} | ||
const fieldDefinition = formFields.get(type).config; | ||
return fieldDefinition.label || type; | ||
}, | ||
|
||
getDocumentationRef, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Was this memo really necessary? If you didn't see any noticeable performance issue without it we should remove to avoid memory leaks
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.
Nothing is necessary but not having this means we re-render the whole header every render cycle. Which isn't ideal. It won't lag, yet, but could cause problems down the line.
Basically, this header provider stuff is a config, and we need to keep the reference to the config stable, hence the memo.
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.
@Skaiir Just rerendering is not an issue, as long as rerendering doesn't take long. Also, not all rerenders are committed to the DOM which is usually the most expensive.
But overusing memoization might cause memory leaks as explained here
It's better to only memoize when it's accompanied by some performance issue, and even then most of the time you can easily just restructure your logic.