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

fix/set saved simplification #196

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to this project will be documented here.

Nothing yet.

## [0.15.2] - Oct 4th, 2024
- Change `set_saved` on submit buttons to be a true boolean,
rather than an optional boolean that could needlessly force a reload prompt

## [0.15.1] - Oct 4th, 2024
- Change deprecation cases to use dedicated `mark_deprecated` function

Expand Down
6 changes: 5 additions & 1 deletion api_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ If either more than one submit button or more button customization is desired, t
// If submit is unsuccessful and annotations edits should not be treated as "saved", return false
},
color?: "Arbitrary Color" // e.g. "#639", "#3AB890", "rgb(200, 0, 170)", "hsl(0, 100%, 50%)"
set_saved?: boolean // If true, will call ulabel.set_saved(true) before the hook is called, thus avoiding the "unsaved changes" warning
/**
* If true, will call ulabel.set_saved(true) before the hook is called,
* thus avoid the "unsaved changes" warning. Defaults to false.
*/
set_saved?: boolean
size_factor?: number // Transform the default button size by this factor.
row_number?: number // The row number of the button in the toolbox
// Buttons with lower row numbers will be higher in the toolbox
Expand Down
2 changes: 1 addition & 1 deletion dist/ulabel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ulabel.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export type ULabelSubmitButton = {
name: string;
hook: (submit_data: ULabelSubmitData) => void;
color?: string;
/**
* Whether or not the button should call `set_saved`
joshua-dean marked this conversation as resolved.
Show resolved Hide resolved
* on the ULabel object when clicked. Defaults to false.
*/
set_saved?: boolean;
size_factor?: number;
row_number?: number;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ulabel",
"description": "An image annotation tool.",
"version": "0.15.1",
"version": "0.15.2",
"main": "dist/ulabel.js",
"module": "dist/ulabel.js",
"scripts": {
Expand Down
10 changes: 8 additions & 2 deletions src/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,11 @@ export class SubmitButtons extends ToolboxItem {
// Grab the submit buttons from ulabel
this.submit_buttons = ulabel.config.submit_buttons;

// Set `set_saved` to false if not provided
for (const button of this.submit_buttons) {
button.set_saved = button.set_saved ?? false;
}

this.add_styles();

this.add_event_listeners();
Expand All @@ -2427,6 +2432,7 @@ export class SubmitButtons extends ToolboxItem {
name: "Submit",
hook: this.submit_buttons,
row_number: 0,
set_saved: false,
}];
}

Expand Down Expand Up @@ -2486,8 +2492,8 @@ export class SubmitButtons extends ToolboxItem {
}

// Set set_saved if it was provided
if (this.submit_buttons[idx].set_saved !== undefined) {
ulabel.set_saved(this.submit_buttons[idx].set_saved);
if (this.submit_buttons[idx].set_saved) {
ulabel.set_saved(true);
}

await this.submit_buttons[idx].hook(submit_payload);
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const ULABEL_VERSION = "0.15.1";
export const ULABEL_VERSION = "0.15.2";