Skip to content

Commit

Permalink
Merge pull request #75 from thim81/hide-edit-link
Browse files Browse the repository at this point in the history
  • Loading branch information
boyney123 committed Jan 18, 2022
2 parents 5113401 + 407d9e0 commit 4f4ef62
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-cats-relax.md
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

feat: optional editUrl config
34 changes: 19 additions & 15 deletions packages/eventcatalog/components/ContentView.tsx
Expand Up @@ -75,16 +75,18 @@ export default function ContentView({
)}
</div>
<div className="mt-4 flex space-x-3 md:mt-0">
<a
href={editUrl}
target="_blank"
type="button"
className="hidden md:inline-flex h-10 justify-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-900"
rel="noreferrer"
>
<PencilIcon className="-ml-1 mr-2 h-5 w-5 text-gray-400" aria-hidden="true" />
<span>Edit</span>
</a>
{editUrl && (
<a
href={editUrl}
target="_blank"
type="button"
className="hidden md:inline-flex h-10 justify-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-900"
rel="noreferrer"
>
<PencilIcon className="-ml-1 mr-2 h-5 w-5 text-gray-400" aria-hidden="true" />
<span>Edit</span>
</a>
)}
</div>
</div>
<div className="py-3 xl:pt-6 xl:pb-0">
Expand All @@ -101,11 +103,13 @@ export default function ContentView({
</div>
</div>
</div>
<div className="flex justify-between mt-10">
<a href={editUrl} target="_blank" className="flex text-gray-400" rel="noreferrer">
<PencilIcon className="top-1 mr-2 relative h-4 w-4 text-gray-400" aria-hidden="true" />
<span>Edit this page</span>
</a>
<div className={`flex mt-10 ${editUrl ? 'justify-between' : 'justify-end'}`}>
{editUrl && (
<a href={editUrl} target="_blank" className="flex text-gray-400" rel="noreferrer">
<PencilIcon className="top-1 mr-2 relative h-4 w-4 text-gray-400" aria-hidden="true" />
<span>Edit this page</span>
</a>
)}
<span className="italic text-xs mt-2">Last updated on {lastModifiedDate}</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/eventcatalog/hooks/EventCatalog.tsx
Expand Up @@ -26,10 +26,10 @@ export const useUser = () => {

export const useUrl = () => {
const config = useConfig();

const getEditUrl = (url: string) => path.join(config.editUrl, url);

return {
getEditUrl,
hasEditUrl: !!config.editUrl,
};
};
5 changes: 2 additions & 3 deletions packages/eventcatalog/pages/events/[name].tsx
Expand Up @@ -67,7 +67,7 @@ export const getComponents = ({ event, schema, examples }: any) => ({

export default function Events(props: EventsPageProps) {
const { event, markdown, loadedVersion, notFound } = props;
const { getEditUrl } = useUrl();
const { getEditUrl, hasEditUrl } = useUrl();

if (notFound) return <NotFound type="event" name={event.name} editUrl={editUrl} />;

Expand All @@ -89,9 +89,8 @@ export default function Events(props: EventsPageProps) {
</title>
</Head>
<ContentView
// {...props}
title={name}
editUrl={getEditUrl(`/events/${name}/index.md`)}
editUrl={hasEditUrl ? getEditUrl(`/events/${name}/index.md`) : ''}
subtitle={summary}
draft={draft}
lastModifiedDate={lastModifiedDate}
Expand Down
4 changes: 2 additions & 2 deletions packages/eventcatalog/pages/services/[name].tsx
Expand Up @@ -37,7 +37,7 @@ const getComponents = (service) => ({

export default function Services(props: ServicesPageProps) {
const { service, markdown, notFound } = props;
const { getEditUrl } = useUrl();
const { getEditUrl, hasEditUrl } = useUrl();

if (notFound) return <NotFound type="service" name={service.name} editUrl={editUrl} />;

Expand All @@ -58,7 +58,7 @@ export default function Services(props: ServicesPageProps) {
</Head>
<ContentView
title={name}
editUrl={getEditUrl(`/services/${name}/index.md`)}
editUrl={hasEditUrl ? getEditUrl(`/services/${name}/index.md`) : ''}
subtitle={summary}
draft={draft}
lastModifiedDate={lastModifiedDate}
Expand Down
5 changes: 3 additions & 2 deletions website/docs/api/eventcatalog.config.js.md
Expand Up @@ -37,6 +37,9 @@ module.exports = {
};
```


## Optional fields {#optional-fields}

### `editUrl` {#editUrl}

- Type: `string`
Expand All @@ -49,8 +52,6 @@ module.exports = {
};
```

## Optional fields {#optional-fields}

### `tagline` {#tagline}

Tagline that is shown on your homepage.
Expand Down

0 comments on commit 4f4ef62

Please sign in to comment.