-
Notifications
You must be signed in to change notification settings - Fork 82
[Subitems] Add extensibility point to add new views #2735
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b7c9ab0
Before prefix change
mnocon 8709a2d
Prefixes
mnocon 3c8a8e9
Screenshot
mnocon 30348fb
Adjusted example to v5
mnocon 5aa9c73
Vale suggestion
mnocon 34c5442
Added mention about replacing a view
mnocon 9bca0be
Improvements
mnocon 9a80704
Added mention of composer run post-install-cmd
mnocon 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const containerNode = document.querySelector('#sub-items-container'); | ||
|
||
ReactDOM.render( | ||
React.createElement(ibexa.modules.SubItems, { | ||
parentLocationId: { Number }, | ||
restInfo: { | ||
token: { String }, | ||
siteaccess: { String }, | ||
}, | ||
}), | ||
containerNode, | ||
); |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const attrs = { | ||
parentLocationId: {Number}, | ||
restInfo: { | ||
token: {String}, | ||
siteaccess: {String} | ||
} | ||
}; | ||
|
||
<SubItemsModule {...attrs}/> |
8 changes: 8 additions & 0 deletions
8
code_samples/back_office/subitems/timeline_view/registerTimelineView.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import TimelineViewComponent from './timeline.view.component.js'; | ||
import { registerView } from '@ibexa-admin-ui-modules/sub-items/services/view.registry'; | ||
|
||
registerView('timeline', { | ||
component: TimelineViewComponent, | ||
iconName: 'timeline', | ||
label: 'Timeline view', | ||
}); |
46 changes: 46 additions & 0 deletions
46
code_samples/back_office/subitems/timeline_view/timeline.view.component.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import TimelineViewItemComponent from './timeline.view.item.component'; | ||
|
||
const TimelineViewComponent = ({ items, generateLink }) => { | ||
const groupByDate = (items) => { | ||
return items.reduce((groups, item) => { | ||
const date = new Date(item.content._info.modificationDate.timestamp * 1000); | ||
const dateKey = date.toISOString().split('T')[0]; | ||
|
||
if (!groups[dateKey]) { | ||
groups[dateKey] = []; | ||
} | ||
|
||
groups[dateKey].push(item); | ||
return groups; | ||
}, {}); | ||
}; | ||
|
||
const groupedItems = groupByDate(items); | ||
|
||
return ( | ||
<div className="app-timeline-view"> | ||
{Object.entries(groupedItems).map(([date, dateItems]) => ( | ||
<div key={date} className="app-timeline-view__group"> | ||
<div className="app-timeline-view__date"> | ||
<div className="app-timeline-view__date-marker" /> | ||
<h3>{new Date(date).toLocaleDateString()}</h3> | ||
</div> | ||
<div className="app-timeline-view__items"> | ||
{dateItems.map((item) => ( | ||
<TimelineViewItemComponent key={item.id} item={item} generateLink={generateLink} /> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
TimelineViewComponent.propTypes = { | ||
items: PropTypes.array.isRequired, | ||
generateLink: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default TimelineViewComponent; |
34 changes: 34 additions & 0 deletions
34
code_samples/back_office/subitems/timeline_view/timeline.view.item.component.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Icon from '@ibexa-admin-ui-modules/common/icon/icon'; | ||
|
||
const { ibexa } = window; | ||
|
||
const TimelineViewItemComponent = ({ item, generateLink }) => { | ||
const { content } = item; | ||
const contentTypeIdentifier = content._info.contentType.identifier; | ||
const contentTypeIconUrl = ibexa.helpers.contentType.getContentTypeIconUrl(contentTypeIdentifier); | ||
const time = new Date(content._info.modificationDate.timestamp * 1000).toLocaleTimeString(); | ||
|
||
return ( | ||
<a className="app-timeline-view-item" href={generateLink(item.id, content._info.id)}> | ||
<div className="app-timeline-view-item__time">{time}</div> | ||
<div className="app-timeline-view-item__content"> | ||
<div className="app-timeline-view-item__info"> | ||
<div className="app-timeline-view-item__name">{content._name}</div> | ||
<div className="app-timeline-view-item__type"> | ||
<Icon customPath={contentTypeIconUrl} extraClasses="ibexa-icon--small" /> | ||
<span className="app-timeline-view-item__type-name">{content._info.contentType.name}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</a> | ||
); | ||
}; | ||
|
||
TimelineViewItemComponent.propTypes = { | ||
item: PropTypes.object.isRequired, | ||
generateLink: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default TimelineViewItemComponent; |
84 changes: 84 additions & 0 deletions
84
code_samples/back_office/subitems/timeline_view/timeline.view.scss
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@use '@ibexa-admin-ui/src/bundle/Resources/public/scss/custom.scss' as *; | ||
|
||
.app-timeline-view { | ||
padding: calculateRem(16px); | ||
|
||
&__group { | ||
position: relative; | ||
margin-bottom: calculateRem(32px); | ||
} | ||
|
||
&__date { | ||
display: flex; | ||
align-items: center; | ||
margin-bottom: calculateRem(16px); | ||
|
||
h3 { | ||
margin: 0; | ||
font-size: $ibexa-text-font-size-large; | ||
color: $ibexa-color-dark; | ||
} | ||
} | ||
|
||
&__date-marker { | ||
width: calculateRem(12px); | ||
height: calculateRem(12px); | ||
border-radius: 50%; | ||
background: $ibexa-color-primary; | ||
margin-right: calculateRem(16px); | ||
} | ||
|
||
&__items { | ||
margin-left: calculateRem(6px); | ||
padding-left: calculateRem(32px); | ||
border-left: calculateRem(2px) solid $ibexa-color-light; | ||
} | ||
} | ||
|
||
.app-timeline-view-item { | ||
display: flex; | ||
align-items: flex-start; | ||
padding: calculateRem(16px); | ||
margin-bottom: calculateRem(8px); | ||
text-decoration: none; | ||
color: inherit; | ||
background: $ibexa-color-light-300; | ||
border-radius: $ibexa-border-radius; | ||
transition: background-color 0.2s $ibexa-admin-transition; | ||
|
||
&:hover { | ||
background: $ibexa-color-light-400; | ||
} | ||
|
||
&__time { | ||
color: $ibexa-color-dark-400; | ||
margin-right: calculateRem(16px); | ||
min-width: calculateRem(80px); | ||
} | ||
|
||
&__content { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
&__icon { | ||
margin-right: calculateRem(16px); | ||
} | ||
|
||
&__name { | ||
font-weight: $ibexa-font-weight-bold; | ||
margin-bottom: calculateRem(4px); | ||
} | ||
|
||
&__type { | ||
font-size: $ibexa-text-font-size-small; | ||
color: $ibexa-color-dark-400; | ||
display: flex; | ||
align-items: center; | ||
gap: calculateRem(8px); | ||
} | ||
|
||
&__type-name { | ||
line-height: calculateRem(16px); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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.
or override the existing view
?If you pass the existing viewName as a first parameter in registerView(), you will override the existing view with your own. https://github.com/ibexa/admin-ui/blob/main/src/bundle/ui-dev/src/modules/sub-items/services/view.registry.js#L26
I think it is worth mentioning because this was the original customer problem.
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.
Thanks, added in 34c5442