Skip to content

Commit

Permalink
[frontend] same for participats (#4333)
Browse files Browse the repository at this point in the history
  • Loading branch information
frapuks committed Sep 30, 2024
1 parent db5dcbc commit 161dd05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ObjectAssigneeField = ({ defaultObjectAssignee, name, style, label, onChan
const { t_i18n } = useFormatter();
const { me } = useContext((UserContext));
const [keyword, setKeyword] = useState('');
const [assignees, setAssignee] = useState(defaultObjectAssignee ? [
const [assignees, setAssignees] = useState(defaultObjectAssignee ? [
{
label: defaultObjectAssignee.name,
value: defaultObjectAssignee.id,
Expand All @@ -89,7 +89,7 @@ const ObjectAssigneeField = ({ defaultObjectAssignee, name, style, label, onChan
entity: n.node,
})),
)(data);
setAssignee(union(assignees, newAssignees));
setAssignees(union(assignees, newAssignees));
});
};

Expand Down Expand Up @@ -120,7 +120,7 @@ const ObjectAssigneeField = ({ defaultObjectAssignee, name, style, label, onChan
onFocus: searchAssignees,
}}
noOptionsText={t_i18n('No available options')}
options={assignees.sort((a, b) => a.value === me.id ? -1 : b.value === me.id ? 1 : a.label.localeCompare(b.label))}
options={assignees.sort((a, b) => a.value === me?.id ? -1 : b.value === me?.id ? 1 : a.label.localeCompare(b.label))}
onInputChange={handleSearch}
onChange={typeof onChange === 'function' ? onChange : null}
renderOption={(props, option) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FunctionComponent, useState } from 'react';
import React, { FunctionComponent, useContext, useState } from 'react';
import { Field } from 'formik';
import { graphql } from 'react-relay';
import { makeStyles } from '@mui/styles';
Expand All @@ -9,6 +9,7 @@ import ItemIcon from '../../../../components/ItemIcon';
import type { Theme } from '../../../../components/Theme';
import { Option } from './ReferenceField';
import { ObjectParticipantFieldMembersSearchQuery$data } from './__generated__/ObjectParticipantFieldMembersSearchQuery.graphql';
import { UserContext } from '../../../../utils/hooks/useAuth';

const objectParticipantFieldMembersSearchQuery = graphql`
query ObjectParticipantFieldMembersSearchQuery($search: String, $first: Int, $entityTypes: [MemberType!]) {
Expand Down Expand Up @@ -77,6 +78,7 @@ const ObjectParticipantField: FunctionComponent<ObjectParticipantFieldProps> = (
}) => {
const classes = useStyles();
const { t_i18n } = useFormatter();
const { me } = useContext((UserContext));
const [participants, setParticipants] = useState<OptionParticipant[]>([]);

const searchParticipants = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -111,7 +113,7 @@ const ObjectParticipantField: FunctionComponent<ObjectParticipantFieldProps> = (
onFocus: searchParticipants,
}}
noOptionsText={t_i18n('No available options')}
options={participants}
options={participants.sort((a, b) => a.value === me?.id ? -1 : b.value === me?.id ? 1 : a.label.localeCompare(b.label))}
onInputChange={searchParticipants}
onChange={typeof onChange === 'function' ? onChange : null}
renderOption={(
Expand Down

0 comments on commit 161dd05

Please sign in to comment.