Skip to content

Commit

Permalink
Introduce Posts & Post Types Selects
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Oct 29, 2023
1 parent a235b36 commit 4d0053d
Show file tree
Hide file tree
Showing 41 changed files with 4,949 additions and 3,406 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
indent_style = tab
insert_final_newline = true
max_line_length = 120
tab_width = 4
Expand Down
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const baseConfiguration = require('@wordpress/scripts/config/.eslintrc.js');

module.exports = {
...baseConfiguration,
rules: {
...baseConfiguration.rules,
'@typescript-eslint/array-type': ['error', { default: 'generic' }],
},
settings: {
'import/resolver': {
typescript: {},
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
41 changes: 41 additions & 0 deletions .github/workflows/js-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: JS Quality Assurance

on:
pull_request:
push:
branches:
- main

paths:
- '**/workflows/*js*'
- '**.js'
- '**.jsx'
- '**.ts'
- '**.tsx'
- '**.json'

jobs:
build:
runs-on: ubuntu-latest
if: "!github.event.pull_request.draft"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v2
with:
cache: 'yarn'
node-version: '16'

- name: Install
run: yarn install

- name: Coding Style
run: yarn cs

- name: Linting JavaScript
run: yarn lint:js

- name: Unit Tests
run: yarn test
34 changes: 34 additions & 0 deletions .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHP Quality Assurance
on:
pull_request:
push:
branches:
- main

paths:
- '**.php'

jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft"
strategy:
matrix:
php-versions: [ '8.0' ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Check syntax error in sources
run: find ./src/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l

- name: Install dependencies
uses: "ramsey/composer-install@v1"

- name: Check code styles
run: composer cs
6 changes: 1 addition & 5 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
*.json
*.scss
*.css

.psalm
.github

./coverage
./vendor
./node_modules
./public
./build
17 changes: 15 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
const prettierConfig = require('@wordpress/scripts/config/.prettierrc.js')
const prettierConfig = require('@wordpress/scripts/config/.prettierrc.js');

module.exports = prettierConfig
module.exports = {
...prettierConfig,
importOrder: [
'<THIRD_PARTY_MODULES>',
'^@jest/(.*)$',
'^@testing-library/(.*)$',
'^@faker-js/faker',
'^@wordpress/(.*)$',
'^[./]',
],
importOrderSeparation: true,
importOrderSortSpecifiers: false,
importOrderCaseInsensitive: false,
};
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"php.suggest.basic": true,
"php.validate.enable": true,
"php.validate.executablePath": "/usr/bin/php",
"php.format.codeStyle": "Off",
"phpCodeSniffer.standardCustom": "./phpcs.xml",
"phpCodeSniffer.standard": "Custom",
"phpCodeSniffer.autoExecutable": true,
"[php]": {
"editor.defaultFormatter": "obliviousharmony.vscode-php-codesniffer"
},
"prettier.configPath": ".prettierrc.js"
}
22 changes: 10 additions & 12 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"core": "WordPress/WordPress",
"plugins": [
"."
],
"env": {
"development": {
"phpVersion": "8.0",
"mappings": {
"wp-content/plugins/entities-search": "."
}
}
}
"core": "./vendor/roots/wordpress-no-content",
"plugins": ["."],
"env": {
"development": {
"phpVersion": "8.0",
"mappings": {
"wp-content/plugins/entities-search": "."
}
}
}
}
60 changes: 60 additions & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Set } from 'immutable';
import React from 'react';

import { BaseEntityRecords, Context } from '@wordpress/core-data';

type ComponentStateAware<V> = {
value: Set<V>;
setValue(value: ComponentStateAware<V>['value']): void;
};

export default EntitiesSearch;

declare namespace EntitiesSearch {
type PostType<C extends Context = 'view'> = BaseEntityRecords.Type<C>;

type ViewablePostType = Readonly<{
[K in keyof PostType<'edit'>]: K extends 'viewable'
? true
: PostType<'edit'>[K];
}>;

type ControlOption<V extends any> = Readonly<{
value: V;
label: string;
}>;

type ComponentStateAware<V> = {
value: V;
setValue(value: ComponentStateAware['value']): void;
};

type EntitiesRecords<Entity> = Readonly<{
records(): Set<Entity>;
isResolving(): boolean;
errored(): boolean;
succeed(): boolean;
}>;

/**
* Components
*/
interface PostTypeSelect<V> {
readonly value: V | null;
readonly options: Set<ControlOption<V>>;
readonly onChange: (value: PostTypeSelect<V>['value']) => void;
}

interface PostsSelect<V> {
readonly value: Set<V> | null;
readonly options: Set<ControlOption<V>>;
readonly onChange: (values: PostsSelect<V>['value']) => void;
}

interface PostsController<P, T> {
readonly postsComponent: React.ComponentType<
ComponentStateAware<Set<P>>
>;
readonly typesComponent: React.ComponentType<ComponentStateAware<T>>;
}
}
74 changes: 37 additions & 37 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"name": "widoz/entities-search",
"description": "A WordPress package to search Entities including Rest API Endpoints and React Components",
"type": "library",
"license": "GPL-v2-or-later",
"autoload": {
"psr-4": {
"Widoz\\EntitiesSearch\\": "sources/php/src/"
}
},
"authors": [
{
"name": "guido scialfa",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=8.0"
},
"require-dev": {
"roots/wordpress": "^6.2",
"inpsyde/modularity": "^1.5"
},
"config": {
"platform": {
"php": "8.0"
},
"allow-plugins": {
"roots/wordpress-core-installer": true
}
},
"extra": {
"wordpress-install-dir": "vendor/wordpress/wordpress",
"installer-disable": [
"wordpress"
]
}
"name": "widoz/entities-search",
"description": "A WordPress package to search Entities including Rest API Endpoints and React Components",
"type": "library",
"license": "GPL-v2-or-later",
"version": "1.0.0",
"autoload": {
"psr-4": {
"Widoz\\EntitiesSearch\\": "sources/php/src/"
}
},
"authors": [
{
"name": "guido scialfa",
"email": "[email protected]"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=8.0"
},
"require-dev": {
"inpsyde/modularity": "^1.5",
"inpsyde/php-coding-standards": "^1.0",
"roots/wordpress-no-content": "^6.3"
},
"config": {
"platform": {
"php": "8.0"
},
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"cs:fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
}
}
29 changes: 0 additions & 29 deletions index.php

This file was deleted.

30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,49 @@
"version": "1.0.0",
"description": "A WordPress package to search Entities including Rest API Endpoints and React Components",
"author": "guido scialfa <[email protected]>",
"main": "./sources/js/src/index.ts",
"types": "./sources/js/src/@types/index.d.ts",
"main": "./build/index.js",
"license": "GPL-2.0-or-later",
"engines": {
"node": "16"
},
"devDependencies": {
"@faker-js/faker": "^7.6.0",
"@jest/globals": "^29.4.3",
"@testing-library/dom": "^9.3.1",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@total-typescript/shoehorn": "^0.1.0",
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
"@wordpress/dependency-extraction-webpack-plugin": "^4.8.0",
"@wordpress/env": "^5.9.0",
"@wordpress/eslint-plugin": "^14.8.0",
"@wordpress/scripts": "^25.1.0",
"@wordpress/scripts": "^26.0.0",
"eslint-import-resolver-typescript": "^3.5.5",
"jest": "^29.4.3",
"jest-environment-jsdom": "^29.5.0",
"prettier": "^2.8.1",
"ts-jest": "^29.0.5",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"typescript": "^5.0.3",
"typescript": "~5.1.0",
"yarn": "^1.22.19"
},
"dependencies": {
"@emotion/styled": "^11.10.5",
"@wordpress/api-fetch": "^6.21.0",
"@wordpress/components": "^23.1.0",
"@wordpress/element": "^5.1.0",
"@wordpress/i18n": "^4.24.0",
"react": "^18.2.0",
"react-select": "^5.7.0"
"@emotion/styled": "~11.10.5",
"@wordpress/api-fetch": "~6.21.0",
"@wordpress/components": "~23.1.0",
"@wordpress/core-data": "~6.12.0",
"@wordpress/element": "~5.1.0",
"@wordpress/i18n": "~4.24.0",
"immutable": "~4.3.0",
"react": "~18.2.0",
"react-select": "~5.7.0"
},
"scripts": {
"wp-env": "wp-env",
"build": "wp-scripts build --webpack-src-dir=./sources/js/src",
"build:dev": "wp-scripts build --mode=development --webpack-src-dir=./sources/js/src",
"build:dev": "wp-scripts start --webpack--devtool=inline-source-map --webpack-src-dir=./sources/js/src",
"cs": "yarn prettier --check ./sources/js",
"cs:fix": "wp-scripts format ./sources/js",
"lint:js": "wp-scripts lint-js",
"lint:js:fix": "wp-scripts lint-js --fix",
Expand Down
Loading

0 comments on commit 4d0053d

Please sign in to comment.