Skip to content

Commit

Permalink
IBX-9109: Enabling TypeScript (ts-loader) with Webpack Encore
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Nov 14, 2024
1 parent 4ad571d commit 103b255
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
4 changes: 4 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recipesEndpoint": "https://api.github.com/repos/ibexa/recipes-dev/contents/index.json?ref=flex/pull-145",
"packages": []
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"prettier": "eslint-config-ibexa/prettier",
"dependencies": {},
"devDependencies": {
"eslint-config-ibexa": "https://github.com/ibexa/eslint-config-ibexa.git#~v1.1.1"
"eslint-config-ibexa": "https://github.com/ibexa/eslint-config-ibexa.git#IBX-9109-enabling-typescript"
},
"scripts": {
"test": "yarn prettier-test && yarn eslint-test",
"fix": "yarn prettier-test --write && yarn eslint-test --fix",
"eslint-test": "eslint \"./src/bundle/Resources/**/*.js\" \"./src/bundle/ui-dev/**/*.js\"",
"prettier-test": "yarn prettier \"./src/bundle/Resources/**/*.{js,scss}\" \"./src/bundle/ui-dev/**/*.js\" --check"
"eslint-test": "eslint \"./src/bundle/Resources/**/*.{js,ts}\" \"./src/bundle/ui-dev/**/*.{js,tsx}\"",
"prettier-test": "yarn prettier \"./src/bundle/Resources/**/*.{js,ts,scss}\" \"./src/bundle/ui-dev/**/*.{js,tsx}\" --check"
}
}
1 change: 1 addition & 0 deletions src/bundle/Resources/encore/ibexa.config.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
module.exports = (Encore) => {
Encore.addAliases({
'@ibexa-admin-ui': path.resolve('./vendor/ibexa/admin-ui'),
'@ibexa-admin-ui-helpers': path.resolve('./vendor/ibexa/admin-ui/src/bundle/Resources/public/js/scripts/helpers'),
'@ibexa-admin-ui-modules': path.resolve('./vendor/ibexa/admin-ui/src/bundle/ui-dev/src/modules'),
});
};
2 changes: 1 addition & 1 deletion src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ module.exports = (Encore) => {
path.resolve(__dirname, '../public/js/scripts/button.content.edit.js'),
path.resolve(__dirname, '../public/js/scripts/admin.search.filters.js'),
path.resolve(__dirname, '../public/js/scripts/admin.search.sorting.js'),
path.resolve(__dirname, '../public/js/scripts/admin.search.js'),
path.resolve(__dirname, '../public/ts/admin.search.ts'),
path.resolve(__dirname, '../public/js/scripts/udw/select.location.js'),
path.resolve(__dirname, '../public/js/scripts/button.translation.edit.js'),
])
Expand Down
28 changes: 28 additions & 0 deletions src/bundle/Resources/public/ts/admin.search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function (document: Document) {
const searchForm = document.querySelector<HTMLFormElement>('.ibexa-search-form');
const searchInput = document.querySelector<HTMLInputElement>('.ibexa-search-form__search-input');
const headerSearchInput = document.querySelector<HTMLInputElement>('.ibexa-global-search__input');
const languageSelector = document.querySelector<HTMLSelectElement>('.ibexa-filters__item--language-selector .ibexa-filters__select');
const headerSearchSubmitBtn = document.querySelector<HTMLButtonElement>(
'.ibexa-main-header .ibexa-input-text-wrapper__action-btn--search',
);

if (!headerSearchInput || !searchInput || !searchForm) {
return;
}

const submitForm = () => {
searchInput.value = headerSearchInput.value;
searchForm.submit();
};
const handleHeaderSearchBtnClick = (event: MouseEvent) => {
event.preventDefault();

submitForm();
};

headerSearchInput.value = searchInput.value;

headerSearchSubmitBtn?.addEventListener('click', handleHeaderSearchBtnClick, false);
languageSelector?.addEventListener('change', submitForm, false);
})(document);
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';

import Icon from '../icon/icon';

const Thumbnail = ({ thumbnailData, iconExtraClasses, contentTypeIconPath }) => {
const renderContentTypeIcon = () => {
interface ThumbnailProps {
thumbnailData: {
mimeType: string;
resource: string;
};
iconExtraClasses?: string;
contentTypeIconPath?: string;
}

const Thumbnail = ({ thumbnailData, iconExtraClasses, contentTypeIconPath }: ThumbnailProps) => {
const renderContentTypeIcon = (): JSX.Element | null => {
if (!contentTypeIconPath) {
return null;
}
Expand Down Expand Up @@ -32,18 +39,4 @@ const Thumbnail = ({ thumbnailData, iconExtraClasses, contentTypeIconPath }) =>
);
};

Thumbnail.propTypes = {
thumbnailData: PropTypes.shape({
mimeType: PropTypes.string.isRequired,
resource: PropTypes.string.isRequired,
}).isRequired,
iconExtraClasses: PropTypes.string,
contentTypeIconPath: PropTypes.string,
};

Thumbnail.defaultProps = {
iconExtraClasses: null,
contentTypeIconPath: null,
};

export default Thumbnail;

0 comments on commit 103b255

Please sign in to comment.