Skip to content

Commit

Permalink
Show a confirmation dialogue before resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
duizendnegen committed Dec 10, 2022
1 parent c8c3cb8 commit 14c63db
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 18 deletions.
7 changes: 6 additions & 1 deletion public/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
"remove_flavour": "Element entfernen",
"remove_flavour_button": "Element und alle untergeordneten Elemente entfernen"
},
"reset": {
"content": "Durch das Zurücksetzen wird dein Smorgasbord erneut geladen - deine Änderungen gehen verloren. OK?",
"confirm": "Ja, zurücksetzen",
"cancel": "Nein, abbrechen"
},
"footer": {
"disclaimer": "<a href=\"https://github.com/duizendnegen/sunburst-smorgasbord\">Open Source</a>; mit <a href=\"https://d3js.org/\">D3</a> hergestellt, basierend auf dem <a href=\"https://observablehq.com/@d3/sunburst\">Sunburstdiagramm</a>.<br />Keine Cookies, kein Tracking, keine Datenerhebung. Dein lokaler Speicher wird verwendet, damit du nicht jedes Mal von vorne anfangen musst, wenn du die Webseite neu lädst. Sweet.<br />Made by JayK / Shandalara / dzing",
"disclaimer": "<a href=\"https://github.com/duizendnegen/sunburst-smorgasbord\">Open Source</a>; mit <a href=\"https://d3js.org/\">D3</a> hergestellt, basierend auf dem <a href=\"https://observablehq.com/@d3/sunburst\">Sunburstdiagramm</a>.<br />Keine Cookies, kein Tracking, keine Datenerhebung. Dein lokaler Speicher wird verwendet, damit du nicht jedes Mal von vorne anfangen musst, wenn du die Webseite neu lädst. Sweet.",
"languages": "Verfügbar auf",
"languages_german": "Deutsch",
"languages_english": "Englisch"
Expand Down
9 changes: 7 additions & 2 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
"remove_flavour": "Flavour to remove",
"remove_flavour_button": "Remove flavour and all descendants"
},
"footer": {
"disclaimer": "<a href=\"https://github.com/duizendnegen/sunburst-smorgasbord\">Open source</a>; made with <a href=\"https://d3js.org/\">D3</a>, based on their <a href=\"https://observablehq.com/@d3/sunburst\">Sunburst diagram</a>.<br />No cookies, no tracking, no data collected. Local storage used to make sure you don't have to start over every time you load the website. Sweet.<br />Made by JayK / Shandalara / dzing",
"reset": {
"content": "Resetting your Smorgasbord will load the default canvas - your changes will be lost. OK?",
"confirm": "Yes, reset",
"cancel": "No, cancel"
},
"footer": {
"disclaimer": "<a href=\"https://github.com/duizendnegen/sunburst-smorgasbord\">Open source</a>; made with <a href=\"https://d3js.org/\">D3</a>, based on their <a href=\"https://observablehq.com/@d3/sunburst\">Sunburst diagram</a>.<br />No cookies, no tracking, no data collected. Local storage used to make sure you don't have to start over every time you load the website. Sweet.",
"languages": "Available in",
"languages_german": "German",
"languages_english": "English"
Expand Down
13 changes: 9 additions & 4 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ footer.footer {
background: #1F1F1F;
color: #fff;
}
.modal {
color: #000;
}

.sunburst-clickable {
cursor: pointer;
}

.button {
.button.is-primary {
background-color: #4a1942;
color: #fff;
}
.button:hover {
color: #ccc;
.button.is-primary:hover {
background-color: #4a1942;
color: #aaa;
}

.button[disabled] {
.button.is-primary[disabled] {
background-color: #fff;
border-color: #4a1942;
color: #333;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/AddFlavourForm/AddFlavourForm.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import AddFlavourForm from './AddFlavourForm';
import * as d3 from 'd3';
import { I18nextProvider } from 'react-i18next';
Expand Down
4 changes: 2 additions & 2 deletions src/components/AddFlavourForm/AddFlavourForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AddFlavourForm = ({ onAdd, hierarchicalFlavours } : AddFlavourFormProps) =
<div className="control">
<input
id="input-new-flavour-name"
className="input is-primary"
className="input"
type="text"
placeholder={t('edit.new_flavour')}
onChange={(e) => setNewFlavourName(e.target.value)}
Expand All @@ -52,7 +52,7 @@ const AddFlavourForm = ({ onAdd, hierarchicalFlavours } : AddFlavourFormProps) =
<div className="field">
<div className="control">
<button
className={ buttonIsConfirmation ? "button is-confirmation" : "button" }
className={ buttonIsConfirmation ? "button is-primary is-confirmation" : "button is-primary" }
onClick={addNewFlavour}
disabled={parentUuidToAddFlavourTo === '' || newFlavourName === ''}>
{t('edit.add_as_child')}
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditButton/EditButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const EditButton = ({ onClick } : EditButtonProps) => {
const { t } = useTranslation();

return (
<button className="button" onClick={onClick}>
<button className="button is-primary" onClick={onClick}>
<strong>{t('button.edit')}</strong>
</button>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExportAsImageButton/ExportAsImageButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const ExportAsImageButton = () => {
}

return (
<button className="button" onClick={exportAsImage}>
<button className="button is-primary" onClick={exportAsImage}>
<strong>{t('button.download_image')}</strong>
</button>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ExportAsJsonButton/ExportAsJsonButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const ExportAsJsonButton = ({ flavours } : ExportAsJsonButtonProps) => {
}

return (
<button className="button" onClick={exportCurrentFlavours}>
<button className="button is-primary" onClick={exportCurrentFlavours}>
<strong>{t('button.download_json')}</strong>
</button>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImportJsonButton/ImportJsonButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ImportJsonButton = ({ onUpload } : ImportJsonButtonProps) => {
}

return (
<button className="button" onClick={importNewFlavours}>
<button className="button is-primary" onClick={importNewFlavours}>
<strong>{t('button.import_json')}</strong>
<input
type='file'
Expand Down
2 changes: 1 addition & 1 deletion src/components/RemoveFlavourForm/RemoveFlavourForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const RemoveFlavourForm = ({ onRemove, hierarchicalFlavours } : RemoveFlavourFor
<div className="field">
<div className="control">
<button
className='button'
className='button is-primary'
onClick={removeFlavour}
disabled={flavourToRemove === ''}>
{t('edit.remove_flavour_button')}
Expand Down
23 changes: 23 additions & 0 deletions src/components/ResetButton/ResetButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { I18nextProvider } from "react-i18next";
import ResetButton from "./ResetButton";
import i18n from '../../i18n.tests';
import { act, fireEvent, getByText, render, screen } from '@testing-library/react';

it('resets the flavours after a confirmation', async () => {
const onReset = jest.fn();
render(
<I18nextProvider i18n={i18n}>
<ResetButton
onReset={onReset} />
</I18nextProvider>);

fireEvent.click(screen.getByText("Reset"));
fireEvent.click(screen.getByText("No, cancel"));

expect(onReset).toHaveBeenCalledTimes(0);

fireEvent.click(screen.getByText("Reset"));
fireEvent.click(screen.getByText("Yes, reset"));

expect(onReset).toHaveBeenCalledTimes(1);
});
24 changes: 21 additions & 3 deletions src/components/ResetButton/ResetButton.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";

interface ResetButtonProps {
Expand All @@ -6,11 +7,28 @@ interface ResetButtonProps {

const ResetButton = ({ onReset } : ResetButtonProps) => {
const { t } = useTranslation();
const [resetConfirmationVisible, setResetConfirmationvisible] = useState<boolean>(false);

return (
<button className="button" onClick={onReset}>
<strong>{t('button.reset')}</strong>
</button>
<div>
<button className="button is-primary" onClick={() => { setResetConfirmationvisible(true); }}>
<strong>{t('button.reset')}</strong>
</button>
<div className={resetConfirmationVisible ? 'modal is-active' : 'modal'}>
<div className="modal-background" onClick={() => { setResetConfirmationvisible(false); }}></div>
<div className="modal-card">
<section className="modal-card-body">
<p>
{t('reset.content')}
</p>
</section>
<footer className="modal-card-foot">
<button className="button is-primary" onClick={() => { onReset(); setResetConfirmationvisible(false); }}>{t('reset.confirm')}</button>
<button className="button" onClick={() => { setResetConfirmationvisible(false); }}>{t('reset.cancel')}</button>
</footer>
</div>
</div>
</div>
)
}

Expand Down

0 comments on commit 14c63db

Please sign in to comment.