OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Start documentation of TreeView
Henriette Dargead4d7910dc00
diff --git a/app/assets/images/lookbook/tree_view_anatomy.png b/app/assets/images/lookbook/tree_view_anatomy.pngnew file mode 100644index 00000000000..67820b23f38Binary files /dev/null and b/app/assets/images/lookbook/tree_view_anatomy.png differdiff --git a/lookbook/docs/components/tree-view.md.erb b/lookbook/docs/components/tree-view.md.erbnew file mode 100644index 00000000000..9f5788af742--- /dev/null+++ b/lookbook/docs/components/tree-view.md.erb@@ -0,0 +1,69 @@+This component is currently an own implementation for OpenProject. It follows as strict as possible the requirements that Primer has set up for their [(react) TreeView](https://primer.style/product/components/tree-view/).++## Overview++<%= embed OpenProject::Common::TreeViewPreview, :default %>++## Anatomy++ %>)++Basically, we follow Primer's specification of a TreeView:++1. Parent node: Expands/collapses to show/hide child nodes.+2. End node: A node with no children (internally called "leaf")+3. Chevron: Expands/collapses a parent node and indicates expanded/collapsed state.+4. Nesting level indicator lines: Each line represents a level of nesting depth+5. Leading action (optional): An IconButton to allow interaction with the node besides activating or expanding.+6. Leading visual (optional): A visual cue for additional context+7. Node label: The text label for the node+8. Trailing visual (optional): Same as a leading visual, but at the end++### Multi-select++In addition to Primer's guidelines, we introduced an option called `select_variant` which can either be++* `none` (default)+* `multiple`: Whe `multiple` is chosen, there is a checkbox rendered between the leading action and the leading visual.++Further, a `selection_strategy` can be configured. This influences the behaviour when selecting a parent node.++* `descendants` (default): Selecting a parent, will automatically select all children. Deselecting the children, will leave the parent in a so called "mixed" state+* `self`: Selecting a parent, does not affect the children++<%= embed OpenProject::Common::TreeViewPreview, :multi_select, panels: %i[params] %>++### Loading strategies++We support two loading strategies:++* static (default): All items are loaded when the component is rendered+* dynamic: Items are loaded from the server as soon as the parents are expanded++For more examples have a look [here](../../inspect/primer/open_project/file_tree_view/loading_skeleton).++### FileTreeView++There is a special component called `FileTreeView` which is a pre-configured `TreeView` for the use case of showing a file hierarchy. For detailed examples have a look [here](../../inspect/primer/open_project/file_tree_view/default).++<%= embed OpenProject::Common::TreeViewPreview, :file_tree, panels: %i[params source] %>++## Best practices++**Do**++**Don't**++## Used in++* the details view of a hierarchy CustomField++## Examples++For detailed examples have a look at the other [preview examples](../../inspect/primer/open_project/tree_view/playground) of the component.++Please check out also the [playground for the individual items](../../inspect/primer/open_project/tree_view/leaf_node_playground).++This is an exemplary playground of the `Primer::OpenProject::TreeView`.++<%= embed OpenProject::Common::TreeViewPreview, :default, panels: %i[params source] %>diff --git a/lookbook/previews/open_project/common/tree_view_preview.rb b/lookbook/previews/open_project/common/tree_view_preview.rbnew file mode 100644index 00000000000..01c68e141a4--- /dev/null+++ b/lookbook/previews/open_project/common/tree_view_preview.rb@@ -0,0 +1,103 @@+# frozen_string_literal: true++module OpenProject+ module Common+ # @hidden+ class TreeViewPreview < Lookbook::Preview+ # @label Default+ # @display min_height 350px+ # @param expanded [Boolean] toggle+ # @param select_variant [Symbol] select [multiple, none]+ # @param select_strategy [Symbol] select [self, descendants]+ # @param leading_icon [Boolean] toggle+ # @param trailing_icon [Boolean] toggle+ def default(expanded: true, select_variant: :none, select_strategy: :descendants, leading_icon: true, trailing_icon: true)+ render(Primer::OpenProject::TreeView.new) do |component|+ component.with_sub_tree(label: "OpenProject",+ expanded: expanded,+ select_variant: select_variant,+ select_strategy: select_strategy) do |sub_tree|+ if leading_icon+ sub_tree.with_leading_visual_icons(label: "Foobar") do |icons|+ icons.with_expanded_icon(icon: :heart, color: :accent)+ icons.with_collapsed_icon(icon: :"heart-fill", color: :accent)+ end+ end++ sub_tree.with_leaf(label: "Website", select_variant: select_variant)++ sub_tree.with_sub_tree(label: "OpenProject GmbH",+ expanded: expanded,+ elect_variant: select_variant,+ select_strategy: select_strategy) do |sub_tree2|+ sub_tree2.with_leaf(label: "HR", select_variant: select_variant)+ sub_tree2.with_leaf(label: "Development", current: true, select_variant: select_variant)++ if trailing_icon+ sub_tree2.with_trailing_visual_icon(icon: :"feed-heart")+ end+ end++ sub_tree.with_leaf(label: "Freedom edition", select_variant: select_variant)++ sub_tree.with_leaf(label: "Documentation", select_variant: select_variant)+ end++ component.with_leaf(label: "External project A", select_variant: select_variant)++ component.with_leaf(label: "External project B", select_variant: select_variant)+ end+ end++ # @label Multi+ # @display min_height 300px+ # @param expanded [Boolean] toggle+ # @param select_variant [Symbol] select [multiple, none]+ # @param select_strategy [Symbol] select [self, descendants]+ def multi_select(expanded: true, select_variant: :multiple, select_strategy: :descendants)+ render(Primer::OpenProject::TreeView.new) do |component|+ component.with_sub_tree(label: "Europe",+ expanded: expanded,+ select_variant: select_variant,+ select_strategy: select_strategy) do |sub_tree|+ sub_tree.with_sub_tree(label: "Germany",+ expanded: expanded,+ select_variant: select_variant,+ select_strategy: select_strategy) do |tree|+ tree.with_leaf(label: "Potsdam", current: true, select_variant: select_variant)+ tree.with_leaf(label: "Berlin", select_variant: select_variant)+ tree.with_leaf(label: "Frankfurt (Main)", select_variant: select_variant)+ tree.with_leaf(label: "München", select_variant: select_variant)+ end++ sub_tree.with_leaf(label: "France", select_variant: select_variant)++ sub_tree.with_leaf(label: "Spain", select_variant: select_variant)+ end++ component.with_leaf(label: "North America", select_variant: select_variant)++ component.with_leaf(label: "Asia", select_variant: select_variant)+ end+ end++ # @label FileTree+ # @display min_height 200px+ # @param expanded [Boolean] toggle+ def file_tree(expanded: true)+ render(Primer::OpenProject::FileTreeView.new) do |component|+ component.with_directory(label: "src", expanded: expanded) do |dir|+ dir.with_trailing_visual_icon(icon: :"diff-modified")++ dir.with_file(label: "button.rb")+ dir.with_file(label: "icon_button.rb", current: true)++ dir.with_directory(label: "tree_view", expanded: expanded) do |subdir|+ subdir.with_file(label: "sub_tree.rb")+ end+ end+ end+ end+ end+ end+end