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

UHF-7791: Add react search and typescript support #508

Merged
merged 64 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
44e2dc5
UHF-7791: rudimentary typescript environment added to HDS. WIP: HDS-r…
sakkelaaksonen-siili Dec 20, 2022
2cc243f
UHF-7791: dev html file that shows current build file.
sakkelaaksonen-siili Dec 20, 2022
b72d27d
UHF-7791: add jest rules from linkedevents repo. heavy WIP
sakkelaaksonen-siili Dec 20, 2022
6f1afa2
UHF-7791: add babel/react loader config for non-typescript react code
sakkelaaksonen-siili Dec 20, 2022
34d25fb
UHF-7791: fixed conflicting peerdeps in hds-react by local override.
sakkelaaksonen-siili Dec 20, 2022
991d714
UHF-7791: linkedevents demo build
sakkelaaksonen-siili Dec 20, 2022
770e269
UHF-7791: added cart components. updated folder name. added tsconfig …
sakkelaaksonen-siili Dec 21, 2022
4d2891f
UHF-7791: UHF-7791: add library config and paragraph preprocess.
Jussiles Dec 21, 2022
66d631d
UHF-7791: fix preprocess function naming.
Jussiles Dec 21, 2022
b99b55a
UHF-7791: WIP: Implementing new card component
sakkelaaksonen-siili Dec 21, 2022
7b2ee8c
UHF-7791: UHF-7791: Add styles from UHF-3128. Fixes.
Jussiles Dec 22, 2022
f5d53ef
UHF-7791: UHF-7791: add dist.
Jussiles Dec 22, 2022
e7bf66a
UHF-7791: UHF-7791: add dist.
Jussiles Dec 22, 2022
5f0fa86
UHF-7791: Wip: card component refactoring
sakkelaaksonen-siili Dec 22, 2022
e885e01
UHF-7791: WIP: named attributes to different meta rows to reduce dupl…
sakkelaaksonen-siili Dec 22, 2022
ec78e7b
UHF-7791: remove test file hello.jsx.
sakkelaaksonen-siili Dec 22, 2022
b3f5f29
UHF-7791: UHF-7791: cleaning and add html-react-parser package.
Jussiles Jan 4, 2023
72c246c
UHF-7791: UHF-7791: add dist.
Jussiles Jan 4, 2023
7a535ec
UHF-7791: UHF-7791: fixing and cleaning card tpls and styles
Jussiles Jan 4, 2023
990ec24
UHF-7791: UHF-7791: fix php coding style.
Jussiles Jan 5, 2023
952f3f3
UHF-7791: UHF-7791: add component library back.
Jussiles Jan 5, 2023
2555e2b
UHF-7791: UHF-7791: cleaning.
Jussiles Jan 5, 2023
d54ffe7
UHF-7791: UHF-7791: update readme. Add html parsing.
Jussiles Jan 5, 2023
9941a59
UHF-7791: Merge main into UHF-7791-tsconfig.
Jussiles Jan 5, 2023
dc37698
UHF-7791: UHF-7791: change folder structure.
Jussiles Jan 5, 2023
fbeb9d9
UHF-7791: UHF-7791: add tsconfig paths also to webpackconfig.
Jussiles Jan 9, 2023
3178cae
UHF-7791: UHF-7791: move types under common types. Add ts paths to im…
Jussiles Jan 9, 2023
5825790
UHF-7791: UHF-7791: add eslint rules for typescript.
Jussiles Jan 9, 2023
758c2e4
UHF-7791: UHF-7791: fixed based on new linting rules.
Jussiles Jan 9, 2023
36f4e5f
UHF-7791: UHF-7791: add lint-staged rule also for jsx and ts files.
Jussiles Jan 9, 2023
7cb5b47
UHF-7791: UHF-7791: lint fix and dist.
Jussiles Jan 9, 2023
44a7420
UHF-7791: UHF-7791: clean
Jussiles Jan 9, 2023
9b85d42
UHF-7791: UHF-7791: update readme.
Jussiles Jan 9, 2023
fcaebc2
UHF-7791: UHF-7791: update eslintrc.
Jussiles Jan 10, 2023
8fd2b2b
UHF-7791: UHF-7791: better comments.
Jussiles Jan 11, 2023
a990220
UHF-7791: UHF-7791: don't show form if theres no filters.
Jussiles Jan 11, 2023
747a167
UHF-7791: UHF-6916: add event count.
Jussiles Jan 11, 2023
df736c2
UHF-7791: UHF-7791: see all button. Todos for data attributes.
Jussiles Jan 11, 2023
c0e054d
UHF-7791: UHF-7791: modify api urls and see all button.
Jussiles Jan 12, 2023
07df1ad
UHF-7791: UHF-7791: add styles for container.
Jussiles Jan 12, 2023
a4c2f17
UHF-7791: UHF-7791: modify filter styles.
Jussiles Jan 12, 2023
825da0f
UHF-7791: UHF-7791: start using HDS loading spinner.
Jussiles Jan 12, 2023
03fdfbc
UHF-7791: UHF-6916: fix event count and page size.
Jussiles Jan 13, 2023
0d90a4b
UHF-7791: UHF-7791: move some types back under the app.
Jussiles Jan 13, 2023
2cd1ad6
UHF-7791: UHF-7791: add jotai package for state handling.
Jussiles Jan 13, 2023
d27912d
UHF-7791: UHF-7791: add enums and types.
Jussiles Jan 13, 2023
de78580
UHF-7791: UHF-7791: add store.
Jussiles Jan 13, 2023
99ae408
UHF-7791: UHF-7791: add pagination components
Jussiles Jan 13, 2023
41dd90d
UHF-7791: Fix event count / pagination page numbers
jeremysteerio Jan 17, 2023
63f4e84
UHF-7791: Fix broken components in event search
jeremysteerio Jan 23, 2023
d4bb671
UHF-7791: Only show submit button if any filter are present
jeremysteerio Jan 26, 2023
939db66
UHF-7791: UHF-7791: Fix styles based on comments.
Jussiles Jan 30, 2023
4987803
UHF-7791: UHF-7791: Merge main into UHF-7791-tsconfig. Fix conflicts …
Jussiles Jan 30, 2023
1beef23
UHF-7791: UHF-7791: add comment what index.html is for.
Jussiles Jan 30, 2023
75b806b
UHF-7791: UHF-7791: update luxon and hds packages.
Jussiles Jan 31, 2023
f312941
UHF-7791: UHF-7791: add heading level check.
Jussiles Jan 31, 2023
ee6aeee
UHF-7791: UHF-7791: fix styles.
Jussiles Jan 31, 2023
87074a2
UHF-7791: UHF-7791: replace hds icons with own icon component.
Jussiles Jan 31, 2023
f325c45
UHF-7791: UHF-7791: simplify result rendering. Fix 0 in empty result.
Jussiles Jan 31, 2023
3aa095f
UHF-7791: UHF-7791: fix styles and coding style.
Jussiles Feb 1, 2023
0f674bc
UHF-7791: UHF-7791: add common pagination.
Jussiles Feb 1, 2023
ecc0dfe
UHF-7791: UHF-7791: enhancements.
Jussiles Feb 1, 2023
def43b2
UHF-7791: UHF-7791: start using aria-labelledby with icons.
Jussiles Feb 2, 2023
97641d5
UHF-7791: Merge main into UHF-7791. Fix conficts.
Jussiles Feb 2, 2023
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
4 changes: 4 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-react"],
"plugins": ["@babel/plugin-syntax-jsx"]
}
94 changes: 81 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
"node": true,
"es6": true
},


"extends": [
"airbnb-base",
// "plugin:prettier/recommended",
"prettier"
// "drupal"
// "plugin:yml/recommended"
],

"extends": [
"airbnb",
"prettier"
],
"parserOptions": {
"ecmaVersion": 2020
},
// "plugins": ["prettier"],
"globals": {
"Drupal": true,
"drupalSettings": true,
Expand All @@ -38,7 +31,6 @@
"rules": {
// "prettier/prettier": "error",
"prefer-arrow-callback":["off"],

"quotes": ["warn", "single"],
"semi": ["error", "always"],
"consistent-return": ["off"],
Expand Down Expand Up @@ -74,5 +66,81 @@
"react": {
"version": "17.x"
}
}
},
// Using ts overrides rules from eslint-config-react-app.
// Finetune these if needed.
"overrides": [
{
"files": ["*.ts?(x)"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
},
// typescript-eslint specific options
"warnOnUnsupportedTypeScriptVersion": true
},
"plugins": ["@typescript-eslint"],
// If adding a typescript-eslint version of an existing ESLint rule,
// make sure to disable the ESLint rule here.
"rules": {
// TypeScript"s `noFallthroughCasesInSwitch` option is more robust (#6906)
"default-case": "off",
// "tsc" already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
"no-dupe-class-members": "off",
// "tsc" already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477)
"no-undef": "off",
// Add TypeScript specific rules (and turn off ESLint equivalents)
"no-array-constructor": "off",
"no-redeclare": "off",
"no-use-before-define": "off",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/no-array-constructor": "warn",
"@typescript-eslint/no-redeclare": "warn",
"@typescript-eslint/no-use-before-define": [
"warn",
{
"functions": false,
"classes": false,
"variables": false,
"typedefs": false
}
],
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": [
"error",
{
"allowShortCircuit": true,
"allowTernary": true,
"allowTaggedTemplates": true
}
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "none",
"ignoreRestSiblings": true
}
],
"no-useless-constructor": "off",
"no-console": ["warn", { "allow": ["warn", "error"] }],
"camelcase": "off",
"@typescript-eslint/no-useless-constructor": "warn",
"react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx", ".tsx"] }],
"react/require-default-props": "off",
"react/jsx-props-no-spreading": "off",
"react/no-array-index-key": "off",
"react/function-component-definition": [1, { "namedComponents": ["arrow-function", "function-declaration"] }],
"react/self-closing-comp": 0,
"import/extensions": 0,
"import/no-unresolved": 0,
// These rules are not needed with react 17 JSX transform.
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off"
}
}
]
}
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# HDBT-theme

## Introduction

HDBT theme is a base theme for the City of Helsinki. It is based on the core theme stable9. The abbrevation comes from
Expand All @@ -21,7 +20,7 @@ Requirements for developing:
| nvm use | Uses correct Node version chosen for the theme compiler. |
| npm i | Install dependencies and link local packages. |
| npm ci | Install a project with a clean slate. Use especially in travis like environments. |
| npm run dev | Compile styles for development environment. and watch file changes. |
| npm run dev | Compile styles and js for development environment. and watch file changes. |
| npm run build | Build packages for production. Minify CSS/JS. |

Setup the developing environment by running
Expand Down Expand Up @@ -53,6 +52,27 @@ hdbt
└───icons
```

## Webpack entries

Any .js file in /src/js/ will be compiled to separate entry and minified into the /dist folder.
Typescript entrypoints must be added separately. See webpack.config.js.


### How to use entries in Drupal libraries

```
component-library:
version: 1.x
css:
theme:
dist/css/component-library.min.css: {}
js:
dist/js/component-library.min.js: {}
```

Library must be loaded on the page where it's used.
It can be added via preprocess function or in a twig template.

## Component library

Ready to use components can be explored from component library.
Expand Down Expand Up @@ -171,6 +191,17 @@ To fix
vendor/bin/phpcbf public/themes/contrib/hdbt --extensions=php,module,theme,inc --ignore="*.js,*.css" --standard=Drupal
```

### How to develop React apps

Add new REACT_SEARCHES entrypoint into webpack.config.js.

Add new library to libraries.yml file.

Inside Drupal: Load correct Drupal library to the page. Run `npm run dev` and make sure caches are disabled.
Outside Drupal: Open React app index.html file in browser and run `npm run dev`.

To build minified js file into the /dist folder run `npm run build`.

## Component documentation

### Accordion paragraph
Expand All @@ -190,8 +221,8 @@ it on the block layout, make sure that there is a block with the correct id on t

## ESLint

We are using the airbnb-base which will be changed to full airbnb when there is react stuff.
The current eslint config is the bare minimum that should pass always everywhere. Extend as necessary.
We are using the airbnb. The current eslint config is the bare minimum that should pass always everywhere.
Extend as necessary.

### Why is it so hard?
- the eslint rules might be used from root (or beyond root) due to husky being funny
Expand Down
4 changes: 2 additions & 2 deletions dist/css/ckeditor.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/css/component-library.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/css/nav_global.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/css/nav_local.min.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/css/styles.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/js/linkedevents.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/menu.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/nav-global.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/nav-toggle-dropdown.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions hdbt.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,12 @@ disable_genesys_button:
- core/jquery
- core/drupal
- core/drupalSettings

event-list:
version: 1.x
js:
dist/js/linkedevents.min.js: {}
dependencies:
- core/drupalSettings
- core/jquery
- core/drupal
56 changes: 56 additions & 0 deletions hdbt.theme
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use Drupal\menu_link_content\Plugin\Menu\MenuLinkContent;
use Drupal\node\NodeInterface;
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
use Drupal\views\ViewExecutable;
use Drupal\helfi_react_search\LinkedEvents;

/**
* Implements hook_preprocess().
Expand Down Expand Up @@ -1474,3 +1475,58 @@ function _hdbt_eu_cookie_compliance_get_privacy_policy_url(): Url {
? Url::fromUri($link)
: Url::fromUserInput($link === '<front>' ? '/' : $link);
}

/**
* Implements hook_preprocess_paragraph().
*/
function hdbt_preprocess_paragraph__event_list(&$variables) {
// Expose event list variables to frontend.
if (isset($variables['paragraph'])) {
$paragraph = $variables['paragraph'];
$linkedEvents = Drupal::service('helfi_react_search_linked_events');
$settings = [];

if ($paragraph->hasField('field_event_count') && !$paragraph->get('field_event_count')->isEmpty()) {
$settings['field_event_count'] = $paragraph->get('field_event_count')->first()->getValue()['value'];
}
else {
$settings['field_event_count'] = '3';
}

if ($paragraph->hasField('field_api_url') && !$paragraph->get('field_api_url')->isEmpty()) {
$initialUrl = $paragraph->get('field_api_url')->first()->getUrl()->toString();
$params = $linkedEvents->parseParams($initialUrl);
$eventUrl = $linkedEvents->getEventsRequest($params, $settings['field_event_count']);
$settings['events_api_url'] = $eventUrl;
$settings['request_url'] = $eventUrl;
$settings['places'] = $linkedEvents->getPlaceslist($eventUrl);
}

$booleanFields = [
'field_event_location',
'field_event_time',
'field_free_events',
'field_remote_events',
];

foreach ($booleanFields as $field) {
if ($paragraph->hasField($field) && !$paragraph->get($field)->isEmpty()) {
$settings[$field] = (boolean) $paragraph->get($field)->first()->getValue()['value'];
}
}

$variables['#attached']['drupalSettings']['helfi_events']['data'][$paragraph->id()] = $settings;
}

// Render image placeholder for use in frontend.
$variables['#attached']['drupalSettings']['helfi_events']['imagePlaceholder'] = twig_render_template(
drupal_get_path('theme', 'hdbt') . '/templates/misc/image-placeholder.twig',
[
'image_placeholder' => 'calendar-clock',
'theme_hook_original' => '',
]
);

$variables['#attached']['library'][] = 'hdbt/event-list';
$variables['#attached']['drupalSettings']['helfi_events']['baseUrl'] = LinkedEvents::BASE_URL;
}
Loading