Skip to content

Commit

Permalink
chore: Release cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Dec 25, 2023
1 parent d5ec4cc commit 3dbafbb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@diplodoc/client",
"version": "2.0.0-beta-1",
"version": "1.2.0",
"description": "",
"main": "./build/server/app.js",
"scripts": {
Expand Down
35 changes: 22 additions & 13 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, {ReactElement, useEffect} from 'react';

import {
NavigationData,
NavigationDropdownItem,
NavigationItemModel,
PageConstructor,
PageConstructorProvider,
} from '@gravity-ui/page-constructor';
Expand Down Expand Up @@ -55,6 +57,24 @@ function Page(props: DocInnerProps) {
);
}

function isDropdownItem(item: NavigationItemModel): item is NavigationDropdownItem {
return Array.isArray((item as NavigationDropdownItem).items);
}

function rebaseNavItem<T extends NavigationItemModel>(item: T) {
const result: T = {...item};

if (isDropdownItem(item)) {
(result as NavigationDropdownItem).items = item.items.map(rebaseNavItem);
}

if (item.url !== undefined) {
result.url = item.url.replace(/^\/?/, '/');
}

return result;
}

type TocData = DocPageData['toc'] & {
navigation?: NavigationData;
};
Expand Down Expand Up @@ -82,17 +102,6 @@ export function App(props: DocInnerProps): ReactElement {
onChangeFullScreen,
};

const rebase = (item: any) => {
if (item.type !== 'link') {
return item;
}

return {
...item,
url: item.url.replace(/^\/?/, '/'),
};
};

useEffect(() => {
updateRootClassName({
theme,
Expand Down Expand Up @@ -142,8 +151,8 @@ export function App(props: DocInnerProps): ReactElement {
? {
header: {
withBorder: true,
leftItems: leftItems.map(rebase),
rightItems: rightItems.map(rebase),
leftItems: leftItems.map(rebaseNavItem),
rightItems: rightItems.map(rebaseNavItem),
},
logo,
}
Expand Down

0 comments on commit 3dbafbb

Please sign in to comment.