Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ references:
defaults: &defaults
working_directory: ~/source
docker:
- image: circleci/node:latest
- image: cimg/node:16.20
resource_class: large

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node
node_modules
target
build
dist

2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
'<rootDir>/jest.setup.js'
],
transform: {
'^.+\\.jsx?$': 'babel-jest'
'^.+\\.[tj]sx?$': 'babel-jest'
},
moduleNameMapper: {
'\\.(gif|ttf|woff|woff2|eot|eot|svg)$': '<rootDir>/__mocks__/fileMock.js'
Expand Down
43 changes: 26 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"clean": "rm -rf packages/**/build/",
"build": "lerna run build",
"publish": "lerna --concurrency 1 run publish-script",
"lint": "eslint --ext js,jsx .",
"lint:fix": "yarn lint --fix .",
"test": "lerna --scope @jahia/test-framework run build && jest --coverage",
"lint": "lerna run lint",
"lint:fix": "lerna run lint:fix",
"test": "lerna --scope @jahia/test-framework run build && lerna run test",
"tdd": "jest --watch"
},
"husky": {
Expand All @@ -19,13 +19,16 @@
},
"license": "SEE LICENSE IN LICENSE.txt FILE",
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/cli": "^7.21.5",
"@babel/core": "^7.21.8",
"@babel/eslint-parser": "^7.21.8",
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.4.3",
"@babel/plugin-transform-runtime": "^7.21.4",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.21.5",
"@storybook/addon-actions": "^6.5.12",
"@storybook/addon-knobs": "^6.4.0",
"@storybook/addons": "^6.5.12",
Expand All @@ -35,24 +38,30 @@
"@storybook/source-loader": "^6.4.5",
"@types/history": "^4.6.2",
"@types/i18next": "^8.4.3",
"@types/react": "^16.3.14",
"@types/react": "^16",
"@types/react-dom": "^16",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"auto": "^10.37.6",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"babel-loader": "^8.0.6",
"babel-jest": "^29.5.0",
"babel-loader": "^9.1.2",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-module-resolver": "^5.0.0",
"babel-plugin-transform-dynamic-import-to-static": "^1.0.1",
"babel-plugin-transform-rename-import": "^2.3.0",
"babel-plugin-typescript-to-proptypes": "^2.1.0",
"cross-env": "^5.1.6",
"css-loader": "^6.7.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.12.1",
"enzyme-to-json": "^3.3.5",
"eslint": "^6.6.0",
"eslint-config-xo": "^0.27.2",
"eslint-config-xo-react": "^0.20.0",
"eslint-plugin-jest": "^23.0.2",
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react-hooks": "^2.2.0",
"eslint": "^8.39.0",
"eslint-config-xo": "^0.43.1",
"eslint-config-xo-react": "^0.27.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^3.0.5",
"jest": "^24.9.0",
"lerna": "^5.5.4",
Expand All @@ -63,7 +72,7 @@
"postcss-mixins": "^9.0.4",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"style-loader": "^3.3.1",
"typescript": "^5.0.4",
"uglify-js": "^3.4.9",
"yarn": "^1.15.2"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/data-helper/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react']
};
22 changes: 22 additions & 0 deletions packages/data-helper/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
setupFilesAfterEnv: [
'<rootDir>/../../jest.setup.js'
],
transform: {
'^.+\\.[tj]sx?$': 'babel-jest'
},
moduleNameMapper: {
'\\.(gif|ttf|woff|woff2|eot|eot|svg)$': '<rootDir>/__mocks__/fileMock.js'
},
modulePathIgnorePatterns: [
'build/',
'target/',
'node'
],
testPathIgnorePatterns: [
'build/',
'node_modules/',
'target/',
'node'
]
};
63 changes: 33 additions & 30 deletions packages/data-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
{
"name": "@jahia/data-helper",
"version": "1.0.8",
"scripts": {
"babel:js": "jahia-babel-js",
"babel:module": "jahia-babel-module",
"react2dts": "jahia-react2dts",
"publish-script": "jahia-publish",
"prepare-build": "jahia-prepare-build",
"build": "jahia-build",
"build-umd": "jahia-build-umd"
},
"main": "js/index.js",
"module": "esm/index.js",
"typings": "esm/index.d.ts",
"browser": "lib/react-apollo.umd.min.js",
"sideEffects": false,
"license": "SEE LICENSE IN ../../LICENSE.txt FILE",
"dependencies": {
"apollo-cache": "^1.3.4",
"apollo-client": "^2.6.8",
"apollo-utilities": "^1.3.3",
"fast-deep-equal": "^3.1.1",
"graphql": "^15.4.0",
"graphql-tag": "^2.11.0",
"lodash": "^4.17.13",
"react-apollo": "^3.1.3"
},
"peerDependencies": {
"react": "^16.12.0"
}
"name": "@jahia/data-helper",
"version": "1.0.8",
"scripts": {
"babel:js": "jahia-babel-js",
"babel:module": "jahia-babel-module",
"react2dts": "jahia-react2dts",
"publish-script": "jahia-publish",
"prepare-build": "jahia-prepare-build",
"build": "jahia-build",
"build-umd": "jahia-build-umd",
"lint": "eslint --ext js,jsx src",
"lint:fix": "yarn lint --fix",
"test": "jest --coverage"
},
"main": "js/index.js",
"module": "esm/index.js",
"typings": "esm/index.d.ts",
"browser": "lib/react-apollo.umd.min.js",
"sideEffects": false,
"license": "SEE LICENSE IN ../../LICENSE.txt FILE",
"dependencies": {
"apollo-cache": "^1.3.4",
"apollo-client": "^2.6.8",
"apollo-utilities": "^1.3.3",
"fast-deep-equal": "^3.1.1",
"graphql": "^15.4.0",
"graphql-tag": "^2.11.0",
"lodash": "^4.17.13",
"react-apollo": "^3.1.3"
},
"peerDependencies": {
"react": "^16.12.0"
}
}
16 changes: 8 additions & 8 deletions packages/data-helper/src/fragments/fragments.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ function findFragmentsInSelectionSet(selectionSet) {

function replaceFragmentsInSelectionSet(selectionSet, fragments, def, document) {
if (selectionSet && selectionSet.selections) {
let newFragmentsSpreads = [];
let removedFragmentSpreads = [];
const newFragmentsSpreads = [];
const removedFragmentSpreads = [];
// Look for all existing fragment spreads in selection set
selectionSet.selections.filter(sel => sel.kind === 'FragmentSpread').forEach(sel => {
// Handle only named fragments
if (sel.name.value) {
// Check if spread exists in current doc - if not, we replace or remove it
let existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === sel.name.value);
const existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === sel.name.value);

if (!existing) {
// First remove the spread, as it has no match in document
Expand All @@ -88,18 +88,18 @@ function replaceFragmentsInSelectionSet(selectionSet, fragments, def, document)
newFragmentsSpreads.push(newSpread);

// Add the new fragment definition in document if it has not already been added
let existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === frag.name.value);
const existing = document.definitions.find(definition => definition.kind === 'FragmentDefinition' && definition.name.value === frag.name.value);
if (!existing) {
document.definitions.push(frag);
}
});

// Adds the associated variables to the query
let allVariables = applyableFragments.reduce((result, n) => ({...result, ...n.variables}), {});
const allVariables = applyableFragments.reduce((result, n) => ({...result, ...n.variables}), {});
Object.entries(allVariables).forEach(([name, value]) => {
let existing = def.variableDefinitions.find(def => def.variable.name.value === name);
const existing = def.variableDefinitions.find(def => def.variable.name.value === name);
if (!existing) {
let type = parseType(value, {noLocation: true});
const type = parseType(value, {noLocation: true});
def.variableDefinitions.push({
kind: 'VariableDefinition',
variable: {
Expand All @@ -109,7 +109,7 @@ function replaceFragmentsInSelectionSet(selectionSet, fragments, def, document)
value: name
}
},
type: type
type
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export const useContentPreview = ({
fetchPolicy
}) => {
const variables = {
path: path,
templateType: templateType,
view: view,
contextConfiguration: contextConfiguration,
language: language,
path,
templateType,
view,
contextConfiguration,
language,
workspace: workspace.toUpperCase(),
requestAttributes: requestAttributes
requestAttributes
};

return useQuery(CONTENT_PREVIEW_QUERY, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {useContentPreview} from './index.js';

jest.mock('react-apollo', () => {
return {
useQuery: jest.fn(() => ({
data: {},
loading: false,
error: null
}))
};
});
jest.mock('react-apollo', () => ({
useQuery: jest.fn(() => ({
data: {},
loading: false,
error: null
}))
}));

import {useQuery} from 'react-apollo';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jest.mock('react', () => {
let current;

return ({
useRef: v => {
useRef(v) {
if (!current) {
current = v;
}
Expand All @@ -24,8 +24,8 @@ describe('useDeepCompareMemoize', () => {
it('should return the same value', () => {
const origValue1 = ['v1'];
const origValue2 = ['v1'];
let value1 = useDeepCompareMemoize(origValue1);
let value2 = useDeepCompareMemoize(origValue2);
const value1 = useDeepCompareMemoize(origValue1);
const value2 = useDeepCompareMemoize(origValue2);

expect(origValue1 === origValue2).toBe(false);
expect(value1 === value2).toBe(true);
Expand All @@ -34,8 +34,8 @@ describe('useDeepCompareMemoize', () => {
it('should not return the same value', () => {
const origValue1 = ['v1'];
const origValue2 = ['v2'];
let value1 = useDeepCompareMemoize(origValue1);
let value2 = useDeepCompareMemoize(origValue2);
const value1 = useDeepCompareMemoize(origValue1);
const value2 = useDeepCompareMemoize(origValue2);

expect(origValue1 === origValue2).toBe(false);
expect(value1 === value2).toBe(false);
Expand Down
14 changes: 7 additions & 7 deletions packages/data-helper/src/hooks/useNodeChecks/useNodeChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export const useNodeChecks = (variables, options, queryOptions) => {
}

const doNodeCheck = node =>
(!requiredPermissions || requiredPermissions.reduce((acc, val) => acc || node[val], false)) &&
(!requiredSitePermissions || requiredSitePermissions.reduce((acc, val) => acc || node.site[val], false)) &&
(!showOnNodeTypes || showOnNodeTypes.reduce((acc, val) => acc || node[val], false)) &&
(!hideOnNodeTypes || !hideOnNodeTypes.reduce((acc, val) => acc || node[val], false)) &&
(!requireModuleInstalledOnSite || requireModuleInstalledOnSite.reduce((acc, val) => acc && node.site.installedModulesWithAllDependencies.includes(val), true)) &&
(!hideForPaths || evaluateVisibilityPaths(false, hideForPaths, node.path || variables.path)) &&
(!showForPaths || evaluateVisibilityPaths(true, showForPaths, node.path || variables.path));
(!requiredPermissions || requiredPermissions.reduce((acc, val) => acc || node[val], false))
&& (!requiredSitePermissions || requiredSitePermissions.reduce((acc, val) => acc || node.site[val], false))
&& (!showOnNodeTypes || showOnNodeTypes.reduce((acc, val) => acc || node[val], false))
&& (!hideOnNodeTypes || !hideOnNodeTypes.reduce((acc, val) => acc || node[val], false))
&& (!requireModuleInstalledOnSite || requireModuleInstalledOnSite.reduce((acc, val) => acc && node.site.installedModulesWithAllDependencies.includes(val), true))
&& (!hideForPaths || evaluateVisibilityPaths(false, hideForPaths, node.path || variables.path))
&& (!showForPaths || evaluateVisibilityPaths(true, showForPaths, node.path || variables.path));

const result = node ? doNodeCheck(node) : nodes.reduce((acc, val) => acc && doNodeCheck(val), true);

Expand Down
Loading