Skip to content

Commit

Permalink
feat(action): Sort devices in Blink Light device selection
Browse files Browse the repository at this point in the history
  • Loading branch information
cicoub13 committed May 2, 2024
1 parent f908eaf commit 1abd427
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions front/src/routes/scene/edit-scene/actions/BlinkLightParams.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class BlinkLight extends Component {
device_feature_category: 'switch',
device_feature_type: 'binary'
});
const deviceOptions = [...lightDevices, ...switchDevices].map(device => ({
value: device.selector,
label: device.name
}));
const deviceOptions = [...lightDevices, ...switchDevices]
.map(device => ({
value: device.selector,
label: device.name
}))
.sort((d1, d2) => d1.label.localeCompare(d2.label));
await this.setState({ deviceOptions });
this.refreshSelectedOptions(this.props);
return deviceOptions;
Expand All @@ -43,13 +45,14 @@ class BlinkLight extends Component {
refreshSelectedOptions = nextProps => {
const selectedOptions = [];
if (nextProps.action.devices && this.state.deviceOptions) {
nextProps.action.devices.forEach(light => {
const deviceOption = this.state.deviceOptions.find(deviceOption => deviceOption.value === light);
nextProps.action.devices.forEach(device => {
const deviceOption = this.state.deviceOptions.find(deviceOption => deviceOption.value === device);
if (deviceOption) {
selectedOptions.push(deviceOption);
}
});
}
selectedOptions.sort((d1, d2) => d1.label.localeCompare(d2.label));
this.setState({ selectedOptions });
};
constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const StateManager = require('../../../../lib/state');

const event = new EventEmitter();

describe('scene.blink-devices', () => {
describe('scene.blink-lights', () => {
let clock;

beforeEach(() => {
Expand Down

0 comments on commit 1abd427

Please sign in to comment.