Skip to content

Commit

Permalink
[frontend] sort group in user creation form (#9273)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archidoit committed Jan 8, 2025
1 parent a5affd2 commit b24c18f
Showing 1 changed file with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,17 @@ const useStyles = makeStyles({
},
});

export const searchGroupFieldQuery = graphql`
query GroupFieldSearchQuery($search: String) {
groups(orderBy: name, search: $search) {
edges {
node {
id
name
group_confidence_level {
max_confidence
}
}
}
}
}
`;

export const groupsQuery = graphql`
query GroupFieldQuery {
groups {
query GroupFieldQuery(
$orderMode: OrderingMode
$orderBy: GroupsOrdering
$filters: FilterGroup
) {
groups(
orderMode: $orderMode
orderBy: $orderBy
filters: $filters
) {
edges {
node {
id
Expand Down Expand Up @@ -95,19 +87,21 @@ const GroupField: React.FC<GroupFieldProps> = (props) => {
if (predefinedGroups) {
setGroups(predefinedGroups);
} else {
fetchQuery(groupsQuery)
fetchQuery(groupsQuery, { orderBy: 'name', orderMode: 'asc' })
.toPromise()
.then((data) => {
const dataGroups = (data as GroupFieldQuery$data).groups?.edges ?? [];
const newGroups = dataGroups.map((n) => {
const max_confidence = n?.node.group_confidence_level
? `${t_i18n('Max Confidence Level:')} ${n.node.group_confidence_level.max_confidence}`
: t_i18n('No Max Confidence Level');
const newLabel = showConfidence
const groupLabel = n?.node.name ?? '';
const groupLabelInList = showConfidence
? `${n?.node.name} (${max_confidence})`
: n?.node.name ?? '';
return {
label: newLabel,
label: groupLabel,
labelInList: groupLabelInList,
value: n?.node.id ?? '',
};
});
Expand All @@ -133,12 +127,12 @@ const GroupField: React.FC<GroupFieldProps> = (props) => {
options={groups}
onInputChange={searchGroups}
onChange={typeof onChange === 'function' ? onChange : null}
renderOption={(renderProps: React.HTMLAttributes<HTMLLIElement>, option: { color: string; label: string }) => (
renderOption={(renderProps: React.HTMLAttributes<HTMLLIElement>, option: { color: string; label: string, labelInList?: string }) => (
<li {...renderProps}>
<div className={classes.icon} style={{ color: option.color }}>
<ItemIcon type="Group" />
<ItemIcon type="Group"/>
</div>
<div className={classes.text}>{option.label}</div>
<div className={classes.text}>{option.labelInList ?? option.label}</div>
</li>
)}
classes={{ clearIndicator: classes.autoCompleteIndicator }}
Expand Down

0 comments on commit b24c18f

Please sign in to comment.