Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
feat: add toggle for media navigation link (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman authored Dec 21, 2023
1 parent c0c53d9 commit b53f8b7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
20 changes: 12 additions & 8 deletions packages/core/src/components/navbar/SidebarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getAdditionalLinks } from '@staticcms/core/lib/registry';
import classNames from '@staticcms/core/lib/util/classNames.util';
import { selectCollections } from '@staticcms/core/reducers/selectors/collections';
import {
selectIsMediaLinkEnabled,
selectIsSearchEnabled,
selectUseWorkflow,
} from '@staticcms/core/reducers/selectors/config';
Expand All @@ -33,6 +34,7 @@ const SidebarContent: FC<SidebarContentProps> = ({ isMobile = false }) => {

const navigate = useNavigate();
const isSearchEnabled = useAppSelector(selectIsSearchEnabled);
const isMediaLinkEnabled = useAppSelector(selectIsMediaLinkEnabled);
const collections = useAppSelector(selectCollections);
const useWorkflow = useAppSelector(selectUseWorkflow);

Expand Down Expand Up @@ -151,14 +153,16 @@ const SidebarContent: FC<SidebarContentProps> = ({ isMobile = false }) => {
) : null}
{collectionLinks}
{links}
<NavLink
key="Media"
to="/media"
icon={<PhotoIcon className={sidebarClasses['icon']} />}
data-testid={`${isMobile ? 'mobile-nav' : 'sidebar-nav'}-Media`}
>
{t('app.header.media')}
</NavLink>
{isMediaLinkEnabled ? (
<NavLink
key="Media"
to="/media"
icon={<PhotoIcon className={sidebarClasses['icon']} />}
data-testid={`${isMobile ? 'mobile-nav' : 'sidebar-nav'}-Media`}
>
{t('app.header.media')}
</NavLink>
) : null}
</ul>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/constants/configSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ function getConfigSchema() {
media_library: {
type: 'object',
properties: {
display_in_navigation: { type: 'boolean' },
max_file_size: { type: 'number' },
folder_support: { type: 'boolean' },
},
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ export interface MediaLibraryConfig {
folder_support?: boolean;
}

export interface RootMediaLibraryConfig extends MediaLibraryConfig {
display_in_navigation?: boolean;
}

export type BackendType =
| 'git-gateway'
| 'github'
Expand Down Expand Up @@ -1046,7 +1050,7 @@ export interface Config<EF extends BaseField = UnknownField> {
media_folder?: string;
public_folder?: string;
media_folder_relative?: boolean;
media_library?: MediaLibraryConfig;
media_library?: RootMediaLibraryConfig;
publish_mode?: Workflow;
slug?: Slug;
i18n?: I18nInfo;
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/reducers/selectors/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { createSelector } from '@reduxjs/toolkit';

import { EDITORIAL_WORKFLOW } from '@staticcms/core/constants/publishModes';

import type { Workflow } from '@staticcms/core/constants/publishModes';
import type { ConfigWithDefaults } from '@staticcms/core';
import type { Workflow } from '@staticcms/core/constants/publishModes';
import type { RootState } from '@staticcms/core/store';

export function selectLocale(config?: ConfigWithDefaults) {
Expand All @@ -28,6 +28,17 @@ export const selectIsSearchEnabled = createSelector(
},
);

export function selectMediaLinkEnabled(state: RootState) {
return state.config.config?.media_library?.display_in_navigation;
}

export const selectIsMediaLinkEnabled = createSelector(
[selectMediaLinkEnabled],
(display_in_navigation: boolean | undefined) => {
return display_in_navigation !== false;
},
);

export function selectDisplayUrl(state: RootState) {
return state.config.config?.display_url;
}
Expand Down
9 changes: 5 additions & 4 deletions packages/docs/content/docs/configuration-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ The `media_library` settings allows customization of the media library.

### Options

| Name | Type | Default | Description |
| -------------- | ------- | -------- | -------------------------------------------------------------------------------------- |
| max_file_size | number | `512000` | _Optional_. The max size, in bytes, of files that can be uploaded to the media library |
| folder_support | boolean | `false` | _Optional_. Enables directory navigation and folder creation in your media library |
| Name | Type | Default | Description |
| --------------------- | ------- | -------- | -------------------------------------------------------------------------------------- |
| max_file_size | number | `512000` | _Optional_. The max size, in bytes, of files that can be uploaded to the media library |
| folder_support | boolean | `false` | _Optional_. Enables directory navigation and folder creation in your media library |
| display_in_navigation | boolean | `true` | _Optional_. Displays the "Media" link in the main navigation |

### Example

Expand Down

0 comments on commit b53f8b7

Please sign in to comment.