chore: merge with master
This commit is contained in:
@@ -44,7 +44,7 @@ const Autosave: React.FC<Props> = ({ collection, global, id, publishedDocUpdated
|
||||
modifiedRef.current = modified;
|
||||
|
||||
const createCollectionDoc = useCallback(async () => {
|
||||
const res = await fetch(`${serverURL}${api}/${collection.slug}?locale=${locale}&fallback-locale=null&depth=0&draft=true`, {
|
||||
const res = await fetch(`${serverURL}${api}/${collection.slug}?locale=${locale}&fallback-locale=null&depth=0&draft=true&autosave=true`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
@@ -95,13 +95,13 @@ const Autosave: React.FC<Props> = ({ collection, global, id, publishedDocUpdated
|
||||
}
|
||||
|
||||
if (url) {
|
||||
const body = {
|
||||
...reduceFieldsToValues(fieldRef.current, true),
|
||||
_status: 'draft',
|
||||
};
|
||||
|
||||
setTimeout(async () => {
|
||||
if (modifiedRef.current) {
|
||||
const body = {
|
||||
...reduceFieldsToValues(fieldRef.current, true),
|
||||
_status: 'draft',
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
credentials: 'include',
|
||||
|
||||
@@ -4,9 +4,6 @@ import { useConfig } from '../../utilities/Config';
|
||||
import Button from '../Button';
|
||||
import { Props } from './types';
|
||||
import { useDocumentInfo } from '../../utilities/DocumentInfo';
|
||||
import { SanitizedCollectionConfig } from '../../../../collections/config/types';
|
||||
import { SanitizedGlobalConfig } from '../../../../globals/config/types';
|
||||
import { shouldIncrementVersionCount } from '../../../../versions/shouldIncrementVersionCount';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
@@ -14,35 +11,20 @@ const baseClass = 'versions-count';
|
||||
|
||||
const VersionsCount: React.FC<Props> = ({ collection, global, id }) => {
|
||||
const { routes: { admin } } = useConfig();
|
||||
const { versions, publishedDoc, unpublishedVersions } = useDocumentInfo();
|
||||
const { versions } = useDocumentInfo();
|
||||
const { t } = useTranslation('version');
|
||||
|
||||
// Doc status could come from three places:
|
||||
// 1. the newest unpublished version (a draft)
|
||||
// 2. the published doc's status, in the event that the doc is published and there are no newer versions
|
||||
// 3. if there is no published doc, it's a draft
|
||||
const docStatus = unpublishedVersions?.docs?.[0]?.version?._status || publishedDoc?._status || 'draft';
|
||||
|
||||
let versionsURL: string;
|
||||
let entity: SanitizedCollectionConfig | SanitizedGlobalConfig;
|
||||
|
||||
if (collection) {
|
||||
versionsURL = `${admin}/collections/${collection.slug}/${id}/versions`;
|
||||
entity = collection;
|
||||
}
|
||||
|
||||
if (global) {
|
||||
versionsURL = `${admin}/globals/${global.slug}/versions`;
|
||||
entity = global;
|
||||
}
|
||||
|
||||
let initialVersionsCount = 0;
|
||||
|
||||
if (shouldIncrementVersionCount({ entity, versions, docStatus })) {
|
||||
initialVersionsCount = 1;
|
||||
}
|
||||
|
||||
const versionCount = (versions?.totalDocs || 0) + initialVersionsCount;
|
||||
const versionCount = versions?.totalDocs || 0;
|
||||
|
||||
return (
|
||||
<div className={baseClass}>
|
||||
|
||||
@@ -191,7 +191,7 @@ export const addFieldStatePromise = async ({
|
||||
id,
|
||||
operation,
|
||||
fields: field.fields,
|
||||
data: data?.[field.name],
|
||||
data: data?.[field.name] || {},
|
||||
fullData,
|
||||
parentPassesCondition: passesCondition,
|
||||
path: `${path}${field.name}.`,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useRouteMatch } from 'react-router-dom';
|
||||
import format from 'date-fns/format';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useConfig } from '../../utilities/Config';
|
||||
import usePayloadAPI from '../../../hooks/usePayloadAPI';
|
||||
import Eyebrow from '../../elements/Eyebrow';
|
||||
import { LoadingOverlayToggle } from '../../elements/Loading';
|
||||
import { useStepNav } from '../../elements/StepNav';
|
||||
import { StepNavItem } from '../../elements/StepNav/types';
|
||||
import Meta from '../../utilities/Meta';
|
||||
@@ -15,20 +15,15 @@ import Table from '../../elements/Table';
|
||||
import Paginator from '../../elements/Paginator';
|
||||
import PerPage from '../../elements/PerPage';
|
||||
import { useSearchParams } from '../../utilities/SearchParams';
|
||||
import { Banner, Pill } from '../..';
|
||||
import { SanitizedCollectionConfig } from '../../../../collections/config/types';
|
||||
import { SanitizedGlobalConfig } from '../../../../globals/config/types';
|
||||
import { shouldIncrementVersionCount } from '../../../../versions/shouldIncrementVersionCount';
|
||||
import { Gutter } from '../../elements/Gutter';
|
||||
import { getTranslation } from '../../../../utilities/getTranslation';
|
||||
import { LoadingOverlayToggle } from '../../elements/Loading';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
const baseClass = 'versions';
|
||||
|
||||
const Versions: React.FC<Props> = ({ collection, global }) => {
|
||||
const { serverURL, routes: { admin, api }, admin: { dateFormat } } = useConfig();
|
||||
const { serverURL, routes: { admin, api } } = useConfig();
|
||||
const { setStepNav } = useStepNav();
|
||||
const { params: { id } } = useRouteMatch<{ id: string }>();
|
||||
const { t, i18n } = useTranslation('version');
|
||||
@@ -39,14 +34,12 @@ const Versions: React.FC<Props> = ({ collection, global }) => {
|
||||
let docURL: string;
|
||||
let entityLabel: string;
|
||||
let slug: string;
|
||||
let entity: SanitizedCollectionConfig | SanitizedGlobalConfig;
|
||||
let editURL: string;
|
||||
|
||||
if (collection) {
|
||||
({ slug } = collection);
|
||||
docURL = `${serverURL}${api}/${slug}/${id}`;
|
||||
entityLabel = getTranslation(collection.labels.singular, i18n);
|
||||
entity = collection;
|
||||
editURL = `${admin}/collections/${collection.slug}/${id}`;
|
||||
}
|
||||
|
||||
@@ -54,13 +47,12 @@ const Versions: React.FC<Props> = ({ collection, global }) => {
|
||||
({ slug } = global);
|
||||
docURL = `${serverURL}${api}/globals/${slug}`;
|
||||
entityLabel = getTranslation(global.label, i18n);
|
||||
entity = global;
|
||||
editURL = `${admin}/globals/${global.slug}`;
|
||||
}
|
||||
|
||||
const useAsTitle = collection?.admin?.useAsTitle || 'id';
|
||||
const [{ data: doc }] = usePayloadAPI(docURL, { initialParams: { draft: 'true' } });
|
||||
const [{ data: versionsData, isLoading: isLoadingData }, { setParams }] = usePayloadAPI(fetchURL);
|
||||
const [{ data: versionsData, isLoading: isLoadingVersions }, { setParams }] = usePayloadAPI(fetchURL);
|
||||
|
||||
useEffect(() => {
|
||||
let nav: StepNavItem[] = [];
|
||||
@@ -164,17 +156,12 @@ const Versions: React.FC<Props> = ({ collection, global }) => {
|
||||
useIDLabel = false;
|
||||
}
|
||||
|
||||
const docStatus = doc?._status;
|
||||
const docUpdatedAt = doc?.updatedAt;
|
||||
const showParentDoc = versionsData?.page === 1 && shouldIncrementVersionCount({ entity, docStatus, versions: versionsData });
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<LoadingOverlayToggle
|
||||
show={isLoadingData}
|
||||
show={isLoadingVersions}
|
||||
name="versions"
|
||||
/>
|
||||
|
||||
<div className={baseClass}>
|
||||
<Meta
|
||||
title={metaTitle}
|
||||
@@ -194,26 +181,6 @@ const Versions: React.FC<Props> = ({ collection, global }) => {
|
||||
)}
|
||||
</header>
|
||||
|
||||
{showParentDoc && (
|
||||
<Banner
|
||||
type={docStatus === 'published' ? 'success' : undefined}
|
||||
className={`${baseClass}__parent-doc`}
|
||||
>
|
||||
{t('currentDocumentStatus', { docStatus })}
|
||||
-
|
||||
{' '}
|
||||
{format(new Date(docUpdatedAt), dateFormat)}
|
||||
<div className={`${baseClass}__parent-doc-pills`}>
|
||||
|
||||
<Pill
|
||||
pillStyle="white"
|
||||
to={editURL}
|
||||
>
|
||||
{t('general:edit')}
|
||||
</Pill>
|
||||
</div>
|
||||
</Banner>
|
||||
)}
|
||||
{versionsData?.totalDocs > 0 && (
|
||||
<React.Fragment>
|
||||
<Table
|
||||
|
||||
@@ -52,13 +52,13 @@ const RelationshipCell = (props) => {
|
||||
{values.map(({ relationTo, value }, i) => {
|
||||
const document = documents[relationTo][value];
|
||||
const relatedCollection = collections.find(({ slug }) => slug === relationTo);
|
||||
const label = document?.[relatedCollection.admin.useAsTitle] ? document[relatedCollection.admin.useAsTitle] : `${t('untitled')} - ID: ${value}`;
|
||||
|
||||
return (
|
||||
<React.Fragment key={i}>
|
||||
{document === false && `${t('untitled')} - ID: ${value}`}
|
||||
{document === null && `${t('loading')}...`}
|
||||
{document && (
|
||||
document[relatedCollection.admin.useAsTitle] ? document[relatedCollection.admin.useAsTitle] : `${t('untitled')} - ID: ${value}`
|
||||
)}
|
||||
{document && label}
|
||||
{values.length > i + 1 && ', '}
|
||||
</React.Fragment>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user