mirror of
https://github.com/strapi/strapi.git
synced 2025-08-23 16:19:37 +00:00
Reduce and optimize lodash imports
This commit is contained in:
parent
69e34ff84a
commit
a9fb1f3130
@ -1,4 +1,4 @@
|
|||||||
import { cloneDeep } from 'lodash';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import init from '../init';
|
import init from '../init';
|
||||||
import { initialState } from '../reducer';
|
import { initialState } from '../reducer';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
function useSelect(name) {
|
function useSelect(name) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { get, take } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import take from 'lodash/take';
|
||||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
import { getFieldName } from '../../../utils';
|
import { getFieldName } from '../../../utils';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { toLower } from 'lodash';
|
import toLower from 'lodash/toLower';
|
||||||
|
|
||||||
const getInputType = (type = '') => {
|
const getInputType = (type = '') => {
|
||||||
switch (toLower(type)) {
|
switch (toLower(type)) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
function useSelect(keys) {
|
function useSelect(keys) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { get } from 'lodash';
|
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import selectLayout from '../../pages/EditViewLayoutManager/selectors';
|
import selectLayout from '../../pages/EditViewLayoutManager/selectors';
|
||||||
|
|
||||||
@ -8,7 +7,7 @@ const useContentTypeLayout = () => {
|
|||||||
|
|
||||||
const getComponentLayout = useCallback(
|
const getComponentLayout = useCallback(
|
||||||
(componentUid) => {
|
(componentUid) => {
|
||||||
return get(currentLayout, ['components', componentUid], {});
|
return currentLayout?.components?.[componentUid] ?? {};
|
||||||
},
|
},
|
||||||
[currentLayout]
|
[currentLayout]
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { cloneDeep, get, set } from 'lodash';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
|
||||||
import { mergeMetasWithSchema } from '../../../utils';
|
import { mergeMetasWithSchema } from '../../../utils';
|
||||||
|
|
||||||
const getRelationModel = (targetModel, models) => models.find((model) => model.uid === targetModel);
|
const getRelationModel = (targetModel, models) => models.find((model) => model.uid === targetModel);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import React, { memo, useMemo } from 'react';
|
import React, { memo, useMemo } from 'react';
|
||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
import { ErrorBoundary } from 'react-error-boundary';
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
import { get } from 'lodash';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { LoadingIndicatorPage, CheckPagePermissions } from '@strapi/helper-plugin';
|
import { LoadingIndicatorPage, CheckPagePermissions } from '@strapi/helper-plugin';
|
||||||
import permissions from '../../../permissions';
|
import permissions from '../../../permissions';
|
||||||
@ -43,7 +42,7 @@ const CollectionTypeRecursivePath = ({
|
|||||||
return { rawContentTypeLayout, rawComponentsLayouts };
|
return { rawContentTypeLayout, rawComponentsLayouts };
|
||||||
}, [layout]);
|
}, [layout]);
|
||||||
|
|
||||||
const uid = get(layout, ['contentType', 'uid'], null);
|
const uid = layout?.contentType?.uid ?? null;
|
||||||
|
|
||||||
// This statement is needed in order to prevent the CollectionTypeFormWrapper effects clean up phase to be run twice.
|
// This statement is needed in order to prevent the CollectionTypeFormWrapper effects clean up phase to be run twice.
|
||||||
// What can happen is that when navigating from one entry to another the cleanup phase of the fetch data effect is run twice : once when
|
// What can happen is that when navigating from one entry to another the cleanup phase of the fetch data effect is run twice : once when
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { cloneDeep, set } from 'lodash';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
|
||||||
import { createLayout, formatLayout } from './utils/layout';
|
import { createLayout, formatLayout } from './utils/layout';
|
||||||
|
|
||||||
const init = (initialState, mainLayout, components) => {
|
const init = (initialState, mainLayout, components) => {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { get } from 'lodash';
|
|
||||||
|
|
||||||
const createPossibleMainFieldsForModelsAndComponents = (array) => {
|
const createPossibleMainFieldsForModelsAndComponents = (array) => {
|
||||||
return array.reduce((acc, current) => {
|
return array.reduce((acc, current) => {
|
||||||
const attributes = get(current, ['attributes'], {});
|
const attributes = current?.attributes ?? {};
|
||||||
const possibleMainFields = Object.keys(attributes).filter((attr) => {
|
const possibleMainFields = Object.keys(attributes).filter((attr) => {
|
||||||
return ![
|
return ![
|
||||||
'boolean',
|
'boolean',
|
||||||
@ -14,7 +12,7 @@ const createPossibleMainFieldsForModelsAndComponents = (array) => {
|
|||||||
'relation',
|
'relation',
|
||||||
'text',
|
'text',
|
||||||
'richtext',
|
'richtext',
|
||||||
].includes(get(attributes, [attr, 'type'], ''));
|
].includes(attributes?.[attr]?.type ?? '');
|
||||||
});
|
});
|
||||||
|
|
||||||
acc[current.uid] = possibleMainFields;
|
acc[current.uid] = possibleMainFields;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { isEmpty } from 'lodash';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
function useSelect() {
|
function useSelect() {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { get, isEmpty } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
|
||||||
const createAttributesLayout = (currentContentTypeLayoutData) => {
|
const createAttributesLayout = (currentContentTypeLayoutData) => {
|
||||||
if (!currentContentTypeLayoutData.layouts) {
|
if (!currentContentTypeLayoutData.layouts) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { uniq, flatMap } from 'lodash';
|
import uniq from 'lodash/uniq';
|
||||||
|
import flatMap from 'lodash/flatMap';
|
||||||
import { findMatchingPermissions } from '@strapi/helper-plugin';
|
import { findMatchingPermissions } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
const getFieldsActionMatchingPermissions = (userPermissions, slug) => {
|
const getFieldsActionMatchingPermissions = (userPermissions, slug) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { toLower } from 'lodash';
|
import toLower from 'lodash/toLower';
|
||||||
|
|
||||||
const checkIfAttributeIsDisplayable = (attribute) => {
|
const checkIfAttributeIsDisplayable = (attribute) => {
|
||||||
const type = attribute.type;
|
const type = attribute.type;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
|
||||||
const createDefaultForm = (attributes, allComponentsSchema) => {
|
const createDefaultForm = (attributes, allComponentsSchema) => {
|
||||||
return Object.keys(attributes).reduce((acc, current) => {
|
return Object.keys(attributes).reduce((acc, current) => {
|
||||||
@ -10,7 +10,7 @@ const createDefaultForm = (attributes, allComponentsSchema) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'component') {
|
if (type === 'component') {
|
||||||
const currentComponentSchema = get(allComponentsSchema, [component, 'attributes'], {});
|
const currentComponentSchema = allComponentsSchema?.[component]?.attributes ?? {};
|
||||||
const currentComponentDefaultForm = createDefaultForm(
|
const currentComponentDefaultForm = createDefaultForm(
|
||||||
currentComponentSchema,
|
currentComponentSchema,
|
||||||
allComponentsSchema
|
allComponentsSchema
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { omit, get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import omit from 'lodash/omit';
|
||||||
|
|
||||||
const formatLayoutToApi = ({ layouts, metadatas, ...rest }) => {
|
const formatLayoutToApi = ({ layouts, metadatas, ...rest }) => {
|
||||||
const list = layouts.list.map((obj) => {
|
const list = layouts.list.map((obj) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { isNaN } from 'lodash';
|
import isNaN from 'lodash/isNaN';
|
||||||
|
|
||||||
const getFieldName = (stringName) =>
|
const getFieldName = (stringName) =>
|
||||||
stringName.split('.').filter((string) => isNaN(parseInt(string, 10)));
|
stringName.split('.').filter((string) => isNaN(parseInt(string, 10)));
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { set } from 'lodash';
|
import set from 'lodash/set';
|
||||||
|
|
||||||
const mergeMetasWithSchema = (data, schemas, mainSchemaKey) => {
|
const mergeMetasWithSchema = (data, schemas, mainSchemaKey) => {
|
||||||
const findSchema = (refUid) => schemas.find((obj) => obj.uid === refUid);
|
const findSchema = (refUid) => schemas.find((obj) => obj.uid === refUid);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* This file is for all helpers related to `paths` in the CM.
|
* This file is for all helpers related to `paths` in the CM.
|
||||||
*/
|
*/
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is typically used in circumstances where there are re-orderable pieces e.g. Dynamic Zones
|
* This is typically used in circumstances where there are re-orderable pieces e.g. Dynamic Zones
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { getType, getOtherInfos } from '@strapi/helper-plugin';
|
import { getType, getOtherInfos } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
const removePasswordFieldsFromData = (data, contentTypeSchema, componentSchema) => {
|
const removePasswordFieldsFromData = (data, contentTypeSchema, componentSchema) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
import { useFetchClient, useNotification } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
const useRegenerate = (url, id, onRegenerate) => {
|
const useRegenerate = (url, id, onRegenerate) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useReducer } from 'react';
|
import { useEffect, useReducer } from 'react';
|
||||||
import { request, useNotification, useOverlayBlocker } from '@strapi/helper-plugin';
|
import { request, useNotification, useOverlayBlocker } from '@strapi/helper-plugin';
|
||||||
import { get, has, omit } from 'lodash';
|
import omit from 'lodash/omit';
|
||||||
import { checkFormValidity, formatAPIErrors } from '../../utils';
|
import { checkFormValidity, formatAPIErrors } from '../../utils';
|
||||||
import { initialState, reducer } from './reducer';
|
import { initialState, reducer } from './reducer';
|
||||||
import init from './init';
|
import init from './init';
|
||||||
@ -102,9 +102,9 @@ const useSettingsForm = (endPoint, schema, cbSuccess, fieldsToPick) => {
|
|||||||
message: { id: 'notification.success.saved' },
|
message: { id: 'notification.success.saved' },
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const data = get(err, 'response.payload', { data: {} });
|
const data = err?.response?.payload ?? { data: {} };
|
||||||
|
|
||||||
if (has(data, 'data') && typeof data.data === 'string') {
|
if (!!data?.data && typeof data.data === 'string') {
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
message: data.data,
|
message: data.data,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { pick, set, unset } from 'lodash';
|
import pick from 'lodash/pick';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
import unset from 'lodash/unset';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
fieldsToPick: [],
|
fieldsToPick: [],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { set } from 'lodash';
|
import set from 'lodash/set';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
menu: [],
|
menu: [],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { set } from 'lodash';
|
import set from 'lodash/set';
|
||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { capitalize } from 'lodash';
|
import capitalize from 'lodash/capitalize';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { pull } from 'lodash';
|
import pull from 'lodash/pull';
|
||||||
import { transformPermissionsData } from './utils';
|
import { transformPermissionsData } from './utils';
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { flatten } from 'lodash';
|
|
||||||
|
|
||||||
const transformPermissionsData = (data) => {
|
const transformPermissionsData = (data) => {
|
||||||
const layout = {
|
const layout = {
|
||||||
allActionsIds: [],
|
allActionsIds: [],
|
||||||
@ -9,11 +7,11 @@ const transformPermissionsData = (data) => {
|
|||||||
layout.permissions = Object.keys(data).map((apiId) => ({
|
layout.permissions = Object.keys(data).map((apiId) => ({
|
||||||
apiId,
|
apiId,
|
||||||
label: apiId.split('::')[1],
|
label: apiId.split('::')[1],
|
||||||
controllers: flatten(
|
controllers: Object.keys(data[apiId].controllers)
|
||||||
Object.keys(data[apiId].controllers).map((controller) => ({
|
.map((controller) => ({
|
||||||
controller,
|
controller,
|
||||||
actions: flatten(
|
actions: data[apiId].controllers[controller]
|
||||||
data[apiId].controllers[controller].map((action) => {
|
.map((action) => {
|
||||||
const actionId = `${apiId}.${controller}.${action}`;
|
const actionId = `${apiId}.${controller}.${action}`;
|
||||||
|
|
||||||
if (apiId.includes('api::')) {
|
if (apiId.includes('api::')) {
|
||||||
@ -25,9 +23,9 @@ const transformPermissionsData = (data) => {
|
|||||||
actionId,
|
actionId,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
),
|
.flat(),
|
||||||
}))
|
}))
|
||||||
),
|
.flat(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
|
||||||
const createConditionsForm = (conditions, valueObject) => {
|
const createConditionsForm = (conditions, valueObject) => {
|
||||||
return conditions.reduce((acc, current) => {
|
return conditions.reduce((acc, current) => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { get, isEmpty } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
import { createArrayOfValues, getCheckboxState } from '../../../utils';
|
import { createArrayOfValues, getCheckboxState } from '../../../utils';
|
||||||
|
|
||||||
const generateCheckboxesActions = (availableActions, modifiedData, pathToData) => {
|
const generateCheckboxesActions = (availableActions, modifiedData, pathToData) => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
|
||||||
import { getCheckboxState } from '../../../../utils';
|
import { getCheckboxState } from '../../../../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
||||||
|
|
||||||
const getActionsIds = (array) => array.map(({ actionId }) => actionId);
|
const getActionsIds = (array) => array.map(({ actionId }) => actionId);
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { cloneDeep, has, isObject, get, set } from 'lodash';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
|
import has from 'lodash/has';
|
||||||
|
import isObject from 'lodash/isObject';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
|
||||||
import updateConditionsToFalse from './utils/updateConditionsToFalse';
|
import updateConditionsToFalse from './utils/updateConditionsToFalse';
|
||||||
import updateValues from './utils/updateValues';
|
import updateValues from './utils/updateValues';
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { merge, get, isEmpty, set } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
import merge from 'lodash/merge';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
|
||||||
import findMatchingPermission from './findMatchingPermissions';
|
import findMatchingPermission from './findMatchingPermissions';
|
||||||
/**
|
/**
|
||||||
* Creates the default condition form: { [conditionId]: false }
|
* Creates the default condition form: { [conditionId]: false }
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { get } from 'lodash';
|
|
||||||
import { createDefaultConditionsForm } from './createDefaultCTFormFromLayout';
|
import { createDefaultConditionsForm } from './createDefaultCTFormFromLayout';
|
||||||
import findMatchingPermission from './findMatchingPermissions';
|
import findMatchingPermission from './findMatchingPermissions';
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ const createSubCategoryForm = (actions, conditions, permissions) => {
|
|||||||
},
|
},
|
||||||
conditions: createDefaultConditionsForm(
|
conditions: createDefaultConditionsForm(
|
||||||
conditions,
|
conditions,
|
||||||
get(foundMatchingPermission, 'conditions', [])
|
foundMatchingPermission?.conditions ?? []
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { has, isObject } from 'lodash';
|
import isObject from 'lodash/isObject';
|
||||||
import { createArrayOfValues } from '../../utils';
|
import { createArrayOfValues } from '../../utils';
|
||||||
import { createConditionsArray } from './formatSettingsPermissionsToAPI';
|
import { createConditionsArray } from './formatSettingsPermissionsToAPI';
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ const createSubjectPermissions = (subject, actions) => {
|
|||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!has(permissions, 'properties.enabled')) {
|
if (!permissions?.properties?.enabled) {
|
||||||
const createdPermissionsArray = createPermissionWithProperties(
|
const createdPermissionsArray = createPermissionWithProperties(
|
||||||
actionName,
|
actionName,
|
||||||
subject,
|
subject,
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { isObject, has, omit } from 'lodash';
|
import isObject from 'lodash/isObject';
|
||||||
|
import has from 'lodash/has';
|
||||||
|
import omit from 'lodash/omit';
|
||||||
|
|
||||||
import { createArrayOfValues } from '../../utils';
|
import { createArrayOfValues } from '../../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { isObject } from 'lodash';
|
import isObject from 'lodash/isObject';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets all the none object values of an object to the given one
|
* Sets all the none object values of an object to the given one
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { createArrayOfValues } from '../../../utils';
|
import { createArrayOfValues } from '../../../utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { flattenDeep, isObject } from 'lodash';
|
import flattenDeep from 'lodash/flattenDeep';
|
||||||
|
import isObject from 'lodash/isObject';
|
||||||
|
|
||||||
const createArrayOfValues = (obj) => {
|
const createArrayOfValues = (obj) => {
|
||||||
if (!isObject(obj)) {
|
if (!isObject(obj)) {
|
||||||
|
@ -26,7 +26,7 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
VisuallyHidden,
|
VisuallyHidden,
|
||||||
} from '@strapi/design-system';
|
} from '@strapi/design-system';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import matchSorter from 'match-sorter';
|
import matchSorter from 'match-sorter';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useMemo } from 'react';
|
import React, { useEffect, useMemo } from 'react';
|
||||||
import { useRBAC, LoadingIndicatorPage, useNotification } from '@strapi/helper-plugin';
|
import { useRBAC, LoadingIndicatorPage, useNotification } from '@strapi/helper-plugin';
|
||||||
import { Redirect, useLocation } from 'react-router-dom';
|
import { Redirect, useLocation } from 'react-router-dom';
|
||||||
import { get } from 'lodash';
|
|
||||||
import adminPermissions from '../../../../../permissions';
|
import adminPermissions from '../../../../../permissions';
|
||||||
import EditPage from '../EditPage';
|
import EditPage from '../EditPage';
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ const ProtectedEditPage = () => {
|
|||||||
allowedActions: { canRead, canUpdate },
|
allowedActions: { canRead, canUpdate },
|
||||||
} = useRBAC(permissions);
|
} = useRBAC(permissions);
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
const from = get(state, 'from', '/');
|
const from = state?.from ?? '/';
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import { set } from 'lodash';
|
|
||||||
|
|
||||||
const cleanData = (data) => {
|
const cleanData = (data) => {
|
||||||
const webhooks = { ...data };
|
return { ...data, headers: unformatHeaders(data.headers) };
|
||||||
|
|
||||||
set(webhooks, 'headers', unformatHeaders(data.headers));
|
|
||||||
|
|
||||||
return webhooks;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const unformatHeaders = (headers) => {
|
const unformatHeaders = (headers) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { merge } from 'lodash';
|
import merge from 'lodash/merge';
|
||||||
import customPermissions from 'ee_else_ce/permissions/customPermissions';
|
import customPermissions from 'ee_else_ce/permissions/customPermissions';
|
||||||
import defaultPermissions from './defaultPermissions';
|
import defaultPermissions from './defaultPermissions';
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { get } from 'lodash';
|
|
||||||
|
|
||||||
const getAttributesToDisplay = (contentType) => {
|
const getAttributesToDisplay = (contentType) => {
|
||||||
const timestamps = get(contentType, ['options', 'timestamps']);
|
const timestamps = contentType?.options?.timestamps;
|
||||||
|
|
||||||
// Sometimes timestamps is false
|
// Sometimes timestamps is false
|
||||||
let timestampsArray = Array.isArray(timestamps) ? timestamps : [];
|
let timestampsArray = Array.isArray(timestamps) ? timestamps : [];
|
||||||
const idsAttributes = ['id', '_id']; // For both SQL and mongo
|
const idsAttributes = ['id', '_id']; // For both SQL and mongo
|
||||||
const unwritableAttributes = [...idsAttributes, ...timestampsArray, 'publishedAt'];
|
const unwritableAttributes = [...idsAttributes, ...timestampsArray, 'publishedAt'];
|
||||||
const schemaAttributes = get(contentType, ['attributes'], {});
|
const schemaAttributes = contentType?.attributes ?? {};
|
||||||
|
|
||||||
return Object.keys(schemaAttributes).reduce((acc, current) => {
|
return Object.keys(schemaAttributes).reduce((acc, current) => {
|
||||||
if (!unwritableAttributes.includes(current)) {
|
if (!unwritableAttributes.includes(current)) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { get } from 'lodash';
|
|
||||||
|
|
||||||
const getExistingActions = (permissions) => {
|
const getExistingActions = (permissions) => {
|
||||||
return Array.from(
|
return Array.from(
|
||||||
new Set(
|
new Set(
|
||||||
@ -23,7 +21,7 @@ const getExistingActions = (permissions) => {
|
|||||||
...acc,
|
...acc,
|
||||||
...getActionsPermission([
|
...getActionsPermission([
|
||||||
...Object.values(current[1].attributes || {}),
|
...Object.values(current[1].attributes || {}),
|
||||||
get(current[1], 'contentTypeActions', {}),
|
current[1]?.contentTypeActions ?? {},
|
||||||
]),
|
]),
|
||||||
];
|
];
|
||||||
}, [])
|
}, [])
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { sortBy } from 'lodash';
|
import sortBy from 'lodash/sortBy';
|
||||||
|
|
||||||
const sortLinks = (links) => sortBy(links, (object) => object.name);
|
const sortLinks = (links) => sortBy(links, (object) => object.name);
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import React, { memo, useEffect, useMemo, useRef } from 'react';
|
import React, { memo, useEffect, useMemo, useRef } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { get, groupBy, set, size } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import groupBy from 'lodash/groupBy';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
import size from 'lodash/size';
|
||||||
import {
|
import {
|
||||||
LoadingIndicatorPage,
|
LoadingIndicatorPage,
|
||||||
useTracking,
|
useTracking,
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { get, isEqual, omit, sortBy, camelCase } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import isEqual from 'lodash/isEqual';
|
||||||
|
import omit from 'lodash/omit';
|
||||||
|
import sortBy from 'lodash/sortBy';
|
||||||
|
import camelCase from 'lodash/camelCase';
|
||||||
|
|
||||||
import pluginId from '../../../pluginId';
|
import pluginId from '../../../pluginId';
|
||||||
import makeUnique from '../../../utils/makeUnique';
|
import makeUnique from '../../../utils/makeUnique';
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { get } from 'lodash';
|
|
||||||
import makeUnique from '../../../utils/makeUnique';
|
import makeUnique from '../../../utils/makeUnique';
|
||||||
|
|
||||||
const retrieveNestedComponents = (appComponents) => {
|
const retrieveNestedComponents = (appComponents) => {
|
||||||
const nestedComponents = Object.keys(appComponents).reduce((acc, current) => {
|
const nestedComponents = Object.keys(appComponents).reduce((acc, current) => {
|
||||||
const componentAttributes = get(appComponents, [current, 'schema', 'attributes'], []);
|
const componentAttributes = appComponents?.[current]?.schema?.attributes ?? [];
|
||||||
const currentComponentNestedCompos = getComponentsFromComponent(componentAttributes);
|
const currentComponentNestedCompos = getComponentsFromComponent(componentAttributes);
|
||||||
|
|
||||||
return [...acc, ...currentComponentNestedCompos];
|
return [...acc, ...currentComponentNestedCompos];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import makeUnique from '../../../utils/makeUnique';
|
import makeUnique from '../../../utils/makeUnique';
|
||||||
|
|
||||||
const retrieveSpecificInfoFromComponents = (allComponents, keysToRetrieve) => {
|
const retrieveSpecificInfoFromComponents = (allComponents, keysToRetrieve) => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { get, toNumber } from 'lodash';
|
import toNumber from 'lodash/toNumber';
|
||||||
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
import getTrad from '../../../../utils/getTrad';
|
import getTrad from '../../../../utils/getTrad';
|
||||||
|
|
||||||
const NAME_REGEX = /^[A-Za-z][_0-9A-Za-z]*$/;
|
const NAME_REGEX = /^[A-Za-z][_0-9A-Za-z]*$/;
|
||||||
@ -20,7 +21,7 @@ const alreadyUsedAttributeNames = (usedNames) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getUsedContentTypeAttributeNames = (ctShema, isEdition, attributeNameToEdit) => {
|
const getUsedContentTypeAttributeNames = (ctShema, isEdition, attributeNameToEdit) => {
|
||||||
const attributes = get(ctShema, ['schema', 'attributes'], {});
|
const attributes = ctShema?.schema?.attributes ?? {};
|
||||||
|
|
||||||
return Object.keys(attributes).filter((attr) => {
|
return Object.keys(attributes).filter((attr) => {
|
||||||
if (isEdition) {
|
if (isEdition) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { toLower } from 'lodash';
|
|
||||||
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
import CATEGORY_NAME_REGEX from './regex';
|
import CATEGORY_NAME_REGEX from './regex';
|
||||||
|
|
||||||
const createCategorySchema = (usedCategoryNames) => {
|
const createCategorySchema = (usedCategoryNames) => {
|
||||||
@ -16,7 +16,7 @@ const createCategorySchema = (usedCategoryNames) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !usedCategoryNames.includes(toLower(value));
|
return !usedCategoryNames.includes(value?.toLowerCase());
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.required(errorsTrads.required),
|
.required(errorsTrads.required),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { toLower, trim } from 'lodash';
|
|
||||||
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
import getTrad from '../../../utils/getTrad';
|
import getTrad from '../../../utils/getTrad';
|
||||||
import { createComponentUid } from '../utils/createUid';
|
import { createComponentUid } from '../utils/createUid';
|
||||||
import { CATEGORY_NAME_REGEX } from '../category';
|
import { CATEGORY_NAME_REGEX } from '../category';
|
||||||
@ -30,7 +30,7 @@ const createComponentSchema = (usedComponentNames, reservedNames, category) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !reservedNames.includes(toLower(trim(value)));
|
return !reservedNames.includes(value?.trim()?.toLowerCase());
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.required(errorsTrads.required),
|
.required(errorsTrads.required),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { toLower, trim } from 'lodash';
|
|
||||||
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
import { translatedErrors as errorsTrads } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
import getTrad from '../../../utils/getTrad';
|
import getTrad from '../../../utils/getTrad';
|
||||||
import { createUid } from '../utils/createUid';
|
import { createUid } from '../utils/createUid';
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ const createContentTypeSchema = ({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !reservedModels.includes(toLower(trim(value)));
|
return !reservedModels.includes(value?.trim()?.toLowerCase());
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.required(errorsTrads.required),
|
.required(errorsTrads.required),
|
||||||
@ -70,7 +70,7 @@ const createContentTypeSchema = ({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !reservedModels.includes(toLower(trim(value)));
|
return !reservedModels.includes(value?.trim()?.toLowerCase());
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.required(errorsTrads.required),
|
.required(errorsTrads.required),
|
||||||
@ -106,7 +106,7 @@ const createContentTypeSchema = ({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !reservedModels.includes(toLower(trim(value)));
|
return !reservedModels.includes(value?.trim()?.toLowerCase());
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.required(errorsTrads.required),
|
.required(errorsTrads.required),
|
||||||
|
@ -27,7 +27,7 @@ import {
|
|||||||
TabPanel,
|
TabPanel,
|
||||||
Flex,
|
Flex,
|
||||||
} from '@strapi/design-system';
|
} from '@strapi/design-system';
|
||||||
import { isEqual } from 'lodash';
|
import isEqual from 'lodash/isEqual';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import useDataManager from '../../hooks/useDataManager';
|
import useDataManager from '../../hooks/useDataManager';
|
||||||
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
import useFormModalNavigation from '../../hooks/useFormModalNavigation';
|
||||||
|
@ -2,7 +2,7 @@ import produce from 'immer';
|
|||||||
import pluralize from 'pluralize';
|
import pluralize from 'pluralize';
|
||||||
import set from 'lodash/set';
|
import set from 'lodash/set';
|
||||||
import snakeCase from 'lodash/snakeCase';
|
import snakeCase from 'lodash/snakeCase';
|
||||||
import _ from 'lodash';
|
|
||||||
import getRelationType from '../../utils/getRelationType';
|
import getRelationType from '../../utils/getRelationType';
|
||||||
import nameToSlug from '../../utils/nameToSlug';
|
import nameToSlug from '../../utils/nameToSlug';
|
||||||
import { createComponentUid } from './utils/createUid';
|
import { createComponentUid } from './utils/createUid';
|
||||||
@ -312,7 +312,7 @@ const reducer = (state = initialState, action) =>
|
|||||||
|
|
||||||
if (optionDefaults.length) {
|
if (optionDefaults.length) {
|
||||||
optionDefaults.forEach(({ name, defaultValue }) =>
|
optionDefaults.forEach(({ name, defaultValue }) =>
|
||||||
_.set(draftState.modifiedData, name, defaultValue)
|
set(draftState.modifiedData, name, defaultValue)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { startsWith } from 'lodash';
|
|
||||||
|
|
||||||
const openWithNewTab = (path) => {
|
const openWithNewTab = (path) => {
|
||||||
const url = (() => {
|
const url = (() => {
|
||||||
if (startsWith(path, '/')) {
|
if (path.startsWith('/')) {
|
||||||
return `${strapi.backendURL}${path}`;
|
return `${strapi.backendURL}${path}`;
|
||||||
}
|
}
|
||||||
if (startsWith(path, 'https') || startsWith(path, 'http')) {
|
|
||||||
|
if (path.startsWith('http')) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import { getType, getOtherInfos } from '@strapi/helper-plugin';
|
import { getType, getOtherInfos } from '@strapi/helper-plugin';
|
||||||
|
|
||||||
const removePasswordAndRelationsFieldFromData = (data, contentTypeSchema, componentSchema) => {
|
const removePasswordAndRelationsFieldFromData = (data, contentTypeSchema, componentSchema) => {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { has } from 'lodash';
|
|
||||||
|
|
||||||
const extendCTBInitialDataMiddleware = () => {
|
const extendCTBInitialDataMiddleware = () => {
|
||||||
return () => (next) => (action) => {
|
return () => (next) => (action) => {
|
||||||
if (
|
if (
|
||||||
@ -20,7 +18,7 @@ const extendCTBInitialDataMiddleware = () => {
|
|||||||
|
|
||||||
// Override the action if the pluginOption config does not contain i18n
|
// Override the action if the pluginOption config does not contain i18n
|
||||||
// In this case we need to set the proper initialData shape
|
// In this case we need to set the proper initialData shape
|
||||||
if (!has(action.data.pluginOptions, 'i18n.localized')) {
|
if (!action.data.pluginOptions?.i18n?.localized) {
|
||||||
return next({ ...action, data });
|
return next({ ...action, data });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import { has, get, omit } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import has from 'lodash/has';
|
||||||
|
import omit from 'lodash/omit';
|
||||||
|
|
||||||
import LOCALIZED_FIELDS from './localizedFields';
|
import LOCALIZED_FIELDS from './localizedFields';
|
||||||
|
|
||||||
const localizedPath = ['pluginOptions', 'i18n', 'localized'];
|
const localizedPath = ['pluginOptions', 'i18n', 'localized'];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useCallback, useMemo } from 'react';
|
import React, { useCallback, useMemo } from 'react';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Box, Checkbox, Flex, Typography, Grid, GridItem } from '@strapi/design-system';
|
import { Box, Checkbox, Flex, Typography, Grid, GridItem } from '@strapi/design-system';
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { Typography, Flex, GridItem } from '@strapi/design-system';
|
import { Typography, Flex, GridItem } from '@strapi/design-system';
|
||||||
import { get, isEmpty, without } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
import without from 'lodash/without';
|
||||||
|
|
||||||
import { useUsersPermissions } from '../../contexts/UsersPermissionsContext';
|
import { useUsersPermissions } from '../../contexts/UsersPermissionsContext';
|
||||||
import BoundRoute from '../BoundRoute';
|
import BoundRoute from '../BoundRoute';
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
/* eslint-disable consistent-return */
|
/* eslint-disable consistent-return */
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { set, get, take } from 'lodash';
|
import get from 'lodash/get';
|
||||||
|
import set from 'lodash/set';
|
||||||
|
import take from 'lodash/take';
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
initialData: {},
|
initialData: {},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useCallback, useEffect, useReducer } from 'react';
|
import { useCallback, useEffect, useReducer } from 'react';
|
||||||
import { useNotification, useFetchClient } from '@strapi/helper-plugin';
|
import { useNotification, useFetchClient } from '@strapi/helper-plugin';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import init from './init';
|
import init from './init';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import { cleanPermissions } from '../../utils';
|
import { cleanPermissions } from '../../utils';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useReducer, useRef } from 'react';
|
import { useEffect, useReducer, useRef } from 'react';
|
||||||
import { request, useNotification } from '@strapi/helper-plugin';
|
import { request, useNotification } from '@strapi/helper-plugin';
|
||||||
import { get } from 'lodash';
|
import get from 'lodash/get';
|
||||||
import init from './init';
|
import init from './init';
|
||||||
import pluginId from '../../pluginId';
|
import pluginId from '../../pluginId';
|
||||||
import reducer, { initialState } from './reducer';
|
import reducer, { initialState } from './reducer';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { set } from 'lodash';
|
import set from 'lodash/set';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
formErrors: {},
|
formErrors: {},
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { sortBy } from 'lodash';
|
import sortBy from 'lodash/sortBy';
|
||||||
|
|
||||||
const createProvidersArray = (data) => {
|
const createProvidersArray = (data) => {
|
||||||
return sortBy(
|
return sortBy(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { isEmpty } from 'lodash';
|
import isEmpty from 'lodash/isEmpty';
|
||||||
|
|
||||||
const cleanPermissions = (permissions) =>
|
const cleanPermissions = (permissions) =>
|
||||||
Object.keys(permissions).reduce((acc, current) => {
|
Object.keys(permissions).reduce((acc, current) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user