Skip to content

Commit

Permalink
chore: rebase clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
barthc committed Jun 24, 2020
1 parent a56c44a commit bc9dcab
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 122 deletions.
24 changes: 22 additions & 2 deletions dev-test/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
backend:
name: test-repo
name: github
repo: bastiaan02/jekyll-base

site_url: https://example.com

publish_mode: editorial_workflow
media_folder: assets/uploads

locales:
- en
- fr

collections: # A list of collections the CMS should be able to edit
- name: 'posts' # Used in routes, ie.: /admin/collections/:slug/edit
label: 'Posts' # Used in the UI
Expand Down Expand Up @@ -45,7 +50,22 @@ collections: # A list of collections the CMS should be able to edit
tagname: ''

- { label: 'Body', name: 'body', widget: 'markdown', hint: 'Main content goes here.' }

- name: 'blog' # Used in routes, ie.: /admin/collections/:slug/edit
label: 'BLOG' # Used in the UI
folder: '_blogs'
i18n_structure: locale_file_extensions
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
- { label: 'Title', name: 'title', widget: 'string', translatable: true, tagname: 'h1' }
- { label: 'Answer', name: 'body', widget: 'markdown', translatable: true }
- name: 'product' # Used in routes, ie.: /admin/collections/:slug/edit
label: 'PRODUCT' # Used in the UI
folder: '_products'
i18n_structure: locale_folders
create: true # Allow users to create new documents in this collection
fields: # The fields each document in this collection have
- { label: 'Title', name: 'title', widget: 'string', translatable: true, tagname: 'h1' }
- { label: 'Description', name: 'body', widget: 'markdown', translatable: true }
- name: 'faq' # Used in routes, ie.: /admin/collections/:slug/edit
label: 'FAQ' # Used in the UI
folder: '_faqs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('github API', () => {
path: 'content/posts/new-post.md',
raw: 'content',
};
await api.persistFiles(entry, [], { commitMessage: 'commitMessage' });
await api.persistFiles([entry], [], { commitMessage: 'commitMessage' });

expect(api.request).toHaveBeenCalledTimes(5);

Expand Down
7 changes: 2 additions & 5 deletions packages/netlify-cms-backend-test/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,8 @@ export default class TestBackend implements Implementation {
};
}

async persistEntry(
{ path, raw, slug, newPath }: Entry,
assetProxies: AssetProxy[],
options: PersistOptions,
) {
async persistEntry(entries: Entry, assetProxies: AssetProxy[], options: PersistOptions) {
const { path, raw, slug, newPath } = entries[0];
if (options.useWorkflow) {
const key = `${options.collectionName}/${slug}`;
const currentEntry = window.repoFilesUnpublished[key];
Expand Down
2 changes: 1 addition & 1 deletion packages/netlify-cms-core/src/__tests__/backend.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ describe('Backend', () => {
},
],
});
});
});
});

describe('getMultipleEntries', () => {
Expand Down
24 changes: 13 additions & 11 deletions packages/netlify-cms-core/src/actions/__tests__/config.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { fromJS } from 'immutable';
<<<<<<< HEAD
import { stripIndent } from 'common-tags';
import { parseConfig, applyDefaults, detectProxyServer, handleLocalBackend } from '../config';
=======
import { applyDefaults, detectProxyServer, handleLocalBackend, addLocaleFields } from '../config';
>>>>>>> 6f4b539c... fix: add unit tests
import {
parseConfig,
applyDefaults,
detectProxyServer,
handleLocalBackend,
addLocaleFields,
} from '../config';

jest.spyOn(console, 'log').mockImplementation(() => {});
jest.mock('coreSrc/backend', () => {
Expand Down Expand Up @@ -582,9 +584,9 @@ describe('config', () => {
describe('addLocaleFields', () => {
it('should add locale fields', () => {
const fields = fromJS([
{ name: 'title', widget: 'string' },
{ name: 'title', widget: 'string', translatable: true },
{ name: 'date', widget: 'date' },
{ name: 'content', widget: 'markdown' },
{ name: 'content', widget: 'markdown', translatable: true },
]);
const actual = addLocaleFields(fields, ['en', 'fr']);

Expand All @@ -596,9 +598,9 @@ describe('config', () => {
widget: 'object',
multiContentId: Symbol.for('multiContentId'),
fields: [
{ name: 'title', widget: 'string' },
{ name: 'title', widget: 'string', translatable: true },
{ name: 'date', widget: 'date' },
{ name: 'content', widget: 'markdown' },
{ name: 'content', widget: 'markdown', translatable: true },
],
},
{
Expand All @@ -607,8 +609,8 @@ describe('config', () => {
widget: 'object',
multiContentId: Symbol.for('multiContentId'),
fields: [
{ name: 'title', widget: 'string' },
{ name: 'content', widget: 'markdown' },
{ name: 'title', widget: 'string', translatable: true },
{ name: 'content', widget: 'markdown', translatable: true },
],
},
]),
Expand Down
19 changes: 13 additions & 6 deletions packages/netlify-cms-core/src/actions/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import yaml from 'yaml';
import { Map, fromJS } from 'immutable';
import { trimStart, trim, get, isPlainObject } from 'lodash';
import { Map, List, fromJS } from 'immutable';
import { trimStart, trim, get, isPlainObject, uniq, isEmpty } from 'lodash';
import { authenticateUser } from 'Actions/auth';
import * as publishModes from 'Constants/publishModes';
import { validateConfig } from 'Constants/configSchema';
import { selectDefaultSortableFields, traverseFields, selectIdentifier } from '../reducers/collections';
import { NON_TRANSLATABLE_FIELDS } from 'Constants/multiContentTypes';
import {
selectDefaultSortableFields,
traverseFields,
selectIdentifier,
} from '../reducers/collections';
import { resolveBackend } from 'coreSrc/backend';
import { DIFF_FILE_TYPES } from 'Constants/multiContentTypes';

export const CONFIG_REQUEST = 'CONFIG_REQUEST';
export const CONFIG_SUCCESS = 'CONFIG_SUCCESS';
Expand Down Expand Up @@ -124,6 +129,9 @@ export function applyDefaults(config) {
if (backend === 'test-repo') {
collection = collection.set('i18n_structure', 'single_file');
}
if (DIFF_FILE_TYPES.includes(collection.get('i18n_structure'))) {
collection = collection.set('multi_content_diff_files', true);
}
}
}

Expand Down Expand Up @@ -190,7 +198,6 @@ export function addLocaleFields(fields, locales) {
function stripNonTranslatableFields(fields) {
return fields.reduce((acc, item) => {
const subfields = item.get('field') || item.get('fields');
const widget = item.get('widget');

if (List.isList(subfields)) {
return acc.push(item.set('fields', stripNonTranslatableFields(subfields)));
Expand All @@ -200,7 +207,7 @@ function stripNonTranslatableFields(fields) {
return acc.push(item.set('field', stripNonTranslatableFields([subfields])));
}

if (!NON_TRANSLATABLE_FIELDS.includes(widget)) {
if (item.get('translatable')) {
return acc.push(item);
}

Expand Down
5 changes: 2 additions & 3 deletions packages/netlify-cms-core/src/actions/editorialWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
createDraftFromEntry,
loadEntries,
} from './entries';
import { DIFF_FILE_TYPES } from 'Constants/multiContentTypes';
import { createAssetProxy } from '../valueObjects/AssetProxy';
import { addAssets } from './media';
import { loadMedia } from './mediaLibrary';
Expand Down Expand Up @@ -282,7 +281,7 @@ export function loadUnpublishedEntry(collection: Collection, slug: string) {
dispatch(unpublishedEntryLoading(collection, slug));

try {
const entry = (await backend.unpublishedEntry(state, collection, slug)) as EntryValue;
let entry = (await backend.unpublishedEntry(state, collection, slug)) as EntryValue;
const assetProxies = await Promise.all(
entry.mediaFiles
.filter(file => file.draft)
Expand All @@ -296,7 +295,7 @@ export function loadUnpublishedEntry(collection: Collection, slug: string) {
);
dispatch(addAssets(assetProxies));

if (multiContent && DIFF_FILE_TYPES.includes(i18nStructure)) {
if (collection.get('multi_content_diff_files')) {
const publishedEntries = get(
getState().entries.toJS(),
`pages.${collection.get('name')}.ids`,
Expand Down
25 changes: 5 additions & 20 deletions packages/netlify-cms-core/src/actions/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Cursor, ImplementationMediaFile } from 'netlify-cms-lib-util';
import { createEntry, EntryValue } from '../valueObjects/Entry';
import AssetProxy, { createAssetProxy } from '../valueObjects/AssetProxy';
import ValidationErrorTypes from '../constants/validationErrorTypes';
import { DIFF_FILE_TYPES } from 'Constants/multiContentTypes';
import { addAssets, getAsset } from './media';
import {
Collection,
Expand Down Expand Up @@ -461,7 +460,7 @@ export function loadEntry(collection: Collection, slug: string) {
dispatch(entryLoading(collection, slug));

try {
const loadedEntry = await tryLoadEntry(getState(), collection, slug, locales, multiContent);
const loadedEntry = await tryLoadEntry(getState(), collection, slug);
dispatch(entryLoaded(collection, loadedEntry));
dispatch(createDraftFromEntry(loadedEntry));
} catch (error) {
Expand All @@ -481,21 +480,9 @@ export function loadEntry(collection: Collection, slug: string) {
};
}

export async function tryLoadEntry(
state: State,
collection: Collection,
slug: string,
locales,
multiContent
) {
export async function tryLoadEntry(state: State, collection: Collection, slug: string) {
const backend = currentBackend(state.config);
const loadedEntry = await backend.getEntry(
state,
collection,
slug,
locales,
multiContent
);
const loadedEntry = await backend.getEntry(state, collection, slug);
return loadedEntry;
}

Expand Down Expand Up @@ -526,8 +513,6 @@ export function loadEntries(collection: Collection, page = 0) {
}

const backend = currentBackend(state.config);
const multiContent = collection.get('multi_content');
const i18nStructure = collection.get('i18n_structure');
const integration = selectIntegration(state, collection.get('name'), 'listEntries');
const provider = integration
? getIntegrationProvider(state.integrations, backend.getToken, integration)
Expand All @@ -543,8 +528,8 @@ export function loadEntries(collection: Collection, page = 0) {
} = await (collection.has('nested')
? // nested collections require all entries to construct the tree
provider.listAllEntries(collection).then((entries: EntryValue[]) => ({ entries }))
: locales && DIFF_FILE_TYPES.includes(multiContent)
? provider.listAllMultipleEntires(collection, locales)
: collection.get('multi_content_diff_files')
? provider.listAllMultipleEntires(collection)
: provider.listEntries(collection, page));
response = {
...response,
Expand Down
Loading

0 comments on commit bc9dcab

Please sign in to comment.