Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into fb-LEAP-192
Browse files Browse the repository at this point in the history
  • Loading branch information
MihajloHoma committed Sep 28, 2023
2 parents b0c9702 + fe44b28 commit 37baffe
Show file tree
Hide file tree
Showing 19 changed files with 513 additions and 27 deletions.
47 changes: 37 additions & 10 deletions label_studio/feature_flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"version": 3,
"deleted": false
},
"ff_back_1587_email_notifications_310122_long": {
Expand Down Expand Up @@ -2172,7 +2172,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 5,
"version": 6,
"deleted": false
},
"fflag_feat_all_lsdv_e_295_project_level_roles_via_saml_scim_ldap_short": {
Expand Down Expand Up @@ -2766,7 +2766,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"version": 3,
"deleted": false
},
"fflag_feat_front_lops_12_label_ops_ui_short": {
Expand Down Expand Up @@ -3252,7 +3252,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"version": 3,
"deleted": false
},
"fflag_feat_front_lsdv_5518_snap_to_pixel_130923_short": {
Expand Down Expand Up @@ -3360,7 +3360,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"version": 3,
"deleted": false
},
"fflag_feat_front_prod_281_project_list_search_19072023_short": {
Expand Down Expand Up @@ -3452,7 +3452,7 @@
"contextTargets": [],
"rules": [],
"fallthrough": {
"variation": 0
"variation": 1
},
"offVariation": 1,
"variations": [
Expand All @@ -3468,7 +3468,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 6,
"version": 7,
"deleted": false
},
"fflag_feat_optic_2_ensure_draft_saved_short": {
Expand All @@ -3479,7 +3479,7 @@
"contextTargets": [],
"rules": [],
"fallthrough": {
"variation": 0
"variation": 1
},
"offVariation": 1,
"variations": [
Expand All @@ -3495,7 +3495,34 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 5,
"version": 9,
"deleted": false
},
"fflag_feat_optic_67_drag_and_drop_charts": {
"key": "fflag_feat_optic_67_drag_and_drop_charts",
"on": false,
"prerequisites": [],
"targets": [],
"contextTargets": [],
"rules": [],
"fallthrough": {
"variation": 0
},
"offVariation": 1,
"variations": [
true,
false
],
"clientSideAvailability": {
"usingMobileKey": false,
"usingEnvironmentId": false
},
"clientSide": false,
"salt": "4923bc1812ba4b1fa10b701540668464",
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 2,
"deleted": false
},
"fflag_fix_all_lsdv_4711_cors_errors_accessing_task_data_short": {
Expand Down Expand Up @@ -4629,7 +4656,7 @@
"trackEvents": false,
"trackEventsFallthrough": false,
"debugEventsUntilDate": null,
"version": 3,
"version": 4,
"deleted": false
},
"fflag_fix_front_lsdv_4620_memory_leaks_100723_short": {
Expand Down
2 changes: 1 addition & 1 deletion label_studio/frontend/dist/dm/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/dm/js/main.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions label_studio/frontend/dist/dm/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"message": "fix: OPTIC-109: Blank draft should not be created when an annotation is submitted",
"commit": "c9758b2fb911f789d6ba3c4b1dd8a44528eea5d0",
"message": "feat: LEAP-206: Ensure users can navigate freely and drafts are saved when leaving the labelling screen",
"commit": "32a18f43f46d65f61db5841ac58258f36f194bdc",
"branch": "master",
"date": "2023/09/22 11:06:45"
"date": "2023/09/26 10:39:21"
}
2 changes: 1 addition & 1 deletion label_studio/frontend/dist/react-app/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/react-app/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/react-app/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/react-app/main.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions label_studio/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"browserContext": "default"
},
"dependencies": {
"@radix-ui/react-toast": "^1.1.4",
"lodash.clonedeep": "^4.5.0",
"webpack-dev-server": "^4.13.3"
}
Expand Down
15 changes: 14 additions & 1 deletion label_studio/frontend/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,32 @@ import { LibraryProvider } from '../providers/LibraryProvider';
import { MultiProvider } from '../providers/MultiProvider';
import { ProjectProvider } from '../providers/ProjectProvider';
import { RoutesProvider } from '../providers/RoutesProvider';
import { DRAFT_GUARD_KEY, DraftGuard, draftGuardCallback } from "../components/DraftGuard/DraftGuard";
import './App.styl';
import { AsyncPage } from './AsyncPage/AsyncPage';
import ErrorBoundary from './ErrorBoundary';
import { RootPage } from './RootPage';
import { FF_OPTIC_2, isFF } from '../utils/feature-flags';
import { ToastProvider, ToastViewport } from '../components/Toast/Toast';

const baseURL = new URL(APP_SETTINGS.hostname || location.origin);

const browserHistory = createBrowserHistory({
basename: baseURL.pathname || "/",
getUserConfirmation: (message, callback) => {
if (isFF(FF_OPTIC_2) && message === DRAFT_GUARD_KEY) {
draftGuardCallback.current = callback;
} else {
callback(window.confirm(message));
}
},
});

window.LSH = browserHistory;

initSentry(browserHistory);

const App = ({content}) => {
const App = ({ content }) => {
const libraries = {
lsf: {
scriptSrc: window.EDITOR_JS,
Expand All @@ -51,9 +61,12 @@ const App = ({content}) => {
<LibraryProvider key="lsf" libraries={libraries}/>,
<RoutesProvider key="rotes"/>,
<ProjectProvider key="project"/>,
<ToastProvider key="toast"/>,
]}>
<AsyncPage>
<DraftGuard />
<RootPage content={content}/>
<ToastViewport />
</AsyncPage>
</MultiProvider>
</Router>
Expand Down
48 changes: 48 additions & 0 deletions label_studio/frontend/src/components/DraftGuard/DraftGuard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useContext, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { ToastContext } from '../Toast/Toast';
import { FF_OPTIC_2, isFF } from '../../utils/feature-flags';

export const DRAFT_GUARD_KEY = "DRAFT_GUARD";

export const draftGuardCallback = {
current: null,
};

export const DraftGuard = () => {
const toast = useContext(ToastContext);
const history = useHistory();

useEffect(() => {
if (isFF(FF_OPTIC_2)) {
const unblock = history.block(() => {
const selected = window.Htx?.annotationStore?.selected;
const submissionInProgress = !!selected?.submissionStarted;
const hasChanges = !!selected?.history.undoIdx && !submissionInProgress;

if (hasChanges) {
selected.saveDraftImmediatelyWithResults()?.then((res) => {
const status = res?.$meta?.status;

if (status === 200 || status === 201) {
toast.show({ message: "Draft saved successfully", type: "info" });
draftGuardCallback.current?.(true);
draftGuardCallback.current = null;
} else if (status !== undefined) {
toast.show({ message: "There was an error saving your draft", type: "error" });
}
});

return DRAFT_GUARD_KEY;
}
});

return () => {
draftGuardCallback.current = null;
unblock();
};
}
}, []);

return <></>;
};
27 changes: 27 additions & 0 deletions label_studio/frontend/src/components/Toast/MessageToast.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
messageToastInfoBackgroundColor = #262626
messageToastErrorBackgroundColor = #cf1322fc

.MessageToast
&_info
--background-color messageToastInfoBackgroundColor
--hover-background-color lighten(messageToastInfoBackgroundColor, 10%)
&_error
--background-color messageToastErrorBackgroundColor
--hover-background-color lighten(messageToastErrorBackgroundColor, 10%)
background-color var(--background-color)

.toast
--border-color rgba(240, 238, 242, 0.16)
--padding 8px 16px
background-color inherit

&__action,
&__content
color #FAFAFA
display flex
align-items center

&__action
background-color inherit
&:hover
background-color var(--hover-background-color)
28 changes: 28 additions & 0 deletions label_studio/frontend/src/components/Toast/MessageToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Toast, ToastAction, ToastProps } from '../../components/Toast/Toast';
import { LsCross } from '../../assets/icons';
import { FC } from 'react';
import { Block } from '../../utils/bem';
import "./MessageToast.styl";

export interface MessageToastProps extends ToastProps {
children?: any,
toastType?: "info" | "error" | null
closeCallback?: () => void
}

export const MessageToast: FC<MessageToastProps> = ({ toastType = "info", closeCallback, children, ...props }) => {
return (
<Block name="MessageToast"
tag={Toast}
open={!!children}
mod={{
info: toastType === "info",
error: toastType === "error",
}}
action={<ToastAction closeCallback={closeCallback} altText="x"><LsCross /></ToastAction>}
{...props}
>
{children}
</Block>
);
};
91 changes: 91 additions & 0 deletions label_studio/frontend/src/components/Toast/Toast.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
@keyframes toast-enter-up
from
opacity 0
transform translateY(100%)
to
opacity 1
transform translateY(0)

@keyframes toast-leave-fade
from
opacity 1
to
opacity 0

@keyframes toast-leave-down
from
opacity 1
transform translateY(var(--radix-toast-swipe-end-y))
to
opacity 0
transform translateY(100%)

.toast-viewport
--toast-spacing 8px
position fixed
display flex
justify-content center
width 100%
z-index 9999
bottom 24px
pointer-events none

& ol
list-style none

& li + li
margin-top var(--toast-spacing)

& ol:empty
display: none;

& li
@media (prefers-reduced-motion: no-preference)
will-change opacity, transform

&[data-state="open"]
animation toast-enter-up 100ms ease-out forwards

&[data-state="closed"]
animation toast-leave-fade 100ms ease-out forwards

&[data-swipe="move"]
transform translateY(var(--radix-toast-swipe-move-y))

&[data-swipe="cancel"]
transform translateY(0)

&[data-swipe="end"]
animation toast-leave-down 100ms ease-out forwards

.toast
--background-color #FAFAFA
--border-color rgba(137, 128, 152, 0.16)
--padding 8px 16px
display flex
align-items center
gap 16px
border-radius 4px
overflow hidden
border 1px solid var(--border-color)
background-color var(--background-color)

& > div,
&__content
font-size 16px
letter-spacing 0.5px
line-height 24px
flex 1

&__action,
&__content
padding var(--padding)

&__action
font-weight 500
font-size 16px
letter-spacing 0.15px
line-height 24px
border none
border-radius 0
border-left 1px solid var(--border-color)
Loading

0 comments on commit 37baffe

Please sign in to comment.