Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Assign task to yourself #19515

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ export default {
assignTask: 'Assign task',
assignee: 'Assignee',
assigneeError: 'There was an error assigning this task, please try another assignee',
assignMe: 'Assign to me',
confirmTask: 'Confirm task',
confirmError: 'Please enter a title and select a share destination',
title: 'Title',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,7 @@ export default {
assignTask: 'Asignar tarea',
assignee: 'Cesionario',
assigneeError: 'Hubo un error al asignar esta tarea, intente con otro cesionario',
assignMe: 'Asignar a mí mismo',
confirmTask: 'Confirmar tarea',
confirmError: 'Por favor introduce un título y selecciona un destino de tarea',
title: 'Título',
Expand Down
9 changes: 8 additions & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ function getOptions(
recentReports: [],
personalDetails: [],
userToInvite: null,
currentUserOption: null,
};
}

Expand Down Expand Up @@ -699,8 +700,13 @@ function getOptions(
});
}

let currentUserOption = _.find(allPersonalDetailsOptions, (personalDetailsOption) => personalDetailsOption.login === currentUserLogin);
if (searchValue && !isSearchStringMatch(searchValue, currentUserOption.searchText)) {
currentUserOption = null;
}
Comment on lines +703 to +706
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it may be possible to not find currentUserLogin within the allPersonalDetailsOptions, or at least it is happening to me in dev:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any key I type in the search just crashes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selectors were likely broken with the privacy changes to use accountIDs


let userToInvite = null;
const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0;
const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption;
const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => option.login === searchValue.toLowerCase());

if (
Expand Down Expand Up @@ -757,6 +763,7 @@ function getOptions(
personalDetails: personalDetailsOptions,
recentReports: recentReportOptions,
userToInvite,
currentUserOption,
};
}

Expand Down
25 changes: 14 additions & 11 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,21 +424,24 @@ function setShareDestinationValue(shareDestination) {
* It also sets the shareDestination as that chat report if a share destination isn't already set
* @param {string} assignee
* @param {string} shareDestination
* @param {boolean} isCurrentUser
*/

function setAssigneeValue(assignee, shareDestination) {
let newChat = {};
const chat = ReportUtils.getChatByParticipants([assignee]);
if (!chat) {
newChat = ReportUtils.buildOptimisticChatReport([assignee]);
}
const reportID = chat ? chat.reportID : newChat.reportID;
function setAssigneeValue(assignee, shareDestination, isCurrentUser = false) {
if (!isCurrentUser) {
let newChat = {};
const chat = ReportUtils.getChatByParticipants([assignee]);
if (!chat) {
newChat = ReportUtils.buildOptimisticChatReport([assignee]);
}
const reportID = chat ? chat.reportID : newChat.reportID;

if (!shareDestination) {
setShareDestinationValue(reportID);
}
if (!shareDestination) {
setShareDestinationValue(reportID);
}

Report.openReport(reportID, [assignee], newChat);
Report.openReport(reportID, [assignee], newChat);
}

// This is only needed for creation of a new task and so it should only be stored locally
Onyx.merge(ONYXKEYS.TASK, {assignee});
Expand Down
27 changes: 20 additions & 7 deletions src/pages/tasks/TaskAssigneeSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ const TaskAssigneeSelectorModal = (props) => {
const [filteredRecentReports, setFilteredRecentReports] = useState([]);
const [filteredPersonalDetails, setFilteredPersonalDetails] = useState([]);
const [filteredUserToInvite, setFilteredUserToInvite] = useState(null);
const [filteredCurrentUserOption, setFilteredCurrentUserOption] = useState(null);

useEffect(() => {
const results = OptionsListUtils.getNewChatOptions(props.reports, props.personalDetails, props.betas, '', [], CONST.EXPENSIFY_EMAILS, false);

setFilteredRecentReports(results.recentReports);
setFilteredPersonalDetails(results.personalDetails);
setFilteredUserToInvite(results.userToInvite);
setFilteredCurrentUserOption(results.currentUserOption);
}, [props]);

const updateOptions = useCallback(() => {
const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getNewChatOptions(
const {recentReports, personalDetails, userToInvite, currentUserOption} = OptionsListUtils.getNewChatOptions(
props.reports,
props.personalDetails,
props.betas,
Expand All @@ -94,11 +96,12 @@ const TaskAssigneeSelectorModal = (props) => {
false,
);

setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0, Boolean(userToInvite), searchValue));
setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue));

setFilteredUserToInvite(userToInvite);
setFilteredRecentReports(recentReports);
setFilteredPersonalDetails(personalDetails);
setFilteredCurrentUserOption(currentUserOption);
}, [props, searchValue]);

useEffect(() => {
Expand All @@ -122,6 +125,16 @@ const TaskAssigneeSelectorModal = (props) => {
const sectionsList = [];
let indexOffset = 0;

if (filteredCurrentUserOption) {
sectionsList.push({
title: props.translate('newTaskPage.assignMe'),
data: [filteredCurrentUserOption],
shouldShow: true,
indexOffset,
});
indexOffset += 1;
}

sectionsList.push({
title: props.translate('common.recents'),
data: filteredRecentReports,
Expand All @@ -136,18 +149,18 @@ const TaskAssigneeSelectorModal = (props) => {
shouldShow: filteredPersonalDetails?.length > 0,
indexOffset,
});
indexOffset += filteredRecentReports?.length;
indexOffset += filteredPersonalDetails?.length;

if (filteredUserToInvite) {
sectionsList.push({
data: [filteredUserToInvite],
shouldShow: filteredUserToInvite?.length > 0,
shouldShow: true,
indexOffset,
});
}

return sectionsList;
}, [filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, props]);
}, [filteredCurrentUserOption, filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, props]);

const selectReport = (option) => {
if (!option) {
Expand All @@ -159,15 +172,15 @@ const TaskAssigneeSelectorModal = (props) => {
if (!props.route.params && option.login) {
// Clear out the state value, set the assignee and navigate back to the NewTaskPage
setSearchValue('');
TaskUtils.setAssigneeValue(option.login, props.task.shareDestination);
TaskUtils.setAssigneeValue(option.login, props.task.shareDestination, OptionsListUtils.isCurrentUser(option));
return Navigation.goBack();
}

// Check to see if we're editing a task and if so, update the assignee
if (props.route.params.reportID && props.task.report.reportID === props.route.params.reportID) {
// There was an issue where sometimes a new assignee didn't have a DM thread
// This would cause the app to crash, so we need to make sure we have a DM thread
TaskUtils.setAssigneeValue(option.login, props.task.shareDestination);
TaskUtils.setAssigneeValue(option.login, props.task.shareDestination, OptionsListUtils.isCurrentUser(option));
// Pass through the selected assignee
TaskUtils.editTaskAndNavigate(props.task.report, props.session.email, '', '', option.login);
}
Expand Down