Skip to content

Commit

Permalink
fix: react 17 warnings and single tab page
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Oct 21, 2020
1 parent 9abb655 commit bcd2d01
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 41 deletions.
3 changes: 1 addition & 2 deletions core/store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './types';
export * from './state';
export * from './create-pages';
export * from './serialization/load-store';
export * from './serialization/sitemap';
export * from './serialization';
2 changes: 2 additions & 0 deletions core/store/src/serialization/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './load-store';
export * from './sitemap';
4 changes: 3 additions & 1 deletion core/store/src/serialization/transform-controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ const controlShortcuts = (
),
};
}
return control;
}
default:
return control;
}
return control;
};
export const transformControls = (
story: Story,
Expand Down
11 changes: 4 additions & 7 deletions core/store/src/state/context/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ interface NavigationResult {
prevPage?: DocumentPage;
}

const useNavigationLinks = (doc: Document): NavigationResult => {
const docId = doc.title;
const type = doc.type || defDocType;
const useNavigationLinks = (doc?: Document): NavigationResult => {
const docId = doc?.title;
const type = doc?.type || defDocType;
const docs = useDocByType(type);
const store = useStore();
const activeTab = useActiveTab();
Expand Down Expand Up @@ -233,10 +233,7 @@ const useNavigationLinks = (doc: Document): NavigationResult => {
*/
export const useNavigationInfo = (): NavigationResult => {
const doc = useCurrentDocument();
if (doc) {
return useNavigationLinks(doc);
}
return {};
return useNavigationLinks(doc);
};

type UseGetDocumentPath = (
Expand Down
4 changes: 2 additions & 2 deletions ui/app/src/AppContext/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const AppContext: FC<AppContextProps> = ({
activeTab,
}) => {
const query =
typeof location !== 'undefined'
? queryString.parse(location.search)
typeof window !== 'undefined'
? queryString.parse(window.location.search)
: undefined;
const dynStoryId =
query &&
Expand Down
16 changes: 9 additions & 7 deletions ui/app/src/AppContext/mdxComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable react/display-name */
import React from 'react';
import { LinkProps } from 'theme-ui';
import { getRoutePath } from '@component-controls/core';
import {
MarkdownComponentType,
Expand All @@ -8,12 +9,13 @@ import {
} from '@component-controls/components';
import { useStore } from '@component-controls/store';

const AnchorElement = (props: LinkProps) => {
const { href, ...rest } = props;
const isLocal = useIsLocalLink(href);
const store = useStore();
const link = isLocal ? getRoutePath(store, href) : href;
return <Link href={link} {...rest} />;
};
export const mdxComponents: MarkdownComponentType = {
a: props => {
const { href, ...rest } = props;
const isLocal = useIsLocalLink(href);
const store = useStore();
const link = isLocal ? getRoutePath(store, href) : href;
return <Link href={link} {...rest} />;
},
a: AnchorElement,
};
27 changes: 14 additions & 13 deletions ui/app/src/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ export const Header: FC<HeaderProps> = ({ toolbar = {} }) => {
const config = useConfig();
const doc = useCurrentDocument();
const { pages, siteTitle, logo, siteDescription } = config || {};
const LogoLink: FC = ({ children }) => (
<Link
variant="appheader.title"
href={homePath}
aria-label={siteTitle}
sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}
>
{children}
</Link>
);
const LogoImage: FC<{ src: string }> = ({ src }) => (
<Image alt={siteDescription} variant="appheader.logo" src={src} />
);
const leftActions: ActionItems = useMemo(() => {
const LogoLink: FC = ({ children }) => (
<Link
variant="appheader.title"
href={homePath}
aria-label={siteTitle}
sx={{ display: 'flex', flexDirection: 'row', alignItems: 'center' }}
>
{children}
</Link>
);
const LogoImage: FC<{ src: string }> = ({ src }) => (
<Image alt={siteDescription} variant="appheader.logo" src={src} />
);
const actions: ActionItems = [
{
node: logo ? (
Expand Down Expand Up @@ -117,6 +117,7 @@ export const Header: FC<HeaderProps> = ({ toolbar = {} }) => {
store,
homePage,
siteTitle,
siteDescription,
]);

const rightActions: ActionItems = useMemo(() => {
Expand Down
20 changes: 11 additions & 9 deletions ui/app/src/SidebarsPage/SidebarsStoryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ export const SidebarsStoryPage: FC<DocPageProps> = ({ type, doc }) => {
ref={pageRef}
>
{tabs &&
tabs.map((tab, index) => {
const route =
tab.route || (tab.title ? tab.title.toLowerCase() : '');
return (
<TabPanel key={`panel_${route}`}>
{tabIndex === index ? renderTab(tab) : null}
</TabPanel>
);
})}
(tabs.length === 1
? renderTab(tabs[0])
: tabs.map((tab, index) => {
const route =
tab.route || (tab.title ? tab.title.toLowerCase() : '');
return (
<TabPanel key={`panel_${route}`}>
{tabIndex === index ? renderTab(tab) : null}
</TabPanel>
);
}))}
</PageContainer>
</Tabs>
</Box>
Expand Down

0 comments on commit bcd2d01

Please sign in to comment.