Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#2339 from Ren-Roros-Digital/New-Sor…
Browse files Browse the repository at this point in the history
…ting-Function

New sorting function
  • Loading branch information
KelvinTegelaar committed Apr 17, 2024
2 parents 894c017 + 139d1cd commit 296f2c1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/forms/RFFComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const RFFCFormInput = ({
}
RFFCFormInput.propTypes = {
...sharedPropTypes,
type: PropTypes.oneOf(['color', 'file', 'text', 'password']),
type: PropTypes.oneOf(['color', 'file', 'text', 'password', 'number']),
placeholder: PropTypes.string,
}

Expand Down
2 changes: 2 additions & 0 deletions src/components/utilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PageSizeSwitcher from 'src/components/utilities/PageSizeSwitcher'
import Toasts from 'src/components/utilities/Toasts'
import UsageLocation from 'src/components/utilities/UsageLocation'
import CippTableOffcanvas from './CippTableOffcanvas'
import validateAlphabeticalSort from './validateAlphabeticalSort'

export {
CippActionsOffcanvas,
Expand All @@ -43,4 +44,5 @@ export {
PageSizeSwitcher,
Toasts,
UsageLocation,
validateAlphabeticalSort,
}
23 changes: 23 additions & 0 deletions src/components/utilities/validateAlphabeticalSort.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default function validateAlphabeticalSort(data, sortKeys) {
if (!sortKeys || sortKeys.length === 0) return data
try {
if (!data) return data
const newList = data.filter((element) => {
return sortKeys.every((key) => {
return (element) => element[key] != null && element[key] != undefined
})
})
return newList.sort((a, b) => {
try {
return sortKeys.reduce((acc, key) => {
if (acc !== 0) return acc
return (a[key] ?? '').toString().localeCompare(b[key] ?? '')
}, 0)
} catch (error) {
return 0
}
})
} catch (error) {
return data
}
}
20 changes: 14 additions & 6 deletions src/views/endpoint/intune/MEMAddPolicy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import React, { useState } from 'react'
import { CCol, CRow, CListGroup, CListGroupItem, CCallout, CSpinner } from '@coreui/react'
import { Field, FormSpy } from 'react-final-form'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCheck, faExclamationTriangle, faTimes } from '@fortawesome/free-solid-svg-icons'
import {
faCheck,
faExclamationTriangle,
faFunnelDollar,
faTimes,
} from '@fortawesome/free-solid-svg-icons'
import { CippWizard } from 'src/components/layout'
import { WizardTableField } from 'src/components/tables'
import { validateAlphabeticalSort } from 'src/components/utilities'
import PropTypes from 'prop-types'
import {
Condition,
Expand All @@ -16,6 +22,7 @@ import {
import { useLazyGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'
import { OnChange } from 'react-final-form-listeners'
import CippJsonView from 'src/components/utilities/CippJsonView'
import { value } from 'lodash-es'

const Error = ({ name }) => (
<Field
Expand Down Expand Up @@ -70,7 +77,6 @@ const AddPolicy = () => {
let template = intuneTemplates.data.filter(function (obj) {
return obj.GUID === value
})
// console.log(template[0][set])
onChange(template[0][set])
}}
</OnChange>
Expand Down Expand Up @@ -145,10 +151,12 @@ const AddPolicy = () => {
{intuneTemplates.isSuccess && (
<RFFCFormSelect
name="TemplateList"
values={intuneTemplates.data?.map((template) => ({
value: template.GUID,
label: template.Displayname,
}))}
values={validateAlphabeticalSort(intuneTemplates.data, ['Displayname'])?.map(
(template) => ({
value: template.GUID,
label: template.Displayname,
}),
)}
placeholder="Select a template"
label="Please choose a template to apply."
/>
Expand Down
8 changes: 6 additions & 2 deletions src/views/tenant/standards/ListAppliedStandards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { faCheck, faCircleNotch, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons'
import { CippContentCard, CippPage } from 'src/components/layout'
import { useSelector } from 'react-redux'
import { ModalService } from 'src/components/utilities'
import { ModalService, validateAlphabeticalSort } from 'src/components/utilities'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import Skeleton from 'react-loading-skeleton'
import { CippTable, cellBooleanFormatter } from 'src/components/tables'
Expand Down Expand Up @@ -509,6 +509,7 @@ const ApplyNewStandard = () => {
<>
{component.type === 'Select' && (
<RFFCFormSelect
placeholder="Select a value"
name={component.name}
className="mb-3"
label={component.label}
Expand Down Expand Up @@ -613,7 +614,10 @@ const ApplyNewStandard = () => {
name={`${template.switchName}.TemplateList`}
className="mb-3"
multi={true}
values={template.templates.data?.map((t) => ({
values={validateAlphabeticalSort(
template.templates.data,
['Displayname', 'name'],
)?.map((t) => ({
value: t.GUID,
name: t.name || t.Displayname || t.displayName,
}))}
Expand Down

0 comments on commit 296f2c1

Please sign in to comment.