Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const _ = require('lodash');

const commentPropKey = 'comment';

const getDifferentItems = (newItems = [], oldItems = []) => {
const intersection = _.intersectionWith(newItems, oldItems, _.isEqual);
return {
Expand All @@ -9,25 +11,30 @@ const getDifferentItems = (newItems = [], oldItems = []) => {
};

const hydrateTableProperties = ({ new: newItems, old: oldItems }, name, commentState) => {
const hydrateProperties = properties => (properties || '').split(',').map(prop => prop.trim());
const prepareProperties = properties =>
properties
.filter(Boolean)
.map(property => property.replace(/(\S+)=([\s\S]+)/, `'$1'='$2'`))
.map(property => `'${property.tablePropKey}'='${property.tablePropValue}'`)
.join(',\n');

const isCommentChanged = !_.isEqual(commentState?.new, commentState?.old);
const addCommentProp = isCommentChanged && commentState?.new ? `comment=${commentState?.new}` : '';
const dropCommentProp = isCommentChanged && !commentState?.new ? `comment` : '';

const addCommentProp =
isCommentChanged && commentState?.new
? { tablePropKey: commentPropKey, tablePropValue: commentState?.new }
: null;

const dropCommentProp = isCommentChanged && !commentState?.new ? { tablePropKey: commentPropKey } : null;

const preparePropertiesName = properties =>
properties
.filter(Boolean)
.map(prop => `'${prop.replace(/(=\S+)/, '')}'`)
.map(prop => `'${prop.tablePropKey}'`)
.join(', ');

const newHydrateItems = hydrateProperties(newItems);
const oldHydrateItems = hydrateProperties(oldItems);
// Ensure newItems and oldItems are arrays
const newHydrateItems = Array.isArray(newItems) ? newItems : [];
const oldHydrateItems = Array.isArray(oldItems) ? oldItems : [];

const { add, drop } = getDifferentItems(newHydrateItems, oldHydrateItems);

Expand Down