Skip to content
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

General Settings view for Devices #624

Merged
merged 22 commits into from
May 6, 2019

Conversation

kschiffer
Copy link
Contributor

Summary

Closes #584

image

Changes

  • Refactor device data form into a dedicated container
  • Add general settings view for devices
  • Add option to use <Tab />'s as nav elements
  • Add submit logic for updating devices
  • Add disabled styling to checkboxes and radio buttons
  • A couple of minor styling tweaks

Notes for Reviewers

I have added the link prop to the <Tabs /> which will render the tab element as <NavLink />, as such also handling active state by itself. I decided to not make it a dedicated component, as the functionality could quite easily be added and it saves us some redundancy. Hope that's ok with you.

Release Notes

  • Added "General Settings" view for end devices

cc @htdvisser

@kschiffer kschiffer added the c/console This is related to the Console label May 2, 2019
@kschiffer kschiffer added this to the May 2019 milestone May 2, 2019
@kschiffer kschiffer requested a review from bafonins May 2, 2019 15:54
@kschiffer kschiffer self-assigned this May 2, 2019
@coveralls
Copy link

coveralls commented May 2, 2019

Coverage Status

Coverage increased (+0.02%) to 73.592% when pulling 474ea80 on feature/584-webui-device-settings into 0534064 on master.

@kschiffer kschiffer mentioned this pull request May 3, 2019
48 tasks
"console.views.device-add.messages.abp": "Xxxxxxxxxx Xx Xxxxxxxxxxxxxxx (XXX)",
"console.views.device-add.messages.resetWarning": "Xxxxxxxx xx xxxxxxxx xxx xxxxx xxxx xxxxxx xxxxxxxxxxx xxx xxxxxx xxxxxxx",
"console.views.device-add.messages.couldNotRetrieveFrequencyPlans": "Xxxxx xxx xxxxxxxx xxx xxxx xx xxxxxxxxx xxxxxxxxx xxxxx",
"console.views.device-general-settings.index.updateSuccess": "Xxxxxxxxxxxx xxxxxxx xxx xxxxxx",
"console.views.device-overview.index.hardware": "Xxxxxxxx",
"console.views.device-overview.index.brand": "Xxxxx",
"console.views.device-overview.index.model": "Xxxxx",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move these to shared-messages.js. The gateway model has them as well, see https://github.com/TheThingsNetwork/lorawan-stack/blob/master/api/gateway.proto#L48-L53

async handleSubmit (values, { setSubmitting, resetForm }) {
const { device } = this.props
const { application_id } = device.ids.application_ids
const updatedDevice = Object.assign({}, values)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const updatedDevice = Object.assign({}, values)
const updatedDevice = {...values}


async handleSubmit (values, { setSubmitting, resetForm }) {
const { device } = this.props
const { application_id } = device.ids.application_ids
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatedDevice.ids.dev_addr = updatedDevice.session.dev_addr
}
}
delete updatedDevice.activation_mode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { activation_mode, ...updatedDevice } = values

and you can remove this + simplifies check on L51

export default class DeviceGeneralSettings extends React.Component {

state = {
error: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
error: undefined,
error: '',

max={16}
placeholder={m.leaveBlankPlaceholder}
description={m.nwkKeyDescription}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}

DeviceDataForm.propTypes = {
onSubmit: PropTypes.func,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required?


DeviceDataForm.propTypes = {
onSubmit: PropTypes.func,
error: PropTypes.error,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add default value

DeviceDataForm.propTypes = {
onSubmit: PropTypes.func,
error: PropTypes.error,
update: PropTypes.bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add default value

@@ -101,6 +101,7 @@ export default {
list: ttnClient.Applications.Devices.getAll.bind(ttnClient.Applications.Devices),
get: ttnClient.Applications.Devices.getById.bind(ttnClient.Applications.Devices),
create: ttnClient.Applications.Devices.create.bind(ttnClient.Applications.Devices),
update: ttnClient.Applications.Devices.updateById.bind(ttnClient.Applications.Devices),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see how the applications and application definitions are structured. lets be consistent

@kschiffer kschiffer requested a review from bafonins May 3, 2019 14:06
Copy link
Contributor

@bafonins bafonins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check the <Tabs /> storybook, changing tabs doesnot work anymore

@@ -16,7 +16,7 @@ import getByPath from '../get-by-path'

export const getApplicationId = function (application = {}) {
return getByPath(application, 'application_id')
|| getByPath(application, 'application_ids.application_id')
|| getByPath(application, 'ids.application_id')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks the events component.
my suggestion would be to add an additional case:

Suggested change
|| getByPath(application, 'ids.application_id')
|| (getByPath(application, 'application_ids.application_id')
|| (getByPath(application, ''ids.application_id'))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also causes the issue we discussed in slack:

checkPropTypes.js:19 Warning: Failed prop type: The prop `emitter` is marked as required in `Event`, but its value is `undefined`.
    in Event (created by DefaultEvent)
    in DefaultEvent (created by List)
    in li (created by ListItem)
    in ListItem (created by List)
    in ol (created by List)
    in div (created by List)
    in List (created by EventsWidget)
    in aside (created by EventsWidget)
    in EventsWidget (created by EventsSubscription)
    in EventsSubscription (created by Connect(EventsSubscription))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh indeed. Was looking whether it was used elsewhere, but couldn't find it. Will add a case then.

const changed = diff(device, updatedDevice)
await api.device.update(appId, device_id, changed)

resetForm({ ...values })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resetForm({ ...values })
resetForm(values)

should work as well

@kschiffer kschiffer force-pushed the feature/584-webui-device-settings branch from db7b48f to dddc699 Compare May 6, 2019 08:04
@kschiffer kschiffer requested a review from bafonins May 6, 2019 08:05
@kschiffer kschiffer force-pushed the feature/584-webui-device-settings branch from 1d7013e to 474ea80 Compare May 6, 2019 11:50
@kschiffer kschiffer merged commit b89085b into master May 6, 2019
@kschiffer kschiffer deleted the feature/584-webui-device-settings branch May 6, 2019 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c/console This is related to the Console
Projects
None yet
Development

Successfully merging this pull request may close these issues.

General Settings view for Devices
3 participants