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

Commit

Permalink
fix: use file name in resizable panel if available
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Nov 16, 2023
1 parent c3c4da8 commit 350835d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/components/entry-editor/EditorInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ const EditorInterface: FC<EditorInterfaceProps> = ({
setSelectedLocale(locale);
}, []);

const file = getFileFromSlug(collection, entry.slug);

const { livePreviewUrlTemplate, showPreviewToggle, previewInFrame, editorSize } = useMemo(() => {
let livePreviewUrlTemplate =
typeof collection.editor?.live_preview === 'string' ? collection.editor.live_preview : false;
Expand All @@ -261,8 +263,6 @@ const EditorInterface: FC<EditorInterfaceProps> = ({
}

if ('files' in collection) {
const file = getFileFromSlug(collection, entry.slug);

if (file?.editor) {
if (typeof file.editor.live_preview === 'string') {
livePreviewUrlTemplate = file.editor.live_preview;
Expand Down Expand Up @@ -417,8 +417,8 @@ const EditorInterface: FC<EditorInterfaceProps> = ({
<>
{!isSmallScreen ? (
<PanelGroup
key={`editor-with-preview-${editorSize}`}
autoSaveId={`editor-with-preview-${collection.name}`}
key="editor-with-preview"
autoSaveId={`editor-with-preview-${collection.name}${file ? `-${file.name}` : ''}`}
direction="horizontal"
units={editorSize === EDITOR_SIZE_COMPACT ? 'pixels' : 'percentages'}
className={classNames(
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/lib/util/collection.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ import { keyToPathArray } from '../widgets/stringTemplate';
import { selectField } from './field.util';
import { selectMediaFolder } from './media.util';

import type { InferrableField } from '@staticcms/core/constants/fieldInference';
import type {
BaseField,
CollectionWithDefaults,
Collection,
CollectionFile,
CollectionFileWithDefaults,
CollectionWithDefaults,
CollectionsWithDefaults,
Config,
ConfigWithDefaults,
Entry,
Field,
FilesCollection,
InferredField,
ObjectField,
SortableField,
} from '@staticcms/core';
import type { InferrableField } from '@staticcms/core/constants/fieldInference';

export function fileForEntry<EF extends BaseField>(
collection: CollectionWithDefaults<EF> | undefined | null,
Expand Down Expand Up @@ -282,9 +283,13 @@ function getFieldsWithMediaFolders<EF extends BaseField>(fields: Field<EF>[]) {
}

export function getFileFromSlug<EF extends BaseField>(
collection: FilesCollection<EF>,
collection: Collection<EF>,
slug: string,
) {
): CollectionFile<EF> | undefined {
if (!('files' in collection)) {
return undefined;
}

return collection.files?.find(f => f.name === slug);
}

Expand Down

0 comments on commit 350835d

Please sign in to comment.