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: Add "Export" and "Duplicate" buttons in notes options menu. #688

Merged
merged 25 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e917871
fix: Fix icon colors so they work with themes
amanharwara Oct 15, 2021
dd088b6
feat: Add EditorIdentifier enum to @/enums.ts
amanharwara Oct 15, 2021
788d60a
feat: Implement "Export" & "Duplicate" actions in notes' options
amanharwara Oct 15, 2021
e465dd4
feat: Simplify format detection while saving notes
amanharwara Oct 17, 2021
43f3dd9
Update app/assets/javascripts/components/NotesOptions.tsx
amanharwara Oct 17, 2021
b1582f8
Update app/assets/javascripts/components/NotesOptions.tsx
amanharwara Oct 17, 2021
302b779
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 17, 2021
eba6c5b
chore(deps): Bump @standardnotes/features to 1.7.0
amanharwara Oct 17, 2021
1164756
refactor: Remove unused deps from notes options menu
amanharwara Oct 17, 2021
9a6fd2b
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 17, 2021
4777203
refactor: Use FeatureIdentifier enum instead of EditorIdentifier
amanharwara Oct 17, 2021
66fbe6c
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 17, 2021
88fc84a
chore(deps): Bump @standardnotes/features to 1.7.1
amanharwara Oct 17, 2021
d7dc044
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 19, 2021
2efd988
chore(deps): Bump @standardnotes/snjs to 2.15.1
amanharwara Oct 19, 2021
ad16d37
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 19, 2021
21f1f35
fix: Editor option types in default editor dropdown
amanharwara Oct 19, 2021
6c390ee
feat: Add correct PrefKeys to NotesCtrlState
amanharwara Oct 19, 2021
473627f
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 19, 2021
e7dccd9
refactor: Remove filter from extensions preferences
amanharwara Oct 19, 2021
6bbf02b
chore: Bump @standardnotes/features to 1.7.2
amanharwara Oct 19, 2021
0427abf
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 19, 2021
10145fa
Merge branch 'develop' into feat/notes-options-actions
amanharwara Oct 19, 2021
36a30f8
chore(deps): Bump snjs to 2.15.2
amanharwara Oct 19, 2021
a2ee7fb
Merge branch 'feat/notes-options-actions' of github.com:amanharwara/w…
amanharwara Oct 19, 2021
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
2 changes: 1 addition & 1 deletion app/assets/icons/ic-copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/icons/ic-download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 72 additions & 6 deletions app/assets/javascripts/components/NotesOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import {
DisclosureButton,
DisclosurePanel,
} from '@reach/disclosure';
import { SNNote } from '@standardnotes/snjs/dist/@types';
import {
PayloadContent,
SNComponent,
SNNote,
} from '@standardnotes/snjs/dist/@types';
import { WebApplication } from '@/ui_models/application';
import { KeyboardModifier } from '@/services/ioService';
import { EditorIdentifier } from '@/enums';

type Props = {
application: WebApplication;
Expand All @@ -20,9 +25,9 @@ type Props = {
};

type DeletePermanentlyButtonProps = {
closeOnBlur: Props["closeOnBlur"];
closeOnBlur: Props['closeOnBlur'];
onClick: () => void;
}
};

const DeletePermanentlyButton = ({
closeOnBlur,
Expand All @@ -45,8 +50,9 @@ export const NotesOptions = observer(
top: 0,
right: 0,
});
const [tagsMenuMaxHeight, setTagsMenuMaxHeight] =
useState<number | 'auto'>('auto');
const [tagsMenuMaxHeight, setTagsMenuMaxHeight] = useState<number | 'auto'>(
'auto'
);
const [altKeyDown, setAltKeyDown] = useState(false);

const toggleOn = (condition: (note: SNNote) => boolean) => {
Expand Down Expand Up @@ -86,7 +92,7 @@ export const NotesOptions = observer(
},
onKeyUp: () => {
setAltKeyDown(false);
}
},
});

return () => {
Expand Down Expand Up @@ -122,6 +128,50 @@ export const NotesOptions = observer(
setTagsMenuOpen(!tagsMenuOpen);
};

const downloadSelectedItems = () => {
notes.forEach((note) => {
let format = '.txt';
const noteAppData = (note.content as PayloadContent).appData[
'org.standardnotes.sn.components'
];
if (noteAppData) {
const editor = application.findItem(
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
Object.keys(noteAppData)[0]
) as SNComponent;
switch (editor.package_info.identifier) {
case EditorIdentifier.BoldEditor:
case EditorIdentifier.PlusEditor:
format = '.html';
Copy link
Member

Choose a reason for hiding this comment

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

I've just merged this PR so let's use the package_info file_type instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've made the change 👍 The tsc run on the PR will fail I guess till the snjs version is bumped.

Copy link
Member

@moughxyz moughxyz Oct 17, 2021

Choose a reason for hiding this comment

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

You can bump this to 1.7.0 when this run finishes: https://github.com/standardnotes/snjs/runs/3919286442

Copy link
Member Author

Choose a reason for hiding this comment

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

Run's still failing it seems.

Copy link
Member

Choose a reason for hiding this comment

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

I know what the issue is, needs a change in SNJS.

Copy link
Member

Choose a reason for hiding this comment

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

Btw you can run yarn build locally to make sure it compiles before pushing so that you don't have to wait for CI.

Copy link
Member

Choose a reason for hiding this comment

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

Merged to master: standardnotes/snjs@7a3e911

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @mobitar, the tsc run still seems to fail. Shows quite a few errors.

app/assets/javascripts/components/NotesOptions.tsx(129,46): error TS2339: Property 'file_type' does not exist on type 'ComponentPackageInfo'.
app/assets/javascripts/preferences/panes/Extensions.tsx(32,21): error TS2345: Argument of type 'import("/home/runner/work/web/web/node_modules/@standardnotes/snjs/node_modules/@standardnotes/features/dist/Domain/Feature/Feature").FeatureDescription[] | undefined' is not assignable to parameter of type 'import("/home/runner/work/web/web/node_modules/@standardnotes/features/dist/Domain/Feature/Feature").FeatureDescription[] | undefined'.

For the second one, import { FeatureDescription } from '@standardnotes/snjs/node_modules/@standardnotes/features' instead of import { FeatureDescription } from '@standardnotes/features' seems to stop that error.

Copy link
Member Author

Choose a reason for hiding this comment

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

In the yarn.lock file, there is both 1.6.2 of @standardnotes/features and 1.7.1:

"@standardnotes/[email protected]":
  version "1.6.2"
  resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.6.2.tgz#98c5998426d9f93e06c2846c5bc7b6aef8d31063"
  integrity sha512-s/rqRyG7mrrgxJOzckPSYlB68wsRpM9jlFwDE+7zQO5/xKh+37ueWfy3RoqOgkKLey6lMpnTurofIJCvqLM3dQ==
  dependencies:
    "@standardnotes/common" "^1.1.0"

"@standardnotes/[email protected]":
  version "1.7.1"
  resolved "https://registry.yarnpkg.com/@standardnotes/features/-/features-1.7.1.tgz#64285a1900114d685ae4c0c9781fd4da1498aba0"
  integrity sha512-ri96lAbYfKnmLz33MZLeMh4e+u5EMxCXotdEzUvUFXhgTfBwbeOI5chTPt8fEkv4CvUjCJa7Wk1btP/ALH0+OQ==
  dependencies:
    "@standardnotes/common" "^1.1.0"

Maybe this is causing the errors?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think standardnotes/snjs#459 will fix this.

break;
case EditorIdentifier.MarkdownBasic:
case EditorIdentifier.MarkdownMath:
case EditorIdentifier.MarkdownMinimist:
case EditorIdentifier.MarkdownPro:
case EditorIdentifier.TaskEditor:
format = '.md';
break;
case EditorIdentifier.SecureSpreadsheets:
case EditorIdentifier.TokenVault:
format = '.json';
break;
}
}
const downloadAnchor = document.createElement('a');
downloadAnchor.setAttribute(
'href',
'data:text/plain;charset=utf-8,' + encodeURIComponent(note.text)
);
downloadAnchor.setAttribute('download', `${note.title}${format}`);
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
downloadAnchor.click();
});
};

const duplicateSelectedItems = () => {
notes.forEach((note) => {
application.duplicateItem(note);
});
};

return (
<>
<Switch
Expand Down Expand Up @@ -246,6 +296,22 @@ export const NotesOptions = observer(
Unpin
</button>
)}
<button
onBlur={closeOnBlur}
className="sn-dropdown-item"
onClick={downloadSelectedItems}
>
<Icon type="download" className={iconClass} />
Export
</button>
<button
onBlur={closeOnBlur}
className="sn-dropdown-item"
onClick={duplicateSelectedItems}
>
<Icon type="copy" className={iconClass} />
Duplicate
</button>
{unarchived && (
<button
onBlur={closeOnBlur}
Expand Down
16 changes: 15 additions & 1 deletion app/assets/javascripts/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,19 @@ export enum HtmlInputTypes {
Text = 'text',
Time = 'time',
Url = 'url',
Week = 'week'
Week = 'week',
}

export enum EditorIdentifier {
amanharwara marked this conversation as resolved.
Show resolved Hide resolved
PlainEditor = 'plain-editor',
BoldEditor = 'org.standardnotes.bold-editor',
CodeEditor = 'org.standardnotes.code-editor',
MarkdownBasic = 'org.standardnotes.simple-markdown-editor',
MarkdownMath = 'org.standardnotes.fancy-markdown-editor',
MarkdownMinimist = 'org.standardnotes.minimal-markdown-editor',
MarkdownPro = 'org.standardnotes.advanced-markdown-editor',
PlusEditor = 'org.standardnotes.plus-editor',
SecureSpreadsheets = 'org.standardnotes.standard-sheets',
TaskEditor = 'org.standardnotes.simple-task-editor',
TokenVault = 'org.standardnotes.token-vault',
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dropdown, DropdownItem } from '@/components/Dropdown';
import { IconType } from '@/components/Icon';
import { EditorIdentifier } from '@/enums';
import {
PreferencesGroup,
PreferencesSegment,
Expand All @@ -20,20 +21,6 @@ type Props = {
application: WebApplication;
};

enum EditorIdentifier {
PlainEditor = 'plain-editor',
BoldEditor = 'org.standardnotes.bold-editor',
CodeEditor = 'org.standardnotes.code-editor',
MarkdownBasic = 'org.standardnotes.simple-markdown-editor',
MarkdownMath = 'org.standardnotes.fancy-markdown-editor',
MarkdownMinimist = 'org.standardnotes.minimal-markdown-editor',
MarkdownPro = 'org.standardnotes.advanced-markdown-editor',
PlusEditor = 'org.standardnotes.plus-editor',
SecureSpreadsheets = 'org.standardnotes.standard-sheets',
TaskEditor = 'org.standardnotes.simple-task-editor',
TokenVault = 'org.standardnotes.token-vault',
}

const getEditorIconType = (identifier: string): IconType | null => {
switch (identifier) {
case EditorIdentifier.BoldEditor:
Expand Down