How to use react admin AutoCompleteInput with remote data? - autocomplete

I'm using react admin to develop a new panel for my client. I want to use AutoCompleteInput. But all the examples I find in the docs and online are showing a simple static data that is defined in the same component.
I want to use AutoCompleteInput for a list of items that is retrieved from my API.
How can I do that?

You can use the AutocompleteInput inside a ReferenceInput as explained in the documentation: https://marmelab.com/react-admin/Inputs.html#autocompleteinput
import { AutocompleteInput, ReferenceInput } from 'react-admin';
<ReferenceInput label="Post" source="post_id" reference="posts">
<AutocompleteInput optionText="title" />
</ReferenceInput>
It means you have to declare the referenced resource using a Resource component in your admin.
If you want to fetch data directly from a remote source, then I suggest you use the Autocomplete from material-ui instead. React-Admin is not a UI library.

Related

NextAuth Documentation refers to a version that doesnt exist?

I am trying to implement the following:
https://next-auth.js.org/tutorials/securing-pages-and-api-routes#nextjs-middleware
I want to list all my secure pages in the const config object. However on that page it references that 'since NextAuth 4.2....` Well the npmjs page only shows up to v4.17 - Is this why I can't get it to work? Why is it documenting something that we cannot even use yet?

Using manually created Cognito User Pool with an amplify project

I'm trying to use my existing Cognito User Pool when adding AWS Amplify to a react project.
In result, I want to use Amplify Datastore functionality for existing users in my manually created Cognito User Pool. Also, I like the Amplify CLI functionality for managing GraphQL schema for API, so, this means that I need to initialize amplify project inside my react project.
I started by this chapter https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js. But this chapter uses API Key authentication.
I know, that I can add Authentication to the amplify project by amplify auth add, but it has no option for using existing User Pool.
I can use my User Pool without initializing amplify project by amplify init - by using manually composed aws-exports.json. But as I pointed, I need also add amplify project for API.
I would combine configs, something like Amplify.configure({...aws_config_by_amplify, ...my_aws_config}), but it still unclear how to manage amplify api authentication with my user pool then.
Ideally, it would be great to use some command for amplify project configuration with an existing user pool, but I have not found one.
Also, I suppose that it's possible to make some manual changes in amplify project's cloudformation template/params, and to update the stack with that, but, unfortunately, I am not so good in CloudFormation usage.
How to solve this?
The solution was found here: https://github.com/aws-amplify/amplify-cli/issues/779
Init amplify project amplify init
Add API amplify add api with choosing of GraphQL
Update ampilfy/backend/api/backend-config.json, changing defaultAuthentication to
"defaultAuthentication": {
"authenticationType": "AMAZON_COGNITO_USER_POOLS"
}
Update ampilfy/backend/api/amplifyDatasource/parameters.json:
{
"AppSyncApiName": "amplifyDatasource",
"DynamoDBBillingMode": "PAY_PER_REQUEST",
"DynamoDBEnableServerSideEncryption": "false",
"authRoleName": {
"Ref": "AuthRoleName"
},
"unauthRoleName": {
"Ref": "UnauthRoleName"
},
"AuthCognitoUserPoolId": "<USERPOOL ID>"
}
(I am unsure that authRoleName and unauthRoleName are needed)
amplify push, and voila, the Appsync will have the user pool as the default authentication.
One solution, assuming you want to use the Amplify UI Authenticator component in your React project:
(Note this does not require any Amplify add/pull/push, config file generation, or any of that. It's 100% client side, you just drop in a component, configure it, and use it).
npm install #aws-amplify/ui-react aws-amplify
In your top-level style file, import the theme:
import '#aws-amplify/ui-react/styles.css';
Note: if you are in a Next.js project or get some complaints about pure selectors, import this in your top level app file, like _app.tsx
Add your config object to _app.tsx:
Amplify.configure({
Auth: {
region: 'us-west-2', << whatever region
userPoolId: 'your-userpool-id',
userPoolWebClientId: 'you-web-client-id', << found in App Integrations
},
});
Note that you can get your region from the userPoolId (at least, at this time), it's the part to the left of the underscore.
Add the Authenticator to your markup:
<div className="authenticator">
<Authenticator>
{({ signOut, user }) => (
// Next.js
<Component {...pageProps} signOut={signOut} user={user} />
// react-router-dom
<Routes>[Your Routes]</Routes>
)}
</Authenticator>
</div>
Import note: to use this component, make sure in your user pool Advanced app client settings -> Authentication Flows, "ALLOW_USER_SRP_AUTH" is in the list. The Authenticator component sends data a certain way and needs this protocol.
That's pretty much it. It assumes the userpool has things like verification and an app integration configured correctly, but as for the client side the above is all there is to it, I've used it a number of times recently.

Load select options dynamically from external service in Touch UI dialog in AEM?

My problem is to load a select field in touch UI dialog with dynamic options. These options are coming from a external URL via webservices, I am consuming this RESTful services using url defined in one of our global javascript objects like
$.get(mec.serviceConfig.baseUrl + '/movies';
Please understand that the options are coming from third party webservice please do not mention datasource. Whenever I search for loading select options dynamically I get this tutorial
Link to Tutorial
This is is not what I want.
In classic UI it is easy with optionsProvider.
In touch UI I am trying to write a script that fetches the data from the external webservice via AJAX ON DIALOG load and set these options in the select field.
Is there any better easier approach ? Can someone please share code snippets?
you should create JS listener for your component.
$document.on("dialog-ready", function() {
// there you should find your select field
//for example
var language = $("[name='./language']").closest(".coral-Select");
//then append to your select field new options from your datasource
});
please see doc: Dynamically updating AEM TouchUI Dialog Select Fields

dotCMS REST API fetch template by its id

I consider using dotCMS and integrate it with other system by its rest API but in spite of ability to fetch content by its api I cannot fetch tempates defined in dotCMS.
With url api/content/type/xml/id/c12fe7e6-d338-49d5-973b-2d974d57015b I obtain as response following xml:
<contentlets>
<content>
<template>1763fa6e-91c0-464e-8b16-9a25d7ae6ce5</template>
<modDate>2015-12-10 10:58:56.098</modDate>
<cachettl>15</cachettl>
<title>About Us</title>
<httpsreq/>
<showOnMenu>true</showOnMenu>
<inode>84e2879a-7749-40f4-bded-9d59dbb2b1da</inode>
<____DOTNAME____>About Us</____DOTNAME____>
<disabledWYSIWYG>[]</disabledWYSIWYG>
<seokeywords>dotCMS Content Management System</seokeywords>
<host>48190c8c-42c4-46af-8d1a-0cd5db894797</host>
<lastReview>2015-12-10 10:58:56.093</lastReview>
<stInode>c541abb1-69b3-4bc5-8430-5e09e5239cc8</stInode>
<owner>dotcms.org.1</owner>
<friendlyname>About Us</friendlyname>
<identifier>c12fe7e6-d338-49d5-973b-2d974d57015b</identifier>
<redirecturl/>
<canonicalUrl/>
<pagemetadata>dotCMS</pagemetadata>
<languageId>1</languageId>
<seodescription>
dotCMS Content Management System demo site - About Quest
</seodescription>
<folder>1049e7fe-1553-4731-bdf9-ba069f1dc08b</folder>
<sortOrder>0</sortOrder>
<modUser>dotcms.org.1</modUser>
</content>
</contentlets>
Is there any possibility to fetch template by its id (here 1763fa6e-91c0-464e-8b16-9a25d7ae6ce5) and obtain html file as response or some xml with html content?
Ok so after some hours of source code analysis I think I can assume that there is no rest api implemented by dotCMS. Instead of this we can use java api and fetch such components like templates, containers etc. by calling methods which are responsible for fetching these components from database. Then we can implement our own rest services.
Templates in dotCMS govern the display of "pages" which can be made up of multiple content objects. If you want to return a content object that has formatting applied to it, take a look at the widget API here:
http://dotcms.com/docs/latest/remote-widgets
and how it can be used here:
http://dotcms.com/docs/latest/remote-widgets

Jira calls external REST Service

My Problem: I want to introduce a new field in JIRA with status information from external REST Service (response is json).
Plan: Every Jira issue has a input field with some reference string. Behind this field there should be a panel, what should display informations from the external REST call (parsing response JSON is required).
Can someone give me some good info pages, how to tell JIRA to call external REST Service?
If you don't want to build it see:
nFeed
HTTP Feed Custom Field
If you want to build it yourself then start by following this tutorial on Creating a custom field type which is to more or less store a basic String within the database. (This would be the reference string)
You then have two options, the first is within the JiraCustomField class override the getVelocityParameters which was taken from How to call a java method from velocity Atlassian Answers question.
Then create a method (fetchValueFromWebService(String val)) that you would call that would contain code to query the REST Service based off the fields value that would be passed in from the velocity template. (E.g. $instance.fetchValueFromWebService($value))
To perform the actual web service call you can use any library you want, just see the Managing Dependencies documentation so it gets included in the plugin. (For example using the Jira Jersey version see this)
Your other option would be to within the view-basictext.vm have it use javascript and perform an AJAX to the web service by calling a function in your own JS file and dump that into a span that you have defined: (See Including Javascript and CSS resources)
<span id="webServiceValue"></span>
<script type="text/javascript">
fetchValueFromWebService($value);
</script>
You would however need to ensure that the webservice has Cross-origin resource sharing (CORS) enabled if you go the AJAX route.