Skip to content

Commit

Permalink
[frontend] fix lint (#4333)
Browse files Browse the repository at this point in the history
  • Loading branch information
frapuks committed Oct 14, 2024
1 parent ad6911a commit f8431dc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import Chip from '@mui/material/Chip';
import { CancelOutlined, PersonOutline } from '@mui/icons-material';
import { useTheme } from '@mui/styles';
import { stixDomainObjectMutation } from '@components/common/stix_domain_objects/StixDomainObjectHeader';
import Tooltip from '@mui/material/Tooltip';
import { truncate } from '../utils/String';
import useGranted, { KNOWLEDGE_KNUPDATE } from '../utils/hooks/useGranted';
import type { Theme } from './Theme';
import FieldOrEmpty from './FieldOrEmpty';
import { commitMutation, defaultCommitMutation } from '../relay/environment';
import Tooltip from '@mui/material/Tooltip';

type Node = {
readonly entity_type: string;
Expand Down Expand Up @@ -42,7 +42,7 @@ const ItemAssignees: FunctionComponent<Props> = ({ assignees, stixDomainObjectId
return (
<FieldOrEmpty source={assignees}>
{assignees.map((assignee) => (
<Tooltip title={assignee.name}>
<Tooltip key={assignee.id} title={assignee.name}>
<Chip
key={assignee.id}
variant="outlined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useTheme } from '@mui/styles';
import { CancelOutlined, PersonOutline } from '@mui/icons-material';
import Chip from '@mui/material/Chip';
import { stixDomainObjectMutation } from '@components/common/stix_domain_objects/StixDomainObjectHeader';
import Tooltip from '@mui/material/Tooltip';
import FieldOrEmpty from './FieldOrEmpty';
import type { Theme } from './Theme';
import useGranted, { KNOWLEDGE_KNUPDATE } from '../utils/hooks/useGranted';
import { truncate } from '../utils/String';
import { commitMutation, defaultCommitMutation } from '../relay/environment';
import Tooltip from '@mui/material/Tooltip';

interface ItemParticipantsProps {
participants: {
Expand Down Expand Up @@ -40,7 +40,7 @@ const ItemParticipants: FunctionComponent<ItemParticipantsProps> = ({ participan
return (
<FieldOrEmpty source={participants}>
{participants.map((participant) => (
<Tooltip title={participant.name}>
<Tooltip key={participant.id} title={participant.name}>
<Chip
key={participant.id}
variant="outlined"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { debounce } from 'rxjs/operators';
import { Subject, timer } from 'rxjs';
import { Field } from 'formik';
import { graphql } from 'react-relay';
import makeStyles from '@mui/styles/makeStyles';
import { fetchQuery } from '../../../../relay/environment';
import AutocompleteField from '../../../../components/AutocompleteField';
import { useFormatter } from '../../../../components/i18n';
import ItemIcon from '../../../../components/ItemIcon';
import makeStyles from '@mui/styles/makeStyles';

const SEARCH$ = new Subject().pipe(debounce(() => timer(1500)));

Expand Down Expand Up @@ -56,35 +56,20 @@ const useStyles = makeStyles((theme) => ({
},
}));

const ObjectAssigneeField = (props) => {
const { defaultObjectAssignee, name, style, label, onChange, helpertext, disabled } = props;
const ObjectAssigneeField = ({ defaultObjectAssignee, name, style, label, onChange, helpertext, disabled }) => {
const classes = useStyles();
const { t_i18n } = useFormatter();
const [keyword, setKeyword] = useState('');
const [assignees, setAssignee] = useState(defaultObjectAssignee ? [
{
label: defaultObjectAssignee.name,
value: defaultObjectAssignee.id,
type: defaultObjectAssignee.entity_type,
entity: defaultObjectAssignee,
},
]
{
label: defaultObjectAssignee.name,
value: defaultObjectAssignee.id,
type: defaultObjectAssignee.entity_type,
entity: defaultObjectAssignee,
},
]
: []);

useEffect(() => {
const subscription = SEARCH$.subscribe({
next: () => searchAssignees(),
});
return subscription.unsubscribe();
});

const handleSearch = (event) => {
if (event && event.target && event.target.value) {
setKeyword(event.target.value);
SEARCH$.next({ action: 'Search' });
}
}

const searchAssignees = () => {
fetchQuery(objectAssigneeFieldMembersSearchQuery, {
search: keyword,
Expand All @@ -104,35 +89,49 @@ const ObjectAssigneeField = (props) => {
)(data);
setAssignee(union(assignees, newAssignees));
});
}
};

useEffect(() => {
const subscription = SEARCH$.subscribe({
next: () => searchAssignees(),
});
return subscription.unsubscribe();
});

const handleSearch = (event) => {
if (event && event.target && event.target.value) {
setKeyword(event.target.value);
SEARCH$.next({ action: 'Search' });
}
};

return (
<Field component={AutocompleteField}
style={style}
name={name}
disabled={disabled}
multiple={true}
textfieldprops={{
variant: 'standard',
label: label ?? t_i18n('Assignee(s)'),
helperText: helpertext,
onFocus: searchAssignees,
}}
noOptionsText={t_i18n('No available options')}
options={assignees.sort((a, b) => a.label.localeCompare(b.label))}
onInputChange={handleSearch}
onChange={typeof onChange === 'function' ? onChange : null}
renderOption={(props, option) => (
<li {...props}>
<div className={classes.icon}>
<ItemIcon type={option.type} />
</div>
<div className={classes.text}>{option.label}</div>
</li>
)}
classes={{ clearIndicator: classes.autoCompleteIndicator }}
style={style}
name={name}
disabled={disabled}
multiple={true}
textfieldprops={{
variant: 'standard',
label: label ?? t_i18n('Assignee(s)'),
helperText: helpertext,
onFocus: searchAssignees,
}}
noOptionsText={t_i18n('No available options')}
options={assignees.sort((a, b) => a.label.localeCompare(b.label))}
onInputChange={handleSearch}
onChange={typeof onChange === 'function' ? onChange : null}
renderOption={(props, option) => (
<li {...props}>
<div className={classes.icon}>
<ItemIcon type={option.type} />
</div>
<div className={classes.text}>{option.label}</div>
</li>
)}
classes={{ clearIndicator: classes.autoCompleteIndicator }}
/>
);
}
};

export default ObjectAssigneeField;
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const StixCoreObjectOrCoreRelationshipLabelsView = (props) => {
const { t_i18n } = useFormatter();
const {
labels,
marginTop,
mutationRelationsAdd,
mutationRelationDelete,
enableReferences = false,
Expand Down

0 comments on commit f8431dc

Please sign in to comment.