This expression has type ... but an expression was expected of type - reason

I am using bs-material-ui-icon binding, but I am given type error when try to use it component.
module Cell = {
type status =
| Empty
| Tick
| Cross;
/* let icon = React.createElement(MaterialUIIcons.AccessAlarm); */
[#react.component]
let make = _children => {
<div> <MaterialUIIcons.AccessAlarm /> </div>; /** <MaterialUIIcons.AccessAlarm /> erorr **/
};
};
Here is the error message it gave:
This expression has type
'a =>
ReasonReact.component(ReasonReact.stateless,
ReasonReact.noRetainedProps,
ReasonReact.actionless)
but an expression was expected of type
React.component('a) = 'a => React.element
Type
ReasonReact.component(ReasonReact.stateless,
ReasonReact.noRetainedProps,
ReasonReact.actionless)
=
ReasonReact.componentSpec(ReasonReact.stateless,
ReasonReact.stateless,
ReasonReact.noRetainedProps,
ReasonReact.noRetainedProps,
ReasonReact.actionless)
is not compatible with type React.element
I am using react-jsx 3 (if this matter)

Like #glennsl said, this is because you're missing JSXv2 and JSXv3. There is a new branch that supports JSXv3 which you can find here https://github.com/jsiebern/bs-material-ui/tree/hooks . It was published on npm in hooks tag.

Related

ApiPlatform Regex property filter with Postgresql

I'm trying to add a custom filter to an entity in my ApiPlatform project that allows me to filter on specific property given a regex pattern.
Following the ApiPlatform documentation I came up with the following class (this is a near copy of the their example, only the where-clause is different):
<?php
namespace App\Filter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use Doctrine\ORM\QueryBuilder;
final class RegexFilter extends AbstractContextAwareFilter
{
protected function filterProperty(
string $property,
$value,
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
string $operationName = null
) {
// otherwise filter is applied to order and page as well
if (
!$this->isPropertyEnabled($property, $resourceClass) ||
!$this->isPropertyMapped($property, $resourceClass)
) {
return;
}
$parameterName = $queryNameGenerator->generateParameterName($property); // Generate a unique parameter name to avoid collisions with other filters
$queryBuilder
->andWhere(sprintf('(o.%s ~ :%s) = true', $property, $parameterName))
->setParameter($parameterName, $value);
}
// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
public function getDescription(string $resourceClass): array
{
if (!$this->properties) {
return [];
}
$description = [];
foreach ($this->properties as $property => $strategy) {
$description["regexp_$property"] = [
'property' => $property,
'type' => 'string',
'required' => false,
'swagger' => [
'description' => 'Filter using a regex. This will appear in the Swagger documentation!',
'name' => 'Custom name to use in the Swagger documentation',
'type' => 'Will appear below the name in the Swagger documentation',
],
];
}
return $description;
}
}
When I run my code this results in the following DQL:
SELECT o FROM App\Entity\Vehicle o WHERE (o.licensePlate ~ :licensePlate_p1) = true ORDER BY o.id ASC
However I cannot get the Lexer to understand the tilde ~ character:
Doctrine\ORM\Query\QueryException
[Syntax Error] line 0, col 56: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got '~'
How can I make Doctrine understand the tilde?
Turns out I was pretty close, simPod's answer helped me fill the gaps.
I copied his custom DQL function and added it in my Doctrine yaml configuration
In my RegexFilter I had to slightly modify the where-clause:
->andWhere(sprintf('REGEX(o.%s, :%s) = true', $property, $parameterName))

action has wrong type in ReasonReact reducer

I'm trying to create a simple todo app, this is an input component and I need a reducer to update the state of the input. This code is throwing the error - This pattern matches values of type action but a pattern was expected which matches values of type unit => string
For some reason it expects action to be unit => string and I have no idea why. Can anyone help?
type state = string;
type action =
| InputChange(string);
let component = ReasonReact.reducerComponent("Input");
let make = (~onSubmit, _children) => {
...component,
initialState: () => "",
reducer: action =>
switch (action) {
| InputChange(text) => ReasonReact.Update(text)
},
render: ({state: todo, send}) =>
<input
className="input"
value=todo
type_="text"
placeholder="What do you want todo"
onChange={e => send(ReactEvent.Form.target(e)##value)}
onKeyDown={
e =>
if (ReactEvent.Keyboard.key(e) == "Enter") {
onSubmit(todo);
send(() => "");
}
}
/>,
};
The type of action is inferred by the use of send in render, where you pass it () => "", a function of type unit => string. It should be send(InputChange("")).
You're also missing the state argument on reducer. It should be reducer: (action, state) => ..., or reducer: (action, _state) => ... to avoid the unused warning, since you're not using it.

In AutoMapper 8.0 missing ResolveUsing

Prior to AutoMapper 8.0, I have used this code:
CreateMap<ApplicationRole, RoleViewModel>()
.ForMember(d => d.Permissions, map => map.MapFrom(s => s.Claims))
.ForMember(d => d.UsersCount, map => map.ResolveUsing(s => s.Users?.Count ?? 0))
.ReverseMap();
The documentation says that you have to change ResolveUsing for MapFrom, but I have a Error "No propagation Null"
.ForMember(d => d.UsersCount, map => map.MapFrom(s => s.Users?.Count ?? 0))
How I have to resolve it?
Replace ResolveUsing with MapFrom, and add one more input parameter to the lambda (TDestination).
.ForMember(d => d.UsersCount, map => map.MapFrom((s,d) => s.Users?.Count ?? 0))
EDIT November 2022
Newest version(s) of AutoMapper doesn't support lambda expression in MapFrom. In this case you have to extract it to a method (Func) or do it inline if you can.
Also, null propagation isn't allowed unless it's a method.
.ForMember(d => d.UsersCount, map => map.MapFrom(s => MapUserCount(s))
--------------
private static int MapUserCount(ApplicationRole src) {
return src.Users?.Count ?? 0;
}
or
.ForMember(d => d.UsersCount, map => map.MapFrom(s => s.Users == null ? 0 : s.Users.Count))
In AutoMapper 8.0 missing ResolveUsing
I also have the same issue and I'm using the following prototype of ResolveUsing:
void ResolveUsing(Func<TSource, TResult> mappingFunction);
Instead of replacing existing code, I preferred to create an extension method:
using System;
using AutoMapper;
namespace myLibrary.Extensions
{
public static class AutoMapperCompatibilityExtensions
{
// Summary:
// Resolve destination member using a custom value resolver callback. Used instead
// of MapFrom when not simply redirecting a source member This method cannot be
// used in conjunction with LINQ query projection
//
// Parameters:
// resolver:
// Callback function to resolve against source type
public static void ResolveUsing<TSource, TDestination, TMember, TResult>(this IMemberConfigurationExpression<TSource, TDestination, TMember> member, Func<TSource, TResult> resolver) => member.MapFrom((Func<TSource, TDestination, TResult>)((src, dest) => resolver(src)));
}
}
Later, in my code, I simply referred the namespace:
using myLibrary.Extensions;
...
... map.ResolveUsing(s => ...
...
Hope this helps.
You don't need to use this expression, you can "Users.Count" and it'll return 0 if the list is empty.

Laravel 4 list and detail route

I want to achieve the following:
devices > Controller#devices
devices/{id} > Controller#devices
Is this possible with Laravel ? I'm trying to map a domotic box with an android application ImperiHome, and they expect me to have the same route for devices list and for any device action.
So far I've tried this:
Route::get('devices/{deviceId}/action/{actionName}/{actionParam?}', 'DomoticzController#devices');
Route::get('devices', 'DomoticzController#devices');
But I cannot retrieve the argument when I call the devices/id url
Ok, so to solve the php strict standard error I just splitted the routes to two methods as follows:
routes.php
Route::get('devices/{deviceId}/action/{actionName}/{actionParam?}', 'DomoticzController#device');
Route::get('devices', 'DomoticzController#devices');
Route::get('rooms', 'DomoticzController#rooms');
//Route::get('action_ret', 'DomoticzController#action_ret');
Route::get('system', 'DomoticzController#system');
Route::get('/', 'DomoticzController#system');
DomoticzController.php
/**
* Call for an action on the device identified by $deviceId.
* #return string Json formated action status.
*/
public function device($deviceId, $actionName, $actionParam = null)
{
$client = $this->getClient();
$request = $client->getClient()->createRequest('GET', get_url("json.htm?type=command&param={$actionName}&idx={$deviceId}}&switchcmd=$actionParam"));
$response = $request->send();
$input = $response->json();
// convert to app format
$output = array('success' => ('OK' === $input['status'] ? true : false), 'errormsg' => ('ERR' === $input['status'] ? 'An error occured' : ''));
return Response::json($output);
}
/**
* Retrieve the list of the available devices.
* #return string Json formatted devices list.
*/
public function devices()
{
$client = $this->getClient();
$request = $client->getClient()->createRequest('GET', get_url('json.htm?type=devices&used=true'));
$response = $request->send();
$input = $response->json();
// convert to app format
$output = new stdClass();
$output->devices = array();
foreach ($input['result'] as $device) {
$output->devices[] = array (
'id' => $device['idx'],
'name' => $device['Name'],
'type' => 'DevSwitch',
'room' => null,
'params' => array(),
);
}
return Response::json($output);
}
maybe there is a better way to solve this, I would be glad to hear it.
If you let both routes use the same controller action, you need to make the parameters optional in the controller I think.
Try this public function device($deviceId = null, $actionName = null, $actionParam = null) and see if you still get the PHP strict error.
You can not have a route without parameters be redirected to a controller action that expects parameters. You can, on the other hand, make a route with parameters be redirected to a controller action with optional parameters (this does not mean that your route parameters need to be optional).

Using HTML::FormFu, how do you change a field value *after* processing so that it appears modified in Template Toolkit?

For example, if I process a form:
my $form_input = { input_data => '123' };
$form->process($form_input);
Then I want to alter the value of 'input_data':
my $clearme = $form->get_field('input_data');
$clearme->value("546"); # doesn't seem to work
..Before pushing the form object to TT:
template 'index' => { form => $form }; # using Dancer
'input_data' seems to retain it's original value (123). Any hints on what I'm doing wrong, or what I should be doing?
Thanks
After looking at the documentation and doing some testing, I think you want
$form->add_valid(input_data => '546');