Skip to content
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
20 changes: 15 additions & 5 deletions commit/commit/doctype/commit_docs/commit_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CommitDocs(Document):

def after_insert(self):
def before_insert(self):
'''
Validate the Document
# 1. Check if the Route is Unique
Expand Down Expand Up @@ -71,8 +71,11 @@ def get_commit_docs_details(route:str):
# Get the Commit Docs Document
commit_docs = frappe.get_doc('Commit Docs',{'route':route}).as_dict()

# Maintain route_map from the sidebar where key is the route and value is the name of the page
route_map = {}

# Get the Sidebar Items
sidebar_items = get_sidebar_items(commit_docs.sidebar)
sidebar_items, route_map = get_sidebar_items(commit_docs.sidebar,route_map)

# Get the Footer Items
footer_items = get_footer_items(commit_docs.footer)
Expand All @@ -89,7 +92,8 @@ def get_commit_docs_details(route:str):
'commit_docs': commit_docs,
'sidebar_items': sidebar_items,
'footer_items': footer_items,
'navbar_items': navbar_items
'navbar_items': navbar_items,
'route_map': route_map
}

else:
Expand Down Expand Up @@ -183,7 +187,7 @@ def get_navbar_items(navbar):

return navbar_obj

def get_sidebar_items(sidebar):
def get_sidebar_items(sidebar, route_map):
'''
Get the Sidebar Items with support for nested Group Pages.
'''
Expand Down Expand Up @@ -233,6 +237,8 @@ def get_group_items(commit_docs_page):
'icon': group_commit_docs_page.icon,
'parent_name': commit_docs_page.name
})
# Add route to route_map
route_map[group_commit_docs_page.route] = group_commit_docs_page.name
return group_items

sidebar_obj = {}
Expand Down Expand Up @@ -272,4 +278,8 @@ def get_group_items(commit_docs_page):
else:
sidebar_obj[sidebar_item.parent_label].append(sidebar_entry)

return sidebar_obj
# Add route to route_map if it's not a group page
if not is_group_page:
route_map[commit_docs_page.route] = commit_docs_page.name

return sidebar_obj, route_map
5 changes: 3 additions & 2 deletions commit/commit/doctype/commit_docs_page/commit_docs_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"depends_on": "eval:doc.is_group_page == 0",
"fieldname": "content",
"fieldtype": "Markdown Editor",
"ignore_xss_filter": 1,
"label": "Content"
},
{
Expand All @@ -63,7 +64,7 @@
"label": "Badge"
},
{
"description": "Add Tailwind colours like red-500, green-500 etc.",
"description": "Add Tailwind colours like red, green, blue, yellow, purple, pink, indigo, cyan, teal, lime, orange, gray etc.",
"fieldname": "badge_color",
"fieldtype": "Data",
"label": "Badge Color"
Expand Down Expand Up @@ -105,7 +106,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-11-09 15:34:23.907329",
"modified": "2024-11-15 15:20:42.503563",
"modified_by": "Administrator",
"module": "commit",
"name": "Commit Docs Page",
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/features/projects/Projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AddMenuButton } from "./AddMenuButton";
import { APIExplorer } from "./APIExplorer";
import ProjectCard from "./Projects/ProjectCard";
import { ViewERDButton } from "./ViewERDButton";
import { ErrorBanner } from "@/components/common/ErrorBanner/ErrorBanner";


export interface ProjectWithBranch extends CommitProject {
Expand Down Expand Up @@ -37,7 +38,7 @@ export const Projects = () => {
);

if (error) {
return <div>Error</div>;
return <ErrorBanner error={error} />;
}

if (isLoading) {
Expand Down
26 changes: 24 additions & 2 deletions dashboard/src/pages/features/docs/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import DynamicIcon from "@/components/common/DynamicIconImport/IconComponent";
import { Badge } from "@/components/ui/badge";
import { useState } from "react";
import { MdKeyboardArrowDown, MdKeyboardArrowRight } from "react-icons/md";
import classNames from "classnames";
import { cn } from "@/lib/utils";

export const Sidebar = ({ commit_docs, sidebar_items, selectedEndpoint, setSelectedEndpoint }: { commit_docs: Omit<CommitDocs, 'sidebar' | 'navbar_items' | 'footer'>, sidebar_items: Record<string, DocsSidebarItem[]>, selectedEndpoint: string, setSelectedEndpoint: (selectedEndpoint: string) => void }) => {

Expand Down Expand Up @@ -61,6 +63,26 @@ const SidebarTitle = ({ item, selectedEndpoint, setSelectedEndpoint, className,

const isSelected = item.route === selectedEndpoint;

const badgeClass = classNames({
'text-[10px] px-1 py-0': true,
'bg-blue-500': item.badge_color === 'blue',
'bg-red-500': item.badge_color === 'red',
'bg-green-500': item.badge_color === 'green',
'bg-yellow-500': item.badge_color === 'yellow',
'bg-purple-500': item.badge_color === 'purple',
'bg-pink-500': item.badge_color === 'pink',
'bg-indigo-500': item.badge_color === 'indigo',
'bg-cyan-500': item.badge_color === 'cyan',
'bg-teal-500': item.badge_color === 'teal',
'bg-lime-500': item.badge_color === 'lime',
'bg-orange-500': item.badge_color === 'orange',
'bg-blue-gray-500': item.badge_color === 'blue-gray',
'bg-gray-500': item.badge_color === 'gray',
'bg-true-gray-500': item.badge_color === 'true-gray',
'bg-warm-gray-500': item.badge_color === 'warm-gray',
'bg-cool-gray-500': item.badge_color === 'cool-gray',
})

return (
<div
className={`flex items-center px-4 py-2 gap-2 cursor-pointer text-sm rounded-md transition-colors
Expand All @@ -71,8 +93,8 @@ const SidebarTitle = ({ item, selectedEndpoint, setSelectedEndpoint, className,
<div className="flex justify-between items-center w-full">
<div className="flex flex-row gap-2">
{item.icon && <DynamicIcon icon={item.icon} size="18px" className={isSelected ? "text-blue-800" : "text-gray-500"} />}
{item.badge && <Badge className={`${item.badge_color ? `bg-${item.badge_color} hover:bg-${item.badge_color}` : 'bg-blue-500 hover:bg-blue-500'} text-[10px] px-1 py-0 `}
>{item.badge}</Badge>}
{item.badge && <Badge
className={cn(badgeClass, 'text-[10px] px-1 py-0')}>{item.badge}</Badge>}
<div className="">
{item.title}
</div>
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/pages/features/docs/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export interface Docs {
sidebar_items: Record<string, DocsSidebarItem[]>
navbar_items: Record<string, DocsNavbarItem>
footer_items: Record<string, DocsFooterItem[]>
route_map: Record<string, string>
}
2 changes: 1 addition & 1 deletion dashboard/src/types/commit/CommitDocsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface CommitDocsPage{
icon?: string
/** Badge : Data - This is badge field, eg: GET , POST etc. */
badge?: string
/** Badge Color : Data - Add Tailwind colours like red-500, green-500 etc. */
/** Badge Color : Data - Add Tailwind colours like red, green, blue, yellow, purple, pink, indigo, cyan, teal, lime, orange, gray etc. */
badge_color?: string
/** Is Group Page : Check - When enabled, this page can hold and display nested sub-pages, creating a structured hierarchy in the sidebar. */
is_group_page?: 0 | 1
Expand Down