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

Commit b53f8b7

Browse files
authored
feat: add toggle for media navigation link (#1007)
1 parent c0c53d9 commit b53f8b7

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

packages/core/src/components/navbar/SidebarContent.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getAdditionalLinks } from '@staticcms/core/lib/registry';
99
import classNames from '@staticcms/core/lib/util/classNames.util';
1010
import { selectCollections } from '@staticcms/core/reducers/selectors/collections';
1111
import {
12+
selectIsMediaLinkEnabled,
1213
selectIsSearchEnabled,
1314
selectUseWorkflow,
1415
} from '@staticcms/core/reducers/selectors/config';
@@ -33,6 +34,7 @@ const SidebarContent: FC<SidebarContentProps> = ({ isMobile = false }) => {
3334

3435
const navigate = useNavigate();
3536
const isSearchEnabled = useAppSelector(selectIsSearchEnabled);
37+
const isMediaLinkEnabled = useAppSelector(selectIsMediaLinkEnabled);
3638
const collections = useAppSelector(selectCollections);
3739
const useWorkflow = useAppSelector(selectUseWorkflow);
3840

@@ -151,14 +153,16 @@ const SidebarContent: FC<SidebarContentProps> = ({ isMobile = false }) => {
151153
) : null}
152154
{collectionLinks}
153155
{links}
154-
<NavLink
155-
key="Media"
156-
to="/media"
157-
icon={<PhotoIcon className={sidebarClasses['icon']} />}
158-
data-testid={`${isMobile ? 'mobile-nav' : 'sidebar-nav'}-Media`}
159-
>
160-
{t('app.header.media')}
161-
</NavLink>
156+
{isMediaLinkEnabled ? (
157+
<NavLink
158+
key="Media"
159+
to="/media"
160+
icon={<PhotoIcon className={sidebarClasses['icon']} />}
161+
data-testid={`${isMobile ? 'mobile-nav' : 'sidebar-nav'}-Media`}
162+
>
163+
{t('app.header.media')}
164+
</NavLink>
165+
) : null}
162166
</ul>
163167
</div>
164168
);

packages/core/src/constants/configSchema.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ function getConfigSchema() {
494494
media_library: {
495495
type: 'object',
496496
properties: {
497+
display_in_navigation: { type: 'boolean' },
497498
max_file_size: { type: 'number' },
498499
folder_support: { type: 'boolean' },
499500
},

packages/core/src/interface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ export interface MediaLibraryConfig {
674674
folder_support?: boolean;
675675
}
676676

677+
export interface RootMediaLibraryConfig extends MediaLibraryConfig {
678+
display_in_navigation?: boolean;
679+
}
680+
677681
export type BackendType =
678682
| 'git-gateway'
679683
| 'github'
@@ -1046,7 +1050,7 @@ export interface Config<EF extends BaseField = UnknownField> {
10461050
media_folder?: string;
10471051
public_folder?: string;
10481052
media_folder_relative?: boolean;
1049-
media_library?: MediaLibraryConfig;
1053+
media_library?: RootMediaLibraryConfig;
10501054
publish_mode?: Workflow;
10511055
slug?: Slug;
10521056
i18n?: I18nInfo;

packages/core/src/reducers/selectors/config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { createSelector } from '@reduxjs/toolkit';
22

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

5-
import type { Workflow } from '@staticcms/core/constants/publishModes';
65
import type { ConfigWithDefaults } from '@staticcms/core';
6+
import type { Workflow } from '@staticcms/core/constants/publishModes';
77
import type { RootState } from '@staticcms/core/store';
88

99
export function selectLocale(config?: ConfigWithDefaults) {
@@ -28,6 +28,17 @@ export const selectIsSearchEnabled = createSelector(
2828
},
2929
);
3030

31+
export function selectMediaLinkEnabled(state: RootState) {
32+
return state.config.config?.media_library?.display_in_navigation;
33+
}
34+
35+
export const selectIsMediaLinkEnabled = createSelector(
36+
[selectMediaLinkEnabled],
37+
(display_in_navigation: boolean | undefined) => {
38+
return display_in_navigation !== false;
39+
},
40+
);
41+
3142
export function selectDisplayUrl(state: RootState) {
3243
return state.config.config?.display_url;
3344
}

packages/docs/content/docs/configuration-options.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ The `media_library` settings allows customization of the media library.
138138

139139
### Options
140140

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

146147
### Example
147148

0 commit comments

Comments
 (0)