ReferenceInput with nested CheckBoxGroupInput behaving strangely - reactjs

I have looked around for many hours and tried various things but alot of the examples i see for CheckBoxGroupInput simply have a hardcoded list of choices associated which is a bit useless... My scenario here is that i have a list of tags that i want to be able to associate with a product, pretty common stuff..
i need that list to be fetched from the postgres database... and that part all seems to work and my list looks normal when first rendered on the create screens for react-admin... The control looks like below
<ReferenceInput reference="ProductRealBenefit" source="realbenefits" sort={{ field: 'name', order: 'ASC' }}>
<CheckboxGroupInput source="name" />
</ReferenceInput>
This all well and good so far..
it renders my list as expected.. i have my schema all set up according to the format for ra_data_graphql_simple... Thing that is unexpected, is that as soon as i click on one of the tags, it immediately sends off a request to the server for the allProductRealBenefit query with a filter value equal to the clicked id and it adds a duplicate of that clicked tag to the list which breaks the control with a duplicate key error... i don't see why it would be sending off a request after i click anyway, i am not trying to save anything just assemble which tags would be sent off with the form data to create the link records, and i already have all that data after the initial populating of the control..
i am guessing maybe this should not be nested in ReferenceInput but i don't see any other way to populate my choices with database query result. I know this is ridiculously common functionality & I'll need to figure out a way to use this in multiple spots because this tagging functionality should be available in multiple resources.. I also tried this with AutocompleteArrayInput and it had similar issues so i know the problem is i must be missing an important step.... Be great if someone can point be in the right direction. i am going back to the docs for now to see what i can dig up!

OK, i am gonna answer another one of my questions in case anyone lands here equally as upsidedown as i was when i asked it... I simply didn't realize what some of the behind the scenes magic was doing therefore i was using this wrong... And i find the docs confusing
In my example above... my ProductRealBenefits in the reference was a one to many relationship represented in my schema with realbenefits: [ProductRealBenefits]... Therefore i needed the following components.
<ReferenceArrayInput label="Real Benefit Tags" source="realbenefitsIds" reference="ProductRealBenefit">
<CheckboxGroupInput optionValue="id" optionText="name" allowEmpty />
</ReferenceArrayInput>
There is a little magic in the ra_data_graphql_simple dataProvider that creates an item for you in state called realbenefitsIds, which is what you use as the source for the ReferenceArrayInput, i was trying to use the actual realbenefits array object, and that was not gonna work. I could not find any good examples out there or any decent explanations on how to get this to work... So ultimately it was Redux Dev Tools that saved my bacon here. I had to jump through some hoops in the graph server to get all this working with the dataprovider sending back diff things for GET_MANY and GET_REFERENCE_MANY filter values, but that was just a matter of parsing the filter args to match what sequelize was expecting. I'll end up writing a dataProvider eventually but this fit the bill for now..
PS.. i was seeing some strange behaviour in my CheckboxGroupInput, when i clicked something it duplicated whatever box was clicked... The reason for that was an error in object type in my schema... There was an Int mixed in with ID, and luckily that showed up in Redux Dev Tools and led me to the problem.
Lastly.. I'm putting together a sample project in Github that will use React-Admin, GraphQL, RA_DATA_GRAPHQL_SIMPLE, Sequelize, and a Postgres Database and i will comment it alot to take some of the confusion out of it for anyone like myself... Cheers!!

Related

WordPress : make categories automatically match according to external API Value

I'm managing a company website, where we have to display our products. We however do not want to handle the admin edit for this CPT, nor offer the ability to access to the form. But we have to read some product data form the admin edit page. All has to be created or updated via our CRM platform automatically.
For this matter, I already setup a CPT (wprc_pr) and registered 6 custom hierarchical terms: 1 generic for the types (wprc_pr_type) and 5 targeting each types available: wprc_pr_rb, wprc_pr_sp, wprc_pr_pe, wprc_pr_ce and wprc_pr_pr. All those taxonomies are required for filtering purposes (was the old way of working, maybe not the best, opened to suggestions here). We happen to come out with archive pages links looking like site.tld/generic/specific-parent/specific-child/ which is what is desired here.
I have a internal tool, nodeJS based, to batch create products from our CRM. The job is simple: get all products not yet pushed to the website, format a new post, push it to the WP REST API, wait for response, updated CRM data in consequence, and proceed to next product. Handle about 1600 products today on trialn each gone fine
The issue for now is that in order for me to put the correct terms to the new post, I have to compute for each product the generic type and specific type children.
I handled that by creating 6 files, one for each taxonomy. Each file is basically a giant JS object with the id from the CRM as a key, and the term id as a value. My script handles the category assertion like that:
wp_taxonomy = [jsTaxonomyMapper[crm_id1][crm_id2]] // or [] if not found
I have to say it is working pretty well, and that I could stop here. But I will have to take that computing to the wp_after_insert_post hook, in order to reaffect the post to the desired category on updated if something changed on the CRM.
Not quite difficult, but if I happen to add category on the CRM, I'll have to manually edit my mappers to add the new terms, and believe me that's a hassle.
Not waiting for a full solution here, but a way to work the thing. Maybe a way to computed those mappers and store their values in the options table maybe, or have a mapper class, I don't know at all.
Additional information:
Data from the CRM comes as integers (ids corresponding to a label) and the mappers today consist of 6 arrays (nested or not), about 600 total entries.
If you have something for me, or even suggestions to simplify the process, I'll go with it.
Thanks.
EDIT :
Went with another approach, see comment below.

How to force two instance of the same app (DNN/2sxc) to read from the same stream?

Sorry if my question is silly but I'm new to DNN/2sxc, I've spent the whole day trying to figure this with no success..
I have two instances of the same app, one in the home page and the other on its own page, each one must have its own view template (I use Razor).
My problem is I cannot figure a way to make the two apps read the same data, so every add/edit/remove/re-sort in one of them will be reflected to the other, currently each app has its own data and therefore they are unusable in my case.
I've tried to use a 'EntityTypeFilter' inside a 'Data Query' and use it in both views (as in the News-Simple demo video), it worked and gave me all the items in the two views, but another two problems come with this solution:
1- now I'm unable to use the toolbar to (add/remove/reorder,.. etc) any of the items , as you can see in this image, which is a show-stopper for me,
note: this is the toolbar I use:
#foreach(var item in AsDynamic(Data["Default"]))
{
...
#Edit.Toolbar(target: item, actions: "new,edit,replace,remove,moveup,movedown,instance-list")
2- the 'Content Demo Item' is also visible in the list, but it is not that important since I can delete it and use one of the real data items as a demo item.
I appreciate any kind of help.
Thank you.
So the first thing you should know is the difference when using content-items as data (to query, etc.) and when using it as assigned-items (where each module-instance has a subset of items). Here's the blog that should help you understand the difference: http://2sxc.org/en/blog/post/12-differences-when-templating-data-instead-of-content
So when you want the "manually and easily control the exact items displayed, their ordering etc." you want to use the "content-assigned-to-instance" which also gives you the simple add, delete buttons, as these don't really delete anything, but just remove the assignment from the module-instance.
Now your case is a bit special, in that you want to re-use the exact same set in another module-instance. There are a few ways you can do this:
Same View
if it's exactly the same view etc. just duplicate the module using DNN-features (the add-existing-module-to-another page)
different view
if it's a different view (maybe more compact, etc.) you again have multiple options. The first is to mirror / duplicate using the dnn-feature, and just put an if-im-on-this-page-then-show-differently or inject another CSS. That's probably the easiest without any dev-know-how.
The harder, but possibly nicer way, is to actually to use a new template, and tell it to retrieve the items in the way they are configured in the other module - let's say module 1 is the original, module 2 has a different template wanting to access the items of module 1 in exactly the same order as given in 1. They way to do this is simple, but requires a few lines of C# code in Module 2.
You need to create a new ModuleDataSource (https://2sxc.org/en/Docs/Feature/feature/4542) object and tell it that it's from Module 1. If you've never done this, it's basically that your code can create a query just like the visual designer, but you have more control - see the wiki https://github.com/2sic/2sxc/wiki/DotNet-DataSources-All. The Module-Data-Source in the visual-query-designer doesn't allow you to "switch" modules (a advanced setting we may add in the future) but the object has a ModuleId property which you can set before accessing the data, making it "switch" to that Module. here's the Pseudo code in your Module#2 razor...
var otherModData = CreateSource<ModuleDataSource>();
otherModData.ModuleId = 1;
foreach(var itm in AsDynamic(otherModData["Default"])) {
...
}
That should do it :)

Get content Id (nid) from path on views block

I just can't seem to wrap my head around Drupal relationships. I have been reading and watching tutorials, but as soon as I try to get my own project done - I fail. I think it's very basic, so I would love to understand it. Maybe someone here can help me understand how it works :)
On my drupal site, I want to keep track of some private game tournaments.
I have created a content type called contestant, which has fields like: Tournament date, Player name, Final Position. I can then create a view that list the information from one tournament. I used the help I got from this thread: drupal views dynamic filter
I would like to have the view described above as a block. And then place that block-view on a "tournament description" page. I could do this, by simply creating a new block each time, and then manually place it on the page it should be shown (structure-->Blocks-->configure), but that is not an elegant way to do it. I am pretty sure this is where Relationships should be used. But I fail to understand how to create this relationship, so that the specific block view, that matches the specific tournament description page will be displayed together.
Use a Content:Nid as a Contextual filter.
WHEN the Filter value is not in the URL >>
Provide default value
Content ID from URL

Issues on a select with AngularJS and Google Spreadsheet

I want to create a small web app which would display a list of movies, with a Google spreadsheet set as a database. So far, I was able to connect my spreadsheet to my app and I also added some filters to it. (As a side note, this thread really helped me in the process.)
Here is a very simplified version of my app: http://plnkr.co/edit/BtbSCVOh7KJsMHjANxMP?p=preview
I still have 3 problems with my <select>, which I can't fix despite trying for hours:
I can't sort my <options> alphabetically. Trying with orderBy didn't return anything.
I can't figure out a way to split my categories when there are more than one for a movie.
If the "categorie" field in my spreadsheet is empty, it will return a blank <option> which I would like to remove or hide.
My guess is that I'll need to update my function one way or another, but I'm a bit lost at the moment.
Any help on this would be really appreciated!

Cognos : Persisting Checkbox state across Multiple Pages

On the Cognos Report Results Page, we need to have a checkbox for each row.
The checkbox is designed using HTMLITEM tag.
However, the problem we face is that the state of the checkbox (checked or unchecked) is not persisted when we go to the next page/previous page.
I am very new to Cognos and I need to know if there is a way to do this.
I am fairly good at JAVAScripting and JSP, but since we only have access to HTML elements and not JSP Tags (Cognos uses CGI anyways), I cannot get the request object.
If there is some way to retrieve the request objects parameters of previous submit(previous page), that would help in solving the issue to a large extent, I feel.
Jonas
There isn't really enough information on what your end goal is to be able to assist you with this properly. There are a few ways that spring to mind that would allow you to use JS on the report to remember previously checked items, but there may be a much better way to do this depending on your requirements.
Without having more details, the first thing that leaps to mind is simply having some JavaScript set and unset cookie values on check/uncheck on the checkbox.
Note, there could be a variety of other ways to work this, including upping the number of visible rows per page, etc...
You can create a dataitem in a query where you can determine whether your checkbox should be checked or not. In the design of your list on the report page you can render a HTMLItem within the list, and base the HTMLItem on a DataItem. Your HTML must than be something like
<input type="checkbox" value="""+ [DataItemValueToPass] + """ " + [DataItemCheckedOrNot] ></input>

Resources