Skip to content

Commit

Permalink
lint everything (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
guysopher authored Jun 13, 2023
1 parent fa46992 commit 7662ecb
Show file tree
Hide file tree
Showing 350 changed files with 5,789 additions and 8,766 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tabWidth": 2,
"useTabs": false,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120
}
4 changes: 0 additions & 4 deletions packages/blueprints/.prettierrc

This file was deleted.

120 changes: 32 additions & 88 deletions packages/blueprints/src/Blueprints.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { Layouter, ItemsHelper } from 'pro-layouts';
import {
populateWithDefaultOptions,
addPresetOptions,
dimensionsHelper,
processLayouts,
utils,
} from 'pro-gallery-lib';
import { populateWithDefaultOptions, addPresetOptions, dimensionsHelper, processLayouts, utils } from 'pro-gallery-lib';

class Blueprints {
createBlueprint({
params,
lastParams,
existingBlueprint,
blueprintManagerId,
isUsingCustomInfoElements,
}) {
createBlueprint({ params, lastParams, existingBlueprint, blueprintManagerId, isUsingCustomInfoElements }) {
// cacheBlocker
// if (this.cache[params]) return this.cache[params];

Expand All @@ -27,34 +15,23 @@ class Blueprints {

let changedParams = {};
try {
const {
container: newContainerParams,
items: newItemsParams,
options: newOptions,
} = params;
const {
container: oldContainerParams,
items: oldItemsParams,
options: oldOptions,
} = lastParams;
const { container: newContainerParams, items: newItemsParams, options: newOptions } = params;
const { container: oldContainerParams, items: oldItemsParams, options: oldOptions } = lastParams;
// getItems,options and dimesions if not supplied in params;

const { formattedItems, changed: itemsChanged } =
this.formatItemsIfNeeded(newItemsParams, oldItemsParams);
const { formattedOptions, changed: optionsChanged } =
this.formatOptionsIfNeeded(
newOptions,
oldOptions,
isUsingCustomInfoElements
);
const { formattedContainer, changed: containerChanged } =
this.formatContainerIfNeeded(
newContainerParams,
oldContainerParams,
oldOptions,
formattedOptions || existingBlueprint.options,
optionsChanged
);
const { formattedItems, changed: itemsChanged } = this.formatItemsIfNeeded(newItemsParams, oldItemsParams);
const { formattedOptions, changed: optionsChanged } = this.formatOptionsIfNeeded(
newOptions,
oldOptions,
isUsingCustomInfoElements
);
const { formattedContainer, changed: containerChanged } = this.formatContainerIfNeeded(
newContainerParams,
oldContainerParams,
oldOptions,
formattedOptions || existingBlueprint.options,
optionsChanged
);

const changed = itemsChanged || optionsChanged || containerChanged;
changedParams = { itemsChanged, optionsChanged, containerChanged };
Expand All @@ -66,8 +43,7 @@ class Blueprints {

const structure = this.createStructure(
{
formattedContainer:
formattedContainer || existingBlueprint.container,
formattedContainer: formattedContainer || existingBlueprint.container,
formattedItems: formattedItems || existingBlueprint.items,
formattedOptions: formattedOptions || existingBlueprint.options,
},
Expand All @@ -87,23 +63,17 @@ class Blueprints {
existingBlueprint.structure = structure;

// if its an infinite gallery - let the container loose
const isInfinite = utils.isHeightSetByGallery(
existingBlueprint.options
);
const isInfinite = utils.isHeightSetByGallery(existingBlueprint.options);
if (isInfinite) {
existingBlueprint.container.height =
existingBlueprint.container.galleryHeight = structure.height;
existingBlueprint.container.height = existingBlueprint.container.galleryHeight = structure.height;
}
}
} catch (error) {
console.error('Could not create blueprint, error:', error);
}

const reasons = Object.entries(this.reasons)
.reduce(
(reasons, [param, reason]) => [...reasons, `${param}: ${reason}`],
[]
)
.reduce((reasons, [param, reason]) => [...reasons, `${param}: ${reason}`], [])
.join(', ');

// return the existing or the modified existing object
Expand Down Expand Up @@ -177,19 +147,16 @@ class Blueprints {
existingItem.metaData &&
(newItem.metaData.type !== existingItem.metaData.type ||
newItem.metaData.title !== existingItem.metaData.title ||
newItem.metaData.description !==
existingItem.metaData.description)) ||
newItem.metaData.description !== existingItem.metaData.description)) ||
(newItem.metaData &&
newItem.metaData.type === 'text' &&
existingItem.metaData &&
existingItem.metaData.type === 'text' &&
(newItem.metaData.width !== existingItem.metaData.width ||
newItem.metaData.height !== existingItem.metaData.height ||
newItem.metaData.html !== existingItem.metaData.html ||
newItem.metaData.textStyle !==
existingItem.metaData.textStyle ||
newItem.metaData.editorHtml !==
existingItem.metaData.editorHtml));
newItem.metaData.textStyle !== existingItem.metaData.textStyle ||
newItem.metaData.editorHtml !== existingItem.metaData.editorHtml));
if (itemsChanged) {
this.reasons.items = `items #${idx} id was changed.`;
}
Expand All @@ -213,9 +180,7 @@ class Blueprints {
this.gettingMoreItems = false; // probably finished getting more items //TODO - what is this and how we keep it alive if needed?
changed = true;
} else if (itemsHaveChanged(items, oldItemsParams)) {
formattedItems = items.map((item) =>
Object.assign(ItemsHelper.convertDtoToLayoutItem(item))
);
formattedItems = items.map((item) => Object.assign(ItemsHelper.convertDtoToLayoutItem(item)));
this.gettingMoreItems = false; // probably finished getting more items
changed = true;
}
Expand All @@ -241,8 +206,7 @@ class Blueprints {
Object.keys(newOptions)
.sort() // sort by keys alphabetically
.forEach((key) => (newOptionsSorted[key] = newOptions[key]));
const wasChanged =
JSON.stringify(newOptionsSorted) !== JSON.stringify(oldOptionsSorted);
const wasChanged = JSON.stringify(newOptionsSorted) !== JSON.stringify(oldOptionsSorted);
if (wasChanged) {
this.reasons.options = 'options were changed.';
}
Expand All @@ -258,28 +222,15 @@ class Blueprints {
let formattedOptions;
if (optionsHaveChanged(options, oldOptions)) {
const optionsOverDefaults = populateWithDefaultOptions(options); //add default for any undefined option
formattedOptions = processLayouts(
addPresetOptions(optionsOverDefaults),
isUsingCustomInfoElements
);
formattedOptions = processLayouts(addPresetOptions(optionsOverDefaults), isUsingCustomInfoElements);
changed = true;
}

return { formattedOptions, changed };
}

formatContainerIfNeeded(
container,
lastContainer,
lastOptions,
formattedOptions,
optionsChanged
) {
const containerHasChanged = ({
newContainerParams,
oldContainerParams,
oldOptions,
}) => {
formatContainerIfNeeded(container, lastContainer, lastOptions, formattedOptions, optionsChanged) {
const containerHasChanged = ({ newContainerParams, oldContainerParams, oldOptions }) => {
if (!oldOptions || !oldContainerParams) {
this.reasons.container = 'no old container or options. ';
return true; // no old container or options (style may change container)
Expand All @@ -291,12 +242,9 @@ class Blueprints {
const containerHasChanged = {
height: utils.isHeightSetByGallery(formattedOptions) // height doesnt matter if the new gallery is going to be vertical
? false
: !!newContainerParams.height &&
newContainerParams.height !== oldContainerParams.height,
: !!newContainerParams.height && newContainerParams.height !== oldContainerParams.height,
width:
!oldContainerParams ||
(!!newContainerParams.width &&
newContainerParams.width !== oldContainerParams.width),
!oldContainerParams || (!!newContainerParams.width && newContainerParams.width !== oldContainerParams.width),
};
return Object.keys(containerHasChanged).reduce((is, key) => {
if (containerHasChanged[key]) {
Expand All @@ -323,11 +271,7 @@ class Blueprints {
container,
});
changed = true;
formattedContainer = Object.assign(
{},
container,
dimensionsHelper.getGalleryDimensions()
);
formattedContainer = Object.assign({}, container, dimensionsHelper.getGalleryDimensions());
}
return { formattedContainer, changed };
}
Expand Down
4 changes: 0 additions & 4 deletions packages/gallery/.prettierrc

This file was deleted.

6 changes: 1 addition & 5 deletions packages/gallery/eslintConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ module.exports = {
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'prettier/@typescript-eslint',
],
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'prettier/@typescript-eslint'],
ignorePatterns: ['versionLogger.js', 'standaloneValidateCode.js'],
rules: {},
};
5 changes: 1 addition & 4 deletions packages/gallery/eslintTSConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module.exports = {
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'],
rules: {},
};
9 changes: 2 additions & 7 deletions packages/gallery/src/components/gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ class Gallery extends React.Component<GalleryProps, GalleryState> {
typeof props.eventsListener === 'function' &&
props.eventsListener(GALLERY_CONSTS.events.NEED_MORE_ITEMS, from);
},
onBlueprintReady: ({
blueprint,
blueprintChanged,
initialBlueprint,
}) => {
onBlueprintReady: ({ blueprint, blueprintChanged, initialBlueprint }) => {
if (blueprintChanged) {
this.setBlueprint(blueprint, initialBlueprint);
} else {
Expand Down Expand Up @@ -64,8 +60,7 @@ class Gallery extends React.Component<GalleryProps, GalleryState> {
if (eventName === GALLERY_CONSTS.events.NEED_MORE_ITEMS) {
this.blueprintsManager.getMoreItems(eventData);
} else {
typeof eventsListener === 'function' &&
eventsListener(eventName, eventData, event);
typeof eventsListener === 'function' && eventsListener(eventName, eventData, event);
}
};
this.galleryProps = {
Expand Down
Loading

0 comments on commit 7662ecb

Please sign in to comment.