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

Copy & Paste of Activity Directives between Plans #1627

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ivydeliz
Copy link
Contributor

@ivydeliz ivydeliz commented Feb 10, 2025

Closes #1625

Extending the original Copy & Paste feature with a few things here...

  1. Let's use the system Clipboard, instead of session storage. This will allow us to deconflict having a separate special clipboard for Aerie, and it enables more features like...
  2. Copy & Paste between plans. Open two plans, you can copy from plan A and paste on plan B either on the table or on the timeline at a specific time.
  3. Now that we handle different plans, they can have different boundaries, so if you're pasting and the earliest start is out of bounds, then we're going to paste at the start of the plan.

@ivydeliz ivydeliz force-pushed the feature/copy-paste-directives-between-plans branch from fab1cfa to e5c2ec1 Compare February 10, 2025 21:28
@ivydeliz ivydeliz self-assigned this Feb 10, 2025
@ivydeliz ivydeliz marked this pull request as ready for review February 10, 2025 21:53
@ivydeliz ivydeliz requested a review from a team as a code owner February 10, 2025 21:53
@ivydeliz ivydeliz changed the title Copy & Paste of Activity Directives between Plans (#1625) Copy & Paste of Activity Directives between Plans Feb 10, 2025
function canPasteActivityDirectives(): Promise<number> {
return new Promise(resolve => {
getActivityDirectivesClipboardCount().then(result => {
if (plan !== null && hasCreatePermission && result > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's okay to use hasCreatePermission here, but our convention for permissions has been to disallow the user from being able to click on the option to paste and displayed a tooltip stating why they're unable to click. It just lets them know quicker why something isn't available to them.

<ContextMenuItem on:click={pasteActivityDirectives}>{getPasteActivityDirectivesText()}</ContextMenuItem>
<ContextMenuSeparator></ContextMenuSeparator>
{/if}
{#await canPasteActivityDirectives() then howMany}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep this option always visible, but disabled if they don't have anything to paste in?

try {
window.navigator.clipboard.readText().then(clipText => resolve(clipText));
} catch (e) {
resolve(`{}`); //empty object string?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be an object string or can we just return null?

@ivydeliz ivydeliz force-pushed the feature/copy-paste-directives-between-plans branch from e5c2ec1 to 258e0ba Compare February 13, 2025 17:40
@ivydeliz ivydeliz force-pushed the feature/copy-paste-directives-between-plans branch from 258e0ba to 3796dac Compare February 13, 2025 17:50
@ivydeliz ivydeliz requested a review from duranb February 13, 2025 18:00
@ivydeliz
Copy link
Contributor Author

ivydeliz commented Feb 13, 2025

@duranb addressed feedback! and actually simplified it! Give it a look when you can.

return 'You do not have permission create activity directives';
} else if (directivesInClipboard <= 0) {
return 'No activity directives in clipboard';
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a final return statement for if the logic falls through all the conditionals?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mind saving the permissionError to a variable that gets updated in a reactive statement? We generally save the error to a local state variable so that it's calculated only when the dependent variables change and not every time the component re-renders.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The showCopyMenu variable seems to no longer be being set to anything else in this file. Can we remove it and just pass true into the BulkActionDataGrid's showCopyMenu prop?

@@ -432,18 +428,35 @@
>
Set Simulation End
</ContextMenuItem>
{#if canPasteActivityDirectives()}
{#await getActivityDirectivesClipboardCount() then directivesInClipboard}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there still a chance that this menu item won't show while it's loading the count? Is it always quick to pop in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sure there's still a chance if you're trying to copy/paste tens of thousands of activities

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah that makes sense. Can we instead save the count to a variable and instead of awaiting to show the menu option, just show the option with a 0 count and disabling it to be consistent with always showing options?

Copy link
Contributor Author

@ivydeliz ivydeliz Feb 25, 2025

Choose a reason for hiding this comment

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

@duranb since we're using the system clipboard we first need to make sure the clipboard has activity directives and then we get how many there are. So keeping the count doesn't really help me because we still have to deserialize the clipboard to see if it's the right type of content.

@@ -0,0 +1,26 @@
export function setClipboardContent(content: object, success?: () => void, fail?: () => void) {
navigator.permissions.query({ name: 'clipboard-write' as PermissionName }).then(result => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

PermissionName is missing a type definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duranb not sure I understand this one!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm getting PermissionName as an unresolved type from typescript.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok it looks like we dont need this after all so i removed that section.

});
}

export async function getClipboardContent(): Promise<string | undefined> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this needs to return void instead of undefined.

@ivydeliz ivydeliz force-pushed the feature/copy-paste-directives-between-plans branch from 3796dac to 0f7ae85 Compare February 20, 2025 04:19
@ivydeliz ivydeliz force-pushed the feature/copy-paste-directives-between-plans branch from 0f7ae85 to 848dfbe Compare February 25, 2025 03:21
@ivydeliz ivydeliz deployed to test-workflow February 25, 2025 03:21 — with GitHub Actions Active
@ivydeliz ivydeliz requested a review from duranb February 25, 2025 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Copy & Paste of Activity Directives between Plans
4 participants