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

Restore points 2.1 #787

Merged
merged 12 commits into from
Aug 11, 2023
1 change: 0 additions & 1 deletion src/addons/addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const addons = [
'tw-remove-feedback',
'tw-disable-cloud-variables',
'tw-disable-compiler',
'tw-disable-restore-points',
'editor-stepping'
];

Expand Down
16 changes: 0 additions & 16 deletions src/addons/addons/tw-disable-restore-points/_manifest_entry.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/addons/addons/tw-disable-restore-points/_runtime_entry.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/addons/addons/tw-disable-restore-points/userscript.js

This file was deleted.

1 change: 0 additions & 1 deletion src/addons/generated/addon-entries.js

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

2 changes: 0 additions & 2 deletions src/addons/generated/addon-manifests.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import _tw_remove_backpack from "../addons/tw-remove-backpack/_manifest_entry.js
import _tw_remove_feedback from "../addons/tw-remove-feedback/_manifest_entry.js";
import _tw_disable_cloud_variables from "../addons/tw-disable-cloud-variables/_manifest_entry.js";
import _tw_disable_compiler from "../addons/tw-disable-compiler/_manifest_entry.js";
import _tw_disable_restore_points from "../addons/tw-disable-restore-points/_manifest_entry.js";
import _editor_stepping from "../addons/editor-stepping/_manifest_entry.js";
export default {
"cat-blocks": _cat_blocks,
Expand Down Expand Up @@ -142,6 +141,5 @@ export default {
"tw-remove-feedback": _tw_remove_feedback,
"tw-disable-cloud-variables": _tw_disable_cloud_variables,
"tw-disable-compiler": _tw_disable_compiler,
"tw-disable-restore-points": _tw_disable_restore_points,
"editor-stepping": _editor_stepping,
};
3 changes: 1 addition & 2 deletions src/addons/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const AddonHooks = {
appStateReducer: () => {},
appStateStore: null,
blockly: null,
blocklyCallbacks: [],
disableRestorePoints: false
blocklyCallbacks: []
};

export default AddonHooks;
13 changes: 3 additions & 10 deletions src/components/tw-restore-point-modal/restore-point-modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@
padding: 1.5rem 2.25rem;
max-height: calc(100vh - 150px);
overflow: auto;
display: flex;
flex-direction: column;
gap: 1rem;
}
[theme="dark"] .body {
color: $text-primary;
background: $ui-primary;
}

.extra-container,
.disabled,
.loading,
.error,
.empty,
.restore-point-container,
.legacy-transition {
margin: 1rem 0 0 0;
}

.extra-container {
display: flex;
justify-content: space-between;
Expand Down
106 changes: 88 additions & 18 deletions src/components/tw-restore-point-modal/restore-point-modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,63 @@ const messages = defineMessages({
defaultMessage: 'Restore Points',
description: 'Title of restore point management modal',
id: 'tw.restorePoints.title'
},
never: {
defaultMessage: 'never',
id: 'tw.restorePoints.never',
description: 'Part of restore point modal. Appears in a message like "Restore points are created [never v]".'
},
minutes: {
defaultMessage: 'every {minutes, plural, one {# minute} other {# minutes}}',
id: 'tw.restorePoints.minutes',
// eslint-disable-next-line max-len
description: 'Part of restore point modal. Appears in a message like "Restore points are created [every one minute v]".'
}
});

const MINUTE = 1000 * 60;
const INTERVAL_OPTIONS = [
MINUTE * 1,
MINUTE * 5,
MINUTE * 10,
MINUTE * 15,
MINUTE * 30,
-1
];
const IntervalSelector = props => (
<select
value={props.value}
onChange={props.onChange}
>
{INTERVAL_OPTIONS.map(interval => (
<option
key={interval}
value={interval}
>
{interval < 0 ? (
props.intl.formatMessage(messages.never)
) : (
props.intl.formatMessage(messages.minutes, {
minutes: Math.round(interval / MINUTE)
})
)}
</option>
))}
{!INTERVAL_OPTIONS.includes(props.value) && (
// This should never happen unless someone manually edits their storage, so we
// don't need to worry about making this work good.
<option value={props.value}>
{`every ${props.value}ms`}
</option>
)}
</select>
);
IntervalSelector.propTypes = {
intl: intlShape,
value: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired
};

const RestorePointModal = props => (
<Modal
className={styles.modalContent}
Expand All @@ -35,14 +89,31 @@ const RestorePointModal = props => (
/>
</p>

{props.disabled && (
<p>
<FormattedMessage
defaultMessage="Restore points are created {time}."
id="tw.restorePoints.intervalOption"
// eslint-disable-next-line max-len
description="{time} will be replaced with a dropdown with values such as [every 5 minutes v] and [never v]"
values={{
time: (
<IntervalSelector
intl={props.intl}
value={props.interval}
onChange={props.onChangeInterval}
/>
)
}}
/>
</p>

{props.interval < 0 && (
<p className={styles.disabled}>
<FormattedMessage
defaultMessage="Disabling restore points is dangerous."
// eslint-disable-next-line max-len
defaultMessage="Disable the &quot;Disable restore points&quot; addon to re-enable restore point creation."
// eslint-disable-next-line max-len
description="Message that appears in restore point manager when the user has disabled restore points. Note that the name of the addon in the addon settings is currently hardcoded as English."
id="tw.restorePoints.disabled"
description="Warning that appears in restore point modal when the user has disabled restore points."
id="tw.restorePoints.off"
/>
</p>
)}
Expand Down Expand Up @@ -73,17 +144,15 @@ const RestorePointModal = props => (
/>
</div>
) : props.restorePoints.length === 0 ? (
<div>
<div className={styles.empty}>
<FormattedMessage
defaultMessage="No restore points found."
description="Message that appears when no restore points exist yet"
id="tw.restorePoints.empty"
/>
</div>
<div className={styles.empty}>
<FormattedMessage
defaultMessage="No restore points found."
description="Message that appears when no restore points exist yet"
id="tw.restorePoints.empty"
/>
</div>
) : (
<div>
<React.Fragment>
<div className={styles.restorePointContainer}>
{props.restorePoints.map(restorePoint => (
<RestorePoint
Expand Down Expand Up @@ -130,10 +199,10 @@ const RestorePointModal = props => (
/>
</button>
</div>
</div>
</React.Fragment>
)}

{!props.isLoading && (
{!props.isLoading && props.onClickLoadLegacy && (
<details className={styles.legacyTransition}>
{/* This is going away within a few days */}
{/* No reason to bother translating */}
Expand All @@ -158,13 +227,14 @@ const RestorePointModal = props => (

RestorePointModal.propTypes = {
intl: intlShape,
interval: PropTypes.number.isRequired,
onChangeInterval: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
onClickCreate: PropTypes.func.isRequired,
onClickDelete: PropTypes.func.isRequired,
onClickDeleteAll: PropTypes.func.isRequired,
onClickLoad: PropTypes.func.isRequired,
onClickLoadLegacy: PropTypes.func.isRequired,
disabled: PropTypes.bool.isRequired,
onClickLoadLegacy: PropTypes.func,
isLoading: PropTypes.bool.isRequired,
totalSize: PropTypes.number.isRequired,
restorePoints: PropTypes.arrayOf(PropTypes.shape({})),
Expand Down
Loading
Loading