Remove useless code

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2021-07-13 09:47:51 +02:00
parent 138ba1c2de
commit cf3d87d69a
8 changed files with 23 additions and 90 deletions

View File

@ -9,7 +9,6 @@ import { get } from 'lodash';
import PropTypes from 'prop-types';
import List from '../List';
import useDataManager from '../../hooks/useDataManager';
// import convertAttrObjToArray from '../../utils/convertAttrObjToArray';
import Td from '../Td';
function ComponentList({
@ -35,7 +34,6 @@ function ComponentList({
<List
customRowComponent={customRowComponent}
dzName={dzName}
// items={convertAttrObjToArray(attributes)}
items={attributes}
targetUid={component}
mainTypeName={mainTypeName}

View File

@ -22,9 +22,6 @@ import makeUnique from '../../utils/makeUnique';
import pluginId from '../../pluginId';
import FormModal from '../FormModal';
import createDataObject from './utils/createDataObject';
// import createModifiedDataSchema, {
// orderAllDataAttributesWithImmutable,
// } from './utils/createModifiedDataSchema';
import createModifiedDataSchema from './utils/createModifiedDataSchema';
import retrieveSpecificInfoFromComponents from './utils/retrieveSpecificInfoFromComponents';
import retrieveComponentsFromSchema from './utils/retrieveComponentsFromSchema';
@ -121,17 +118,9 @@ const DataManagerProvider = ({
const formattedComponents = formatSchemas(components);
const contentTypes = createDataObject(contentTypesArray);
const formattedContentTypes = formatSchemas(contentTypes);
// const orderedComponents = orderAllDataAttributesWithImmutable({
// components,
// });
// const orderedContenTypes = orderAllDataAttributesWithImmutable({
// components: contentTypes,
// });
dispatch({
type: GET_DATA_SUCCEEDED,
// components: orderedComponents.get('components'),
// contentTypes: orderedContenTypes.get('components'),
components: formattedComponents,
contentTypes: formattedContentTypes,
reservedNames,
@ -415,15 +404,12 @@ const DataManagerProvider = ({
isInContentTypeView
);
// const dataShape = orderAllDataAttributesWithImmutable(newSchemaToSet, isInContentTypeView);
const hasJustCreatedSchema =
get(schemaToSet, 'isTemporary', false) &&
size(get(schemaToSet, 'schema.attributes', [])) === 0;
dispatch({
type: SET_MODIFIED_DATA,
// schemaToSet: dataShape,
schemaToSet: newSchemaToSet,
hasJustCreatedSchema,
});

View File

@ -1,3 +1,8 @@
/**
* Creates an object of content types from an array
* @params {Object[]} arr array of content types
* @returns {Object} an object of content types
*/
const createDataObject = arr =>
arr.reduce((acc, current) => {
acc[current.uid] = current;

View File

@ -1,6 +1,13 @@
// import { fromJS, OrderedMap } from 'immutable';
import get from 'lodash/get';
/**
*
* @params {Object} contentTypeSchema
* @params {Object[]} retrievedComponents array of components that are used in the content type
* @params {Object} allComponentsSchema All app's components
* @params {Boolean} isInContentTypeView
* @returns {Object} The modifiedData to set in the reducer
*/
const createModifiedDataSchema = (
contentTypeSchema,
retrievedComponents,
@ -23,52 +30,4 @@ const createModifiedDataSchema = (
return schema;
};
// const orderAllDataAttributesWithImmutable = (allDataSchema, isInContentTypeView) => {
// const attributesPath = ['schema', 'attributes'];
// const componentsSchema = allDataSchema.components;
// const componentsWithImmutableSchema = Object.keys(componentsSchema).reduce((acc, current) => {
// const currentSchema = get(componentsSchema, [current], {});
// const currentAttributes = get(currentSchema, attributesPath, {});
// const fromJSAttributes = Object.keys(currentAttributes).reduce((acc, current) => {
// acc[current] = fromJS(currentAttributes[current]);
// return acc;
// }, {});
// // TODO refacto
// const currentImmutableSchemas = fromJS(currentSchema).setIn(
// ['schema', 'attributes'],
// fromJS(OrderedMap(fromJSAttributes))
// );
// acc[current] = fromJS(currentImmutableSchemas);
// return acc;
// }, {});
// const keyName = isInContentTypeView ? 'contentType' : 'component';
// const mainSchema = get(allDataSchema, [keyName], {});
// const mainImmutableSchema = fromJS(mainSchema).setIn(
// attributesPath,
// fromJS(
// OrderedMap(
// Object.keys(get(mainSchema, attributesPath, {})).reduce((acc, current) => {
// acc[current] = fromJS(get(mainSchema, [...attributesPath, current], {}));
// return acc;
// }, {})
// )
// )
// );
// const immutableData = fromJS({
// components: componentsWithImmutableSchema,
// [keyName]: mainImmutableSchema,
// });
// return immutableData;
// };
export default createModifiedDataSchema;
// export { orderAllDataAttributesWithImmutable };

View File

@ -1,3 +1,8 @@
/**
* Format the attributes to array instead of an object
* @params {Object} schemas The content types schema
* @returns {Object} The formatted content types
*/
const formatSchemas = schemas => {
return Object.keys(schemas).reduce((acc, current) => {
const schema = schemas[current].schema;
@ -11,6 +16,11 @@ const formatSchemas = schemas => {
}, {});
};
/**
*
* @params {Object} Object of attributes
* @returns {Object[]} An array of attributes
*/
const toAttributesArray = attributes => {
return Object.keys(attributes).reduce((acc, current) => {
acc.push({ ...attributes[current], name: current });

View File

@ -25,19 +25,6 @@ const data = {
max: 5,
},
],
// attributes: {
// title: {
// type: 'string',
// required: true,
// },
// slide: {
// component: 'default.slide',
// type: 'component',
// repeatable: true,
// min: 1,
// max: 5,
// },
// },
},
},
'default.dish': {

View File

@ -6,8 +6,6 @@ import { BackHeader, ListWrapper, useTracking } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
import { Header } from '@buffetjs/custom';
import ListViewContext from '../../contexts/ListViewContext';
// import convertAttrObjToArray from '../../utils/convertAttrObjToArray';
// import convertAttrObjToArray from '../../utils/convertAttrObjToArray';
import getAttributeDisplayedType from '../../utils/getAttributeDisplayedType';
import pluginId from '../../pluginId';
import getTrad from '../../utils/getTrad';
@ -60,8 +58,6 @@ const ListView = () => {
const attributes = get(modifiedData, mainDataTypeAttributesPath, []);
const attributesLength = attributes.length;
// const attributes = get(modifiedData, mainDataTypeAttributesPath, {});
// const attributesLength = Object.keys(attributes).length;
const currentDataName = get(initialData, [firstMainDataPath, 'schema', 'name'], '');
const isFromPlugin = has(initialData, [firstMainDataPath, 'plugin']);
const hasModelBeenModified = !isEqual(modifiedData, initialData);
@ -305,7 +301,6 @@ const ListView = () => {
<ListWrapper style={{ marginBottom: 80 }}>
<ListHeader actions={listActions} title={listTitle} />
<List
// items={convertAttrObjToArray(attributes)}
items={attributes}
customRowComponent={props => <CustomRow {...props} />}
addComponentToDZ={handleClickAddComponentToDZ}

View File

@ -1,7 +0,0 @@
const convertAttrObjToArray = attributes => {
return Object.keys(attributes).map((key, index) => {
return { ...attributes[key], name: key, index };
});
};
export default convertAttrObjToArray;