Skip to content

Commit

Permalink
Merge pull request #301 from performant-software/feature/cdc292_impor…
Browse files Browse the repository at this point in the history
…t_compare

CDC #292 - Import Compare
  • Loading branch information
dleadbetter authored Oct 9, 2024
2 parents a288298 + 717bc3f commit c78c21b
Show file tree
Hide file tree
Showing 12 changed files with 1,032 additions and 26 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"publish-beta": "node --experimental-json-modules ./scripts/publish.js --tag beta"
},
"devDependencies": {
"@babel/core": "^7.17.9",
"babel-jest": "^27.5.1",
"@babel/core": "^7.25.7",
"@babel/preset-env": "^7.25.7",
"babel-jest": "^29.7.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"eslint": "^7.1.0",
"eslint-config-airbnb": "^18.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/controlled-vocabulary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/controlled-vocabulary",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand All @@ -23,8 +23,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/semantic-components": "^2.2.15",
"@performant-software/shared-components": "^2.2.15",
"@performant-software/semantic-components": "^2.2.16",
"@performant-software/shared-components": "^2.2.16",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/core-data",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of components used with the Core Data platform.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -40,8 +40,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/geospatial": "^2.2.15",
"@performant-software/shared-components": "^2.2.15",
"@performant-software/geospatial": "^2.2.16",
"@performant-software/shared-components": "^2.2.16",
"@peripleo/maplibre": "^0.5.2",
"@peripleo/peripleo": "^0.5.2",
"react": ">= 16.13.1 < 19.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/geospatial/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/geospatial",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of components for all things map-related.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/semantic-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/semantic-components",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of shared components based on the Semantic UI Framework.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down Expand Up @@ -35,7 +35,7 @@
"zotero-translation-client": "^5.0.1"
},
"peerDependencies": {
"@performant-software/shared-components": "^2.2.15",
"@performant-software/shared-components": "^2.2.16",
"@samvera/clover-iiif": "^2.3.2",
"react": ">= 16.13.1 < 19.0.0",
"react-dnd": "^11.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/shared-components",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
40 changes: 33 additions & 7 deletions packages/shared/src/utils/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@
import _ from 'underscore';

type OptionsProps = {
emptyValues: Array<any>,
ignoreHtml: boolean
/**
* List of values to consider "empty", these values will be treated as equivalent.
*/
emptyValues?: Array<any>,

/**
* If true, HTML tags will be stripped from string values.
*/
ignoreHtml?: boolean,

/**
* If true, whitespace will be stripped from string values.
*/
ignoreWhitespace?: boolean,

/**
* If true, "empty" keys/values will be removed from objects prior to equality check.
*/
removeEmptyValues?: boolean
};

const EMPTY_VALUES = [
Expand All @@ -18,7 +35,8 @@ const EMPTY_VALUES = [
const DEFAULT_OPTIONS = {
emptyValues: EMPTY_VALUES,
ignoreHtml: true,
ignoreWhitespace: true
ignoreWhitespace: true,
removeEmptyValues: false
};

const HTML_REGEX = /(<([^>]+)>)/gi;
Expand Down Expand Up @@ -85,8 +103,16 @@ const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
}

if (a !== null && typeof a === 'object' && b !== null && typeof b === 'object') {
const aKeys = _.keys(a);
const bKeys = _.keys(b);
let aObject = a;
let bObject = b;

if (options.removeEmptyValues) {
aObject = _.omit(a, (value) => _.contains(options.emptyValues, value));
bObject = _.omit(b, (value) => _.contains(options.emptyValues, value));
}

const aKeys = _.keys(aObject);
const bKeys = _.keys(bObject);

// If the objects contain different number of keys, return false
if (aKeys.length !== bKeys.length) {
Expand All @@ -96,8 +122,8 @@ const isEqual = (a: any, b: any, userOptions: OptionsProps = {}) => {
// Recursively check each key for equality
let equal = true;

_.each(_.keys(a), (key) => {
if (!(_.has(b, key) && isEqual(a[key], b[key]))) {
_.each(_.keys(aObject), (key) => {
if (!(_.has(bObject, key) && isEqual(aObject[key], bObject[key]))) {
equal = false;
}
});
Expand Down
26 changes: 26 additions & 0 deletions packages/shared/test/utils/Object.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,30 @@ describe('isEqual', () => {

expect(ObjectUtils.isEqual(func1, func2)).toBeTruthy();
});

test('should be equal for objects with different keys with null values', () => {
const a = {
name: 'Test 123',
address: null
};

const b = {
name: 'Test 123'
};

expect(ObjectUtils.isEqual(a, b, { removeEmptyValues: true })).toBeTruthy();
});

test('should be unequal for objects with different keys with null values with removeEmptyValues "false"', () => {
const a = {
name: 'Test 123',
address: null
};

const b = {
name: 'Test 123'
};

expect(ObjectUtils.isEqual(a, b)).toBeFalsy();
});
});
6 changes: 3 additions & 3 deletions packages/user-defined-fields/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/user-defined-fields",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of components used for allowing end users to define fields on models. Use with the \"user_defined_fields\" gem.",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand All @@ -23,8 +23,8 @@
"underscore": "^1.13.2"
},
"peerDependencies": {
"@performant-software/semantic-components": "^2.2.15",
"@performant-software/shared-components": "^2.2.15",
"@performant-software/semantic-components": "^2.2.16",
"@performant-software/shared-components": "^2.2.16",
"react": ">= 16.13.1 < 19.0.0",
"react-dom": ">= 16.13.1 < 19.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/visualize",
"version": "2.2.15",
"version": "2.2.16",
"description": "A package of components used for data visualization",
"license": "MIT",
"main": "./dist/index.cjs.js",
Expand Down
2 changes: 1 addition & 1 deletion react-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"packages/user-defined-fields",
"packages/visualize"
],
"version": "2.2.15"
"version": "2.2.16"
}
Loading

0 comments on commit c78c21b

Please sign in to comment.