Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-1007: [Admin UI] As a developer I want to have js code style used in code #336

Merged
merged 14 commits into from
Mar 1, 2022
33 changes: 1 addition & 32 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
{
"plugins": ["react"],
"extends": ["eslint:recommended", "plugin:react/recommended"],
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module",
"ecmaVersion": 9
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn",
"no-extra-semi": "error",
"no-extra-boolean-cast": "off",
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"jsx-quotes": ["error", "prefer-double"],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"eqeqeq": ["error", "always"],
"indent": ["error", 4]
}
"extends": "eslint-config-ibexa"
}
26 changes: 26 additions & 0 deletions .github/workflows/frontend-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Frontend build

on:
push:
paths:
- "**.js"
branches:
- main
- '[0-9]+.[0-9]+'
pull_request:
paths:
- "**.js"

jobs:
frontend-test:
name: Frontend build test
runs-on: "ubuntu-20.04"
timeout-minutes: 5

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: yarn install
- run: yarn test
10 changes: 0 additions & 10 deletions .prettierrc

This file was deleted.

40 changes: 11 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
{
"name": "PlatformAdminUIBundle",
"version": "1.0.0",
"description": "Platform Admin UI Bundle",
"repository": "https://github.com/ezsystems/ezplatform-admin-ui.git",
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-scripts": "1.0.13",
"alloyeditor": "^1.4"
},
"devDependencies": {
"babel": "^6.23.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-react-remove-prop-types": "^0.4.8",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"clean-webpack-plugin": "^0.1.16",
"css-loader": "^0.28.5",
"eslint-plugin-react": "^7.3.0",
"prop-types": "^15.5.10",
"style-loader": "^0.18.2",
"uglifyjs-webpack-plugin": "^0.4.6",
"webpack": "^3.5.5"
},
"scripts": {
"componentize": "webpack"
}
"name": "admin-ui",
"repository": "[email protected]:ibexa/admin-ui.git",
"private": true,
"dependencies": {},
"devDependencies": {
"eslint-config-ibexa": "https://github.com/ibexa/eslint-config-ibexa.git"
},
"scripts": {
"test": "yarn eslint-test",
"eslint-test": "eslint \"./src/bundle/Resources/**/*.js\" \"./src/bundle/ui-dev/**/*.js\""
}
}
1 change: 0 additions & 1 deletion src/bundle/Resources/encore/ibexa.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const addJSEntries = require('./ibexa.js.config.js');
const addCSSEntries = require('./ibexa.css.config.js');

Expand Down
6 changes: 3 additions & 3 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,17 @@ module.exports = (Encore) => {
path.resolve(__dirname, '../../ui-dev/src/modules/universal-discovery/content.meta.preview.module.js'),
path.resolve(
__dirname,
'../../ui-dev/src/modules/universal-discovery/components/content-create-button/content.create.button.js'
'../../ui-dev/src/modules/universal-discovery/components/content-create-button/content.create.button.js',
),
path.resolve(
__dirname,
'../../ui-dev/src/modules/universal-discovery/components/content-edit-button/selected.item.edit.button.js'
'../../ui-dev/src/modules/universal-discovery/components/content-edit-button/selected.item.edit.button.js',
),
path.resolve(__dirname, '../../ui-dev/src/modules/universal-discovery/components/sort-switcher/sort.switcher.js'),
path.resolve(__dirname, '../../ui-dev/src/modules/universal-discovery/components/view-switcher/view.switcher.js'),
path.resolve(
__dirname,
'../../ui-dev/src/modules/universal-discovery/components/tree-item-toggle-selection/tree.item.toggle.selection.js'
'../../ui-dev/src/modules/universal-discovery/components/tree-item-toggle-selection/tree.item.toggle.selection.js',
),
])
.addEntry('ibexa-admin-ui-mfu-js', [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa) {
(function (global, doc) {
const scrollOffset = 300;
const formContainerNode = doc.querySelector('.ibexa-edit-content');
const allSections = [...doc.querySelectorAll('.ibexa-anchor-navigation-sections__section')];
Expand All @@ -17,7 +17,7 @@
const navigateTo = (event) => {
const { anchorTargetSectionId } = event.currentTarget.dataset;
const targetSection = [...doc.querySelectorAll('.ibexa-anchor-navigation-sections__section')].find(
(section) => section.dataset.anchorSectionId == anchorTargetSectionId
(section) => section.dataset.anchorSectionId === anchorTargetSectionId,
);

if (isVerticalScrollVisible()) {
Expand Down Expand Up @@ -51,4 +51,4 @@
}
});
}
})(window, window.document, window.ibexa);
})(window, window.document);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc) {
(function (global, doc) {
const togglers = doc.querySelectorAll('.ibexa-card__body-display-toggler');
const toggleFieldTypeView = (event) => {
event.preventDefault();
Expand Down
8 changes: 4 additions & 4 deletions src/bundle/Resources/public/js/scripts/admin.content.edit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa, Translator) {
(function (global, doc, ibexa, Translator, moment) {
const ENTER_KEY_CODE = 13;
const SIMPLIFIED_MESSAGE_TIMEOUT = 3000;
const STATUS_ERROR = 'error';
Expand Down Expand Up @@ -97,10 +97,10 @@
const isFormValid = (btn) => {
const validators = ibexa.fieldTypeValidators;
const validationResults = validators.map(getValidationResults);
const isFormValid = validationResults.every((result) => result.isValid);
const isValid = validationResults.every((result) => result.isValid);
const invalidSections = validators.map(getInvalidSections);

if (isFormValid) {
if (isValid) {
btn.dataset.isFormValid = 1;

return true;
Expand Down Expand Up @@ -236,4 +236,4 @@
menuButtonsToValidate.forEach((btn) => {
btn.addEventListener('click', validateHandler, false);
});
})(window, window.document, window.ibexa, window.Translator);
})(window, window.document, window.ibexa, window.Translator, window.moment);
6 changes: 3 additions & 3 deletions src/bundle/Resources/public/js/scripts/admin.content.tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

contentTreeContainer.style.width = null;
}
};
const renderTree = () => {
ReactDOM.render(
React.createElement(ibexa.modules.ContentTree, {
Expand All @@ -25,9 +25,9 @@
rootLocationId: parseInt(treeRootLocationId, 10),
restInfo: { token, siteaccess },
}),
contentTreeRootElement
contentTreeRootElement,
);
}
};

doc.body.addEventListener('ibexa-tb-rendered', removeContentTreeContainerWidth);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa, Routing) {
(function (global, doc, ibexa, Routing) {
const copyButtons = doc.querySelectorAll('.ibexa-btn--copy-content-type');
const copyContentType = ({ currentTarget }) => {
const contentTypeCopyForm = doc.querySelector('form[name="content_type_copy"]');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa, Routing, Translator) {
(function (global, doc, ibexa, Routing, Translator) {
const TIMEOUT_REMOVE_PLACEHOLDERS = 1500;
const SELECTOR_INPUTS_TO_VALIDATE = '.ibexa-input[required]:not([disabled]):not([hidden])';
let targetContainer = null;
Expand Down Expand Up @@ -37,7 +37,7 @@
contentType: 'application/vnd.ibexa.api.ContentTypeFieldDefinitionReorder+json',
},
};
const popupMenu = new ibexa.core.PopupMenu({
new ibexa.core.PopupMenu({
popupMenuElement,
triggerElement: addGroupTriggerBtn,
onItemClick: (event) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa, React, ReactDOM) {
(function (global, doc, ibexa, React, ReactDOM) {
const SELECTOR_RESET_STARTING_LOCATION_BTN = '.ibexa-btn--reset-starting-location';
const resetStartingLocationBtns = doc.querySelectorAll(SELECTOR_RESET_STARTING_LOCATION_BTN);
const udwBtns = doc.querySelectorAll('.ibexa-btn--udw-relation-default-location');
Expand Down Expand Up @@ -36,7 +36,7 @@
multiple: false,
...config,
}),
udwContainer
udwContainer,
);
};
const toggleResetStartingLocationBtn = (button, isEnabled) => {
Expand Down Expand Up @@ -74,7 +74,7 @@
removeLocationBtns.forEach((btn) => btn.addEventListener('click', resetStartingLocation, false));
});
},
false
false,
);

resetStartingLocationBtns.forEach((btn) => btn.addEventListener('click', resetStartingLocation, false));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc) {
(function (global, doc) {
const SELECTOR_TEMPLATE = '.ezselection-settings-option-value-prototype';
const SELECTOR_OPTION = '.ezselection-settings-option-value';
const SELECTOR_OPTIONS_LIST = '.ezselection-settings-option-list';
Expand Down Expand Up @@ -45,6 +45,6 @@
}
});
},
false
false,
);
})(window, window.document);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa) {
(function (global, doc, ibexa) {
const adapatItemsContainer = doc.querySelector('.ibexa-context-menu');

if (!adapatItemsContainer) {
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/js/scripts/admin.dropdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc, ibexa) {
(function (global, doc, ibexa) {
const dropdowns = doc.querySelectorAll('.ibexa-dropdown:not(.ibexa-dropdown--custom-init)');

dropdowns.forEach((dropdownContainer) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc) {
(function (global, doc) {
const autosubmit = (event) => {
const form = event.target.closest('form');

Expand Down
76 changes: 11 additions & 65 deletions src/bundle/Resources/public/js/scripts/admin.format.date.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function(moment) {
(function (moment) {
/*
([yqLdDeEcaZ])\1* -> find any pattern of one or repeated one of these characters
or
\'([^\']|(\'\'))*\' -> find any string in ' ' quotes
*/
const formatICUEx = /([yqLdDeEcaZ])\1*|\'([^\']|(\'\'))*\'/g;
const formatICUEx = /([yqLdDeEcaZ])\1*|'([^']|(''))*'/g;
/*
Allowed formats:
y, yy, yyyy, Y, YY, YYYY,
Expand Down Expand Up @@ -54,74 +54,20 @@
ZZZ: 'ZZ',
ZZZZ: 'Z',
};
const formatPHPEx = /[dDjlNSwzWFmMntLoYyaABgGhHisueIOPTZcrU]/g;
const formatPHPMap = {
d: 'DD',
D: 'ddd',
j: 'D',
l: 'dddd',
N: 'E',
S: function() {
return `[${this.format('Do').replace(/\d*/g, '')}]`;
},
w: 'd',
z: function() {
return this.format('DDD') - 1;
},
W: 'W',
F: 'MMMM',
m: 'MM',
M: 'MMM',
n: 'M',
t: function() {
return this.daysInMonth();
},
L: function() {
return this.isLeapYear() ? 1 : 0;
},
o: 'GGGG',
Y: 'YYYY',
y: 'YY',
a: 'a',
A: 'A',
B: function() {
var thisUTC = this.clone().utc(),
swatch = ((thisUTC.hours() + 1) % 24) + thisUTC.minutes() / 60 + thisUTC.seconds() / 3600;
return Math.floor((swatch * 1000) / 24);
},
g: 'h',
G: 'H',
h: 'hh',
H: 'HH',
i: 'mm',
s: 'ss',
u: '[u]',
e: '[e]',
I: function() {
return this.isDST() ? 1 : 0;
},
O: 'ZZ',
P: 'Z',
T: '[T]',
Z: function() {
return parseInt(this.format('ZZ'), 10) * 36;
},
c: 'YYYY-MM-DD[T]HH:mm:ssZ',
r: 'ddd, DD MMM YYYY HH:mm:ss ZZ',
U: 'X',
};

const formatEscapedString = function(icuStr) {
if (icuStr === '\'\'') {
return '[\']';
const formatEscapedString = function (icuStr) {
// eslint-disable-next-line quotes
if (icuStr === "''") {
return "[']"; // eslint-disable-line quotes
}

return icuStr.replace(/\'(.*)\'/g, '[$1]').replace(/\'\'/g, '\'');
}
return icuStr.replace(/'(.*)'/g, '[$1]').replace(/''/g, "'"); // eslint-disable-line quotes
};

moment.fn.formatICU = function(format) {
moment.fn.formatICU = function (format) {
const form = format.replace(formatICUEx, (icuStr) => {
if (icuStr[0] === '\'') {
// eslint-disable-next-line quotes
if (icuStr[0] === "'") {
return formatEscapedString(icuStr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/js/scripts/admin.input.text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(global, doc) {
(function (global, doc) {
const clearText = (event) => {
const inputWrapper = event.target.closest('.ibexa-input-text-wrapper');
const textInput = inputWrapper.querySelector('.ibexa-input--text');
Expand Down
Loading