Skip to content

Commit

Permalink
Add counts to tab titles
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Jan 18, 2025
1 parent 40ef1ca commit e6a36cd
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
51 changes: 42 additions & 9 deletions src/components/EditorSidePanel/SidePanel.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Tabs, TabPane } from "@douyinfe/semi-ui";
import { Tab } from "../../data/constants";
import { useLayout, useSelect, useDiagram } from "../../hooks";
import {
useLayout,
useSelect,
useDiagram,
useAreas,
useNotes,
useEnums,
useTypes,
} from "../../hooks";
import RelationshipsTab from "./RelationshipsTab/RelationshipsTab";
import TypesTab from "./TypesTab/TypesTab";
import Issues from "./Issues";
Expand All @@ -17,39 +25,64 @@ import i18n from "../../i18n/i18n";
export default function SidePanel({ width, resize, setResize }) {
const { layout } = useLayout();
const { selectedElement, setSelectedElement } = useSelect();
const { database } = useDiagram();
const { database, tablesCount, relationshipsCount } = useDiagram();
const { areasCount } = useAreas();
const { notesCount } = useNotes();
const { typesCount } = useTypes();
const { enumsCount } = useEnums();
const { t } = useTranslation();

const tabList = useMemo(() => {
const tabs = [
{ tab: t("tables"), itemKey: Tab.TABLES, component: <TablesTab /> },
{
tab: t("relationships"),
tab: `${t("tables")} (${tablesCount})`,
itemKey: Tab.TABLES,
component: <TablesTab />,
},
{
tab: `${t("relationships")} (${relationshipsCount})`,
itemKey: Tab.RELATIONSHIPS,
component: <RelationshipsTab />,
},
{ tab: t("subject_areas"), itemKey: Tab.AREAS, component: <AreasTab /> },
{ tab: t("notes"), itemKey: Tab.NOTES, component: <NotesTab /> },
{
tab: `${t("subject_areas")} (${areasCount})`,
itemKey: Tab.AREAS,
component: <AreasTab />,
},
{
tab: `${t("notes")} (${notesCount})`,
itemKey: Tab.NOTES,
component: <NotesTab />,
},
];

if (databases[database].hasTypes) {
tabs.push({
tab: t("types"),
tab: `${t("types")} (${typesCount})`,
itemKey: Tab.TYPES,
component: <TypesTab />,
});
}

if (databases[database].hasEnums) {
tabs.push({
tab: t("enums"),
tab: `${t("enums")} (${enumsCount})`,
itemKey: Tab.ENUMS,
component: <EnumsTab />,
});
}

return isRtl(i18n.language) ? tabs.reverse() : tabs;
}, [t, database]);
}, [
t,
database,
tablesCount,
relationshipsCount,
areasCount,
typesCount,
enumsCount,
notesCount,
]);

return (
<div className="flex h-full">
Expand Down
9 changes: 8 additions & 1 deletion src/context/AreasContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ export default function AreasContextProvider({ children }) {

return (
<AreasContext.Provider
value={{ areas, setAreas, updateArea, addArea, deleteArea }}
value={{
areas,
setAreas,
updateArea,
addArea,
deleteArea,
areasCount: areas.length,
}}
>
{children}
</AreasContext.Provider>
Expand Down
2 changes: 2 additions & 0 deletions src/context/DiagramContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ export default function DiagramContextProvider({ children }) {
deleteRelationship,
database,
setDatabase,
tablesCount: tables.length,
relationshipsCount: relationships.length,
}}
>
{children}
Expand Down
1 change: 1 addition & 0 deletions src/context/EnumsContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function EnumsContextProvider({ children }) {
addEnum,
updateEnum,
deleteEnum,
enumsCount: enums.length,
}}
>
{children}
Expand Down
9 changes: 8 additions & 1 deletion src/context/NotesContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ export default function NotesContextProvider({ children }) {

return (
<NotesContext.Provider
value={{ notes, setNotes, updateNote, addNote, deleteNote }}
value={{
notes,
setNotes,
updateNote,
addNote,
deleteNote,
notesCount: notes.length,
}}
>
{children}
</NotesContext.Provider>
Expand Down
1 change: 1 addition & 0 deletions src/context/TypesContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default function TypesContextProvider({ children }) {
addType,
updateType,
deleteType,
typesCount: types.length,
}}
>
{children}
Expand Down

0 comments on commit e6a36cd

Please sign in to comment.