Skip to content

Commit

Permalink
Improve desk select
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Jun 20, 2024
1 parent 5bd2a11 commit 44bfde7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 25 deletions.
28 changes: 10 additions & 18 deletions client/components/UI/List/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import React from 'react';
import React, {CSSProperties} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

interface IProps {
children: Array<JSX.Element> | JSX.Element;
classes?: string;
paddingBottom?: boolean;
testId?: string;
style?: CSSProperties;
}

/**
* @ngdoc react
* @name Row
* @description Row Component in a list of item where each item is a row
*/
export const Row = ({children, classes, paddingBottom, testId, style}) => (
export const Row = ({children, classes = '', paddingBottom, testId, style}: IProps) => (
<div
className={classNames(
'sd-list-item__row',
Expand All @@ -22,19 +30,3 @@ export const Row = ({children, classes, paddingBottom, testId, style}) => (
{children}
</div>
);

Row.propTypes = {
children: PropTypes.node.isRequired,
classes: PropTypes.string,
margin: PropTypes.bool,
marginTop: PropTypes.bool,
paddingBottom: PropTypes.bool,
testId: PropTypes.string,
style: PropTypes.object,
};

Row.defaultProps = {
classes: '',
margin: true,
marginTop: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,52 @@ function getLanguagesForCoverage(
};
}

export class EmbeddedCoverageFormComponent extends React.PureComponent<IProps> {
interface IState {
userList: Array<IUser>;
selectedDeskId?: string;
}

const propertiesToFilterUsersBy = [
'username',
'display_name',
'first_name',
'last_name',
'email',
'sign_off',
];

export class EmbeddedCoverageFormComponent extends React.PureComponent<IProps, IState> {
constructor(props) {
super(props);

this.state = {
userList: this.props.users,
selectedDeskId: null,
};

this.onDeskChange = this.onDeskChange.bind(this);
this.onStatusChange = this.onStatusChange.bind(this);
this.onUserChange = this.onUserChange.bind(this);
this.onLanguageChange = this.onLanguageChange.bind(this);
}

onDeskChange(deskId?: IDesk['_id']) {
const newDesk = deskId == null ? null : this.props.desks.find((desk) => desk._id === deskId);
const newDesk = deskId == null || deskId == '' ? null : this.props.desks.find((desk) => desk._id === deskId);

const updates: Partial<ICoverageDetails> = {
desk: newDesk,
filteredUsers: getUsersForDesk(newDesk, this.props.users),
};

if ((this.props.coverage.language ?? '').length < 1) {
updates.language = newDesk.desk_language;
updates.language = newDesk?.desk_language;
}

this.setState({
selectedDeskId: deskId,
userList: updates.filteredUsers,
});

this.props.update(updates);
}

Expand Down Expand Up @@ -155,7 +179,7 @@ export class EmbeddedCoverageFormComponent extends React.PureComponent<IProps> {
error={this.props.errors?.desk}
>
<Option />
{coverage.filteredDesks.map(
{this.props.desks.map(
(desk) => (
<Option
key={desk._id}
Expand All @@ -174,6 +198,26 @@ export class EmbeddedCoverageFormComponent extends React.PureComponent<IProps> {
style={{padding: '2rem 0'}}
>
<SelectUser
key={this.state.selectedDeskId}
getItems={(searchString) => {
const getFilteredUsers = (users: Array<IUser>) => {

Check failure on line 203 in client/components/fields/editor/EventRelatedPlannings/EmbeddedCoverageForm.tsx

View workflow job for this annotation

GitHub Actions / client (14.x)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return users.filter((user) =>
propertiesToFilterUsersBy.some((filterProp) => {
if (user[filterProp]?.toLowerCase().includes(searchString.toLowerCase())) {

Check failure on line 206 in client/components/fields/editor/EventRelatedPlannings/EmbeddedCoverageForm.tsx

View workflow job for this annotation

GitHub Actions / client (14.x)

This line has a length of 123. Maximum allowed is 120
return true;
}

return false;
}),
)

Check failure on line 212 in client/components/fields/editor/EventRelatedPlannings/EmbeddedCoverageForm.tsx

View workflow job for this annotation

GitHub Actions / client (14.x)

Missing semicolon
};

if (searchString === '' || searchString == null) {
return Promise.resolve(this.state.userList);
}

return Promise.resolve(getFilteredUsers(this.state.userList));
}}
onSelect={(user) => {
this.onUserChange(null, user);
}}
Expand All @@ -187,11 +231,12 @@ export class EmbeddedCoverageFormComponent extends React.PureComponent<IProps> {
<List.Row>
<Row>
<Select
key={this.state.selectedDeskId}
label={gettext('Language:')}
value={language}
onChange={(item) => this.onLanguageChange(item)}
>
<Option />
<Option value={null} />
{allLanguages.map(
(language) => (
<Option
Expand Down
3 changes: 1 addition & 2 deletions client/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,7 @@ export const getItemsById = (ids, items) => (
export const getUsersForDesk = (desk, globalUserList = []) => {
if (!desk) return globalUserList;

return globalUserList.filter((user) =>
map(desk.members, 'user').indexOf(user._id) !== -1);
return globalUserList.filter(({_id}) => (desk.members ?? []).find((member) => member.user === _id));
};

export const getDesksForUser = (user, desksList = []) => {
Expand Down

0 comments on commit 44bfde7

Please sign in to comment.