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

feat: users can save their progress #18511

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

douglasbouttell-camunda
Copy link
Contributor

Description

Some tasks require significant effort from the user or due to circumstances tasks may need to be transferred to other people. Camunda should support allowing users to save their progress in order to help their job.

Related issues

closes #17609

@douglasbouttell-camunda douglasbouttell-camunda requested a review from a team May 14, 2024 13:28
@github-actions github-actions bot added the component/tasklist Related to the Tasklist component/team label May 14, 2024
Copy link
Contributor

github-actions bot commented May 14, 2024

Tasklist Test Results

143 files  143 suites   1h 36m 41s ⏱️
549 tests 544 ✅ 5 💤 0 ❌
547 runs  542 ✅ 5 💤 0 ❌

Results for commit 9102846.

♻️ This comment has been updated with latest results.

@douglasbouttell-camunda douglasbouttell-camunda marked this pull request as ready for review May 15, 2024 08:19
Copy link
Contributor

@vsgoulart vsgoulart left a comment

Choose a reason for hiding this comment

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

@douglasbouttell-camunda This PR is already a bit too, next time please it into smaller ones (a PR for the visual component and one for the mutation logic for example)

const {error} = await request(api.saveVariables({taskId, variables}));

if (error !== null) {
throw error ?? new Error('Could not complete task');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
throw error ?? new Error('Could not complete task');
throw error;

return new Request(getFullURL(`/v1/tasks/${taskId}/variables`), {
...BASE_REQUEST_OPTIONS,
method: 'POST',
body: JSON.stringify(body),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick, but there's no need to create a var since it's no reused

Suggested change
body: JSON.stringify(body),
body: JSON.stringify({
variables,
}),

function formatFormDataToVariables(data: object) {
return Object.keys(data).map((key) => ({
name: key,
// @ts-expect-error TS7053: data[key] can be anything
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's fix the types instead of ignoring them

@@ -79,6 +79,10 @@ const VariableEditor: React.FC<Props> = ({
}) => {
const {dirtyFields} = useFormState<FormValues, Partial<FormValues>>();

const nonDraftVariables = variables.filter(
(v) => v.value !== null || v.previewValue !== null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(v) => v.value !== null || v.previewValue !== null,
({value, previewValue}) => value !== null || previewValue !== null,

})}
description="Saving..."
iconDescription="Saving"
status={'active'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
status={'active'}
status="active"

vi.advanceTimersByTime(5000);
});

expect(screen.getByRole('status')).toBeEmptyDOMElement();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it bad for a11y to have it empty? maybe we should stop rending it

Comment on lines 638 to 635
await waitFor(() => {
expect(screen.getByTitle(/save current progress/i)).not.toHaveAttribute(
'disabled',
);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await waitFor(() => {
expect(screen.getByTitle(/save current progress/i)).not.toHaveAttribute(
'disabled',
);
});
await waitFor(() => {
expect(screen.getByTitle(/save current progress/i)).toBeDisabled();
});

Comment on lines 281 to 280
savingState === 'finished' ? (
<SaveSuccessMessage />
) : savingState === 'error' ? (
<SaveFailedMessage />
) : undefined
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have the AsyncActionButton, I see no reason to not reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the AsyncActionButton doesn't do what the UX design wants.

const newVariables: Array<Pick<Variable, 'name' | 'value'>> = [];

variables.forEach((variable) => {
if (variable.draft) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's invert the logic to use a explicit check like everywhere else

Suggested change
if (variable.draft) {
if (variable.draft === null) {

Comment on lines 206 to 209
save(
formatFormDataToVariables(
formManagerRef.current
?.get('form')
._getSubmitData() as object,
),
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't be using form-js internal methods like this, part of the epic should have been changing adapting form-js and make this public...

@vsgoulart
Copy link
Contributor

@esraagamal6 Could you please test this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tasklist Related to the Tasklist component/team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Users are able to manually save the current state of their form
2 participants