-
Notifications
You must be signed in to change notification settings - Fork 0
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
React Integration for Itinerum #4
base: explore_react_integration
Are you sure you want to change the base?
Conversation
…a structure for additions. Still lacking teating and confirmation. Curious about changes needed in the html, and function return values.
Still trying to get variables to be present in the Tutorial.jsx file. Stuck with the variables...
Next Steps: Setting some JSON formatted value within the schema, and seeing if I can pull data from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put in some pseudo-like code. I hope it actually works :)
I would order the next tasks as:
- check to see if you can pass an object instead of individual fields
- change the schema to pass in first and last name and display them
I thought that the two-way binding worked, but actually looking again, I see that the form is actually modifying the angular scope using ng-model
and the react component is not actually modifying anything.
<form class="pure-form">
<fieldset>
<legend>Enter Name</legend>
<input type="text" ng-model="person.fname" placeholder="First Name"/>
<input type="text" ng-model="person.lname" placeholder="Last Name"/>
</fieldset>
</form>
Let's get this to work and then go back to ngReact to explore the two-way binding properly
www/js/intro.js
Outdated
@@ -23,6 +23,7 @@ angular.module('emission.intro', ['emission.splash.startprefs', | |||
.controller('IntroCtrl', function($scope, $state, $window, $ionicSlideBoxDelegate, | |||
$ionicPopup, $ionicHistory, ionicToast, $timeout, CommHelper, StartPrefs, UpdateCheck, $translate, i18nUtils) { | |||
|
|||
$scope.surveyState = { test: 'test', isValid: true, schema: {}, result: {} }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$scope.surveyState = { test: 'test', isValid: true, schema: {}, result: {} }; | |
$scope.surveyState = { test: 'test', isValid: true, schema: {'firstname': 'Jenna', 'lastname': "Ruzekowicz"}, result: {} }; |
www/templates/intro/survey.html
Outdated
@@ -1,5 +1,5 @@ | |||
<ion-content class="has-footer"> | |||
<tutorial/> | |||
<tutorial test="surveyState.test" isValid="surveyState.isValid" schema="surveyState.schema" result="surveyState.result"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you are passing the individual fields. can you just pass in the surveyState
object directly?
Probably best to try that first, since we want to pass in the schema object with sub-fields next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am attempting to pass the survey state via:
surveyState="surveyState"
but I am hitting a hurdle with then accessing the variables within the $scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/49081549/passing-object-as-props-to-jsx
Thought something like this would work.. alas I can't seem to get it right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by accessing variables within the $scope?
Also, you are already passing in an object (surveyState.schema
) and it looked like that worked?
Does it mean that top level objects directly under $scope
don't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within the .jsx file, we do the prop type checking. I believe one of the issues here is that we originally passed in the name, ie isValid="isValid". Now, we are only passing in the $scope variable surveyState. Code from .jsx:
propTypes: {
isValid: React.PropTypes.bool,
schema: React.PropTypes.object,
result: React.PropTypes.object
}
My initial instinct was to attempt something like surveyState.result: React.PropTypes.object
, but this did not work.
A few ways I've tried to pass in the surveyState:
<tutorial {surveyState} />
<tutorial {...surveyState} />
<tutorial surveyState="surevyState" />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, you would need to change the propTypes to accept a surveyState
object as well
Also, check the spelling on <tutorial surveyState="surevyState" />
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we changed the propTypes to accept a surveyState, would that be the only check?
ie. would we have something like:
propTypes : {
surveyState: React.propTypes.object
}
I am not seeing how the propTypes would be changed to accept a surveyState object exactly. We would still want to do all the confirmation that isValid is a boolean etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that would be the only check. Note that we already don't do any type checking within either the schema or the results, so we only lose type information for isValid
with this approach.
Let's first see if it works, and then we can make the design decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, here is a commit that does not quite work yet, but seems to be what we want. Still trying to figure out why this would not work. d48bba1
Question: Why do we need the React.PropTypes. ...
as opposed to just PropTypes. ...
?
Maybe they need to be key values pairs within the scope now? As in 'isValid': false
instead of isValid: false
? But not sure why this would work on the individual level but not when we attempt to pass in via the entire scope variable?
<div> | ||
This is the test -> {this.props.test} | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully something like this works.
<div> | |
This is the test -> {this.props.test} | |
</div> | |
<div> | |
This is the first name -> {this.props.schema.firstname} | |
This is the last name -> {this.props.schema.lastname} | |
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! This works perfectly. (Surprised it is so simple.)
Still trying to figure out the passing in of only surveyState
@jruzekowicz were you able to debug in android and figure out what the error is? |
I was able to get the debugger up and running by the end of the day Friday. This morning I have traced it down to a type error as follows:
This error statement pertains to the following line: |
Some things that have not worked:
No error is returned to directly access the surveyState such as: |
this seems to say that I wanted to spend some time seeing if top level structures would work, but they are not critical to the long-term design. |
Sounds good. I will make those changes, re-run to confirm everything is working properly and push a commit. I scheduled a meeting for early today to discuss next steps and getting started on writing this week. |
There is no error because
|
we still need to experiment with setting values in React and ensuring that they are visible in Angular. |
After that, we will want to retrieve the schema from @kafitz's service (e.g. e-mission/e-mission-docs#643 (comment)) and pass it in to the react component. I think @kafitz will take it from there? @kafitz or do you also want us to save the values to the database to be pushed up? |
If we're able to save the values to the app's own database, that sounds ideal. I think this primarily comes down to whether we will allow users to update their own survey answers in the future. As a user, I'm always in favor of having more control, but I don't want to divert if it seems too time consuming. For the React component, it can be just passed in as the raw JSON payload, no other parsing necessary. I've got that running on my end now with the Tutorial.jsx demo too. Other component development thoughts:
So overall my intention is to start by getting a TypeScript version of Tutorial.jsx working, merge in code from TS dashboard for state management, and then copy in the UI code from my Flutter repo. Open to comments/thoughts/suggestions |
@shankari Currently having some trouble checking the two-way binding for React to Angular. I have been doing some reading with some examples but am not clearly seeing how it corresponds to what we are trying to check here. Within the Hello examples within the ngReact repo, we have input text boxes. The following code is the input for the names:
The ng-model seems to be the key for the two-way binding on the angular side. I am unfortunately extremely confused with how to/what we are showing for React to Angular? |
@jruzekowicz we currently want to focus on a 2-way binding between react and angular. So if I make a change to How do you change variables in react? There must be a standard way... |
Concrete goal:
|
This is about the implementation I have for the button, yet I am still stuck in getting it to change the actual values. I seem to have trouble working with the props ie: |
@jruzekowicz I have no familiarity with React, so I would need to look it up, explore, etc myself. |
I'm less familiar with using createClass() to build components, but nothing jumps out at first glance (if the changename function is indeed getting called). There's 3 main ways to build a component in React: using createClass(), extending the built-in React.Component class, or most recently, their "functional components". Most current advice is to use functional components and they may be easiest to reason about. There's a comparison between them and extending the class here: https://reactjs.org/docs/hooks-state.html I would suggest going over there because binding methods like you're doing here is one of the key areas that's been improved. I believe it may cause the component to re-render unnecessarily passing in a parameter like you're doing now. |
…back on this and what improvements are needed. Working on understanding the prop vs state differences.
@kafitz @shankari I think I am on the right track with this commit: bf9c9f0 I would love @kafitz 's feedback on this commit and how close it is to what we are targeting. Another commit was pushed slightly after to demonstrate some of the issues with using event.target.value. May need to rethink this? |
…g for Kyle's feedback on the best way to go forward.
}; | ||
this.handleChange = this.handleChange.bind(this); | ||
} | ||
handleChange(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use different handlers!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Network call:
Handled by angular side of the app. Where is this located?? net.py?? Python w/ all network calls somewhere?
How to retrieve a JSON from endpoint (first pull request) ->
Pull down the JSON and store it within the app database? (All happening outside, local database on the phone itself??)
Eventually JSON becomes the "schema"-> tells the app how to layout all the data
Return data is just the answers.
Kyle has react.
Model off of existing code.
Kyle and I discussed the use/standard of multiple handling.
@shankari Latest Commit demonstrating the react -> angular operations with a text box entry. 8da04fb @kafitz took a look at this and suggested I move on to the next step of pulling down the survey in the JSON format. I will add to this comment with questions!
Where in the code base would I be adding in the retrieving step? @kafitz mentioned you may have a common location with GET and POST requests. |
As I said,
Otherwise, your thinking looks good. |
Hmm okay. So my plan is to load the data via a call with a specific email such as: Then I will launch the server and log into the app with the same email of test_july_22. I then plan to run the intake pipeline: I then would want to extract that data using the following: What am I missing here? Additionally, I looked at
but got completely lost in the process. Possibly something for us to go over within the meeting today? |
No. That is the part linked from e-mission#770 |
|
@shankari
My worry here is that maybe I shouldn't be looking within this exact metadata.key (stats/client_nav_event). This definitely seems wrong as no edits were made to that file. Trying to figure out what this would even be under?? |
Right, you should look for the key that you just inserted |
How do I know if this will be in metadata vs data? |
Empty result here... hmm... |
I encourage you to read up on the e-mission data model from the |
Some updates:
I feel as if I am on track with using the |
@kafitz Any reason I would all of the sudden be getting a 404 error for the POST request? |
@jruzekowicz sorry about that! I was dealing with a CORS issue working on our dashboard. Should be back now |
Haha no worries! I was just concerned I broke something on my end! |
Look at the stages of the intake pipeline (e.g. what is the first stage) and read up (maybe from the thesis) on the differences between the timeseries and the usercache. |
which logically makes sense and confirms my understanding.
|
Glad you figured it out! We can resolve the confusion at our 1:1 meeting. |
Yes! That is what I am now working on. I plan to run the full export pipeline and check to see if the key and the data is within the export file. Does this sound correct? |
@shankari I am seeing somewhat unique results and am trying to determine if they are expected.
For this, I changed the first name three times, while the last name remained the same. It seems to record all new values each time. Maybe we can talk more about this? Not sure what is expected or if this is an implementation error. |
Results from running the intake pipeline: Indentation errors fixed. However the following error still occurring: |
@shankari Still a little confused on how we want to incorporate the start_ts and end_ts. It still appears that the code is using a putMessage with a specific key. Would this mean I would want to incorporate the start_ts and end_ts within the message I am already sending (using the same survey_response key)? Additionally, I am still search to find how I actually can get those time stamps. We would want the exact time stamps for when the survey is first displayed to the user, and when they finally click the submit button. I can visualize where this should be within the code, but do not yet know how to actually get an immediate time stamp. |
@shankari Still currently stuck on this. I am not sure if we already have a function that does this, but is there a way to get the exact time stamp of a specific event? i.e. a button is pressed, and we get the timestamp of that press? |
When a button is pressed, your |
Okay, so for this implementation, would I simply look into js documentation to figure out how to get a time stamp? You noted that e-mission expects the timestamps in seconds. Is there other formatting I need to worry about? |
@shankari I was about to get the start_ts within the data, and for that ts to be directly applicable to the moment when the survey is officially loaded in displayed. The following message now occurs: Indicating there is an error with the formatting? This seems to be different than the error that we had before. Do you have any insight on this? |
I notice that the |
Success! No longer an issue. Results from filling the survey twice and checking the usercache:
Results after the intake pipeline has been run:
which confirms the results are being transferred from phone to usercache to db. |
Results from the exported file:
confirming that the process is completed and working! |
…ses. Testing done: After an "end trip and sync" from the app. I checked the usercache to confirm that the start_ts, end_ts were present. >>> edb.get_usercache_db().find({"metadata.key": "manual/survey_response"}).distinct("data.start_ts") [1628788017.462, 1628788224.702] >>> edb.get_usercache_db().find({"metadata.key": "manual/survey_response"}).distinct("data.end_ts") [1628788028.444, 1628788226.254] Additionally checked to make sure the data would result in the same outcome once the intake pipeline was run. >>> edb.get_timeseries_db().find({"metadata.key": "manual/survey_response"}).distinct("data.end_ts") [1628788028.444, 1628788226.254] Finally verified that the information would be present within the fully exported file: "metadata": { "key": "manual/survey_response", "platform": "android", "read_ts": 0, "time_zone": "America/New_York", "type": "message", "write_ts": 1628787342.232, "write_local_dt": { "year": 2021, "month": 8, "day": 12, "hour": 12, "minute": 55, "second": 42, "weekday": 3, "timezone": "America/New_York" }, "write_fmt_time": "2021-08-12T12:55:42.232000-04:00" }, "data": { "start_ts": 1628787339.618, "end_ts": 1628787342.231, "fname": "", "lname": "", "start_local_dt": { "year": 2021, "month": 8, "day": 12, "hour": 12, "minute": 55, "second": 39, "weekday": 3, "timezone": "America/New_York" },
hack for enketo to preserve prefilled timezone
Renamed clear data to something more accurate
Currently stuck on the variable passing/using within Tutorial.jsx.
Unable to use the variables/they are not showing as anticipated. Trying to figure out what I am missing here...