Skip to content

Commit

Permalink
Sort group select dropdown, add sortOnProperty function - #981
Browse files Browse the repository at this point in the history
  • Loading branch information
libpitt committed Oct 18, 2023
1 parent 33e20df commit 992c4b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/custom/edit/GroupSelect.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React, {useContext} from 'react';
import React, {useContext, useEffect} from 'react';
import {QuestionCircleFill} from "react-bootstrap-icons";
import {Form} from 'react-bootstrap';
import SenNetPopover from "../../SenNetPopover";
import AppContext from "../../../context/AppContext";

const GroupSelect = ({groups, onGroupSelectChange, entity_type, plural}) => {
const {cache} = useContext(AppContext)

useEffect(() => {
groups.sortOnProperty('displayname')
})

return (
<>
<Form.Group className="mb-3" controlId="group_uuid">
Expand Down
18 changes: 18 additions & 0 deletions src/components/custom/js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,24 @@ Object.assign(String.prototype, {
}
})

Object.assign(Array.prototype, {
sortOnProperty(key) {
return this.sort((a, b) => {
let fa = a[key].toLowerCase(),
fb = b[key].toLowerCase()

if (fa < fb) {
return -1
}
if (fa > fb) {
return 1
}
return 0
})
}
})


export const flipObj = (obj) => {
return Object.keys(obj).reduce((ret, key) => {
ret[obj[key]] = key;
Expand Down

0 comments on commit 992c4b0

Please sign in to comment.