fix(list-entries-integration): don't show commit date & author default sort (#4849)
This commit is contained in:
@ -377,17 +377,21 @@ export const selectEntryCollectionTitle = (collection: Collection, entry: EntryM
|
||||
export const COMMIT_AUTHOR = 'commit_author';
|
||||
export const COMMIT_DATE = 'commit_date';
|
||||
|
||||
export const selectDefaultSortableFields = (collection: Collection, backend: Backend) => {
|
||||
export const selectDefaultSortableFields = (
|
||||
collection: Collection,
|
||||
backend: Backend,
|
||||
hasIntegration: boolean,
|
||||
) => {
|
||||
let defaultSortable = SORTABLE_FIELDS.map((type: string) => {
|
||||
const field = selectInferedField(collection, type);
|
||||
if (backend.isGitBackend() && type === 'author' && !field) {
|
||||
if (backend.isGitBackend() && type === 'author' && !field && !hasIntegration) {
|
||||
// default to commit author if not author field is found
|
||||
return COMMIT_AUTHOR;
|
||||
}
|
||||
return field;
|
||||
}).filter(Boolean);
|
||||
|
||||
if (backend.isGitBackend()) {
|
||||
if (backend.isGitBackend() && !hasIntegration) {
|
||||
// always have commit date by default
|
||||
defaultSortable = [COMMIT_DATE, ...defaultSortable];
|
||||
}
|
||||
|
@ -1,42 +1,49 @@
|
||||
import { fromJS, List } from 'immutable';
|
||||
import { CONFIG_SUCCESS } from '../actions/config';
|
||||
import { Integrations, IntegrationsAction, Integration } from '../types/redux';
|
||||
import { Integrations, IntegrationsAction, Integration, Config } from '../types/redux';
|
||||
|
||||
interface Acc {
|
||||
providers: Record<string, {}>;
|
||||
hooks: Record<string, string | Record<string, string>>;
|
||||
}
|
||||
|
||||
export const getIntegrations = (config: Config) => {
|
||||
const integrations: Integration[] = config.get('integrations', List()).toJS() || [];
|
||||
const newState = integrations.reduce(
|
||||
(acc, integration) => {
|
||||
const { hooks, collections, provider, ...providerData } = integration;
|
||||
acc.providers[provider] = { ...providerData };
|
||||
if (!collections) {
|
||||
hooks.forEach(hook => {
|
||||
acc.hooks[hook] = provider;
|
||||
});
|
||||
return acc;
|
||||
}
|
||||
const integrationCollections =
|
||||
collections === '*'
|
||||
? config
|
||||
.get('collections')
|
||||
.map(collection => collection!.get('name'))
|
||||
.toArray()
|
||||
: (collections as string[]);
|
||||
integrationCollections.forEach(collection => {
|
||||
hooks.forEach(hook => {
|
||||
acc.hooks[collection]
|
||||
? ((acc.hooks[collection] as Record<string, string>)[hook] = provider)
|
||||
: (acc.hooks[collection] = { [hook]: provider });
|
||||
});
|
||||
});
|
||||
return acc;
|
||||
},
|
||||
{ providers: {}, hooks: {} } as Acc,
|
||||
);
|
||||
return fromJS(newState);
|
||||
};
|
||||
|
||||
const integrations = (state = null, action: IntegrationsAction): Integrations | null => {
|
||||
switch (action.type) {
|
||||
case CONFIG_SUCCESS: {
|
||||
const integrations: Integration[] = action.payload.get('integrations', List()).toJS() || [];
|
||||
const newState = integrations.reduce(
|
||||
(acc, integration) => {
|
||||
const { hooks, collections, provider, ...providerData } = integration;
|
||||
acc.providers[provider] = { ...providerData };
|
||||
if (!collections) {
|
||||
hooks.forEach(hook => {
|
||||
acc.hooks[hook] = provider;
|
||||
});
|
||||
return acc;
|
||||
}
|
||||
const integrationCollections =
|
||||
collections === '*'
|
||||
? action.payload.get('collections').map(collection => collection.get('name'))
|
||||
: (collections as string[]);
|
||||
integrationCollections.forEach(collection => {
|
||||
hooks.forEach(hook => {
|
||||
acc.hooks[collection]
|
||||
? ((acc.hooks[collection] as Record<string, string>)[hook] = provider)
|
||||
: (acc.hooks[collection] = { [hook]: provider });
|
||||
});
|
||||
});
|
||||
return acc;
|
||||
},
|
||||
{ providers: {}, hooks: {} } as Acc,
|
||||
);
|
||||
return fromJS(newState);
|
||||
return getIntegrations(action.payload);
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
|
Reference in New Issue
Block a user