Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

Commit 295dcad

Browse files
tbarlow12wbreza
authored andcommitted
Added confirm and strings for tag and rename operations
1 parent 94df15d commit 295dcad

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

src/common/localization/en-us.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,14 @@ export const english: IAppStrings = {
256256
apply: "Apply Tag with Hot Key",
257257
lock: "Lock Tag with Hot Key",
258258
},
259+
rename: {
260+
title: "Rename Tag",
261+
confirmation: "Are you sure you want to rename this tag? It will be renamed throughout all assets",
262+
},
263+
delete: {
264+
title: "Delete Tag",
265+
confirmation: "Are you sure you want to delete this tag? It will be deleted throughout all assets and any regions where this is the only tag will also be deleted",
266+
}
259267
},
260268
canvas: {
261269
removeAllRegions: {

src/common/localization/es-cl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ export const spanish: IAppStrings = {
258258
apply: "Aplicar etiqueta con tecla de acceso rápido",
259259
lock: "Bloquear etiqueta con tecla de acceso rápido",
260260
},
261+
rename: {
262+
title: "Cambiar el nombre de la etiqueta",
263+
confirmation: "¿Está seguro que quiere cambiar el nombre de esta etiqueta? Será cambiada en todos los activos",
264+
},
265+
delete: {
266+
title: "Delete Tag",
267+
confirmation: "¿Está seguro que quiere borrar esta etiqueta? Será borrada en todos los activos y en las regiones donde esta etiqueta sea la única, la region también será borrada",
268+
}
261269
},
262270
canvas: {
263271
removeAllRegions: {

src/common/mockFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ export default class MockFactory {
802802
save: jest.fn((project: IProject) => Promise.resolve(project)),
803803
delete: jest.fn((project: IProject) => Promise.resolve()),
804804
isDuplicate: jest.fn((project: IProject, projectList: IProject[]) => true),
805+
renameTag: jest.fn(),
806+
deleteTag: jest.fn(),
805807
};
806808
}
807809

src/common/strings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ export interface IAppStrings {
255255
apply: string;
256256
lock: string;
257257
},
258+
rename: {
259+
title: string;
260+
confirmation: string;
261+
},
262+
delete: {
263+
title: string;
264+
confirmation: string;
265+
}
258266
}
259267
canvas: {
260268
removeAllRegions: {

src/react/components/common/tagInput/tagInput.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export interface ITagInputProps {
3131
/** Function to call on clicking individual tag while holding CTRL key */
3232
onCtrlTagClick?: (tag: ITag) => void;
3333
/** Function to call when tag is renamed */
34-
onTagRenamed?: (oldTag: string, newTag: string) => void;
34+
onTagRenamed?: (tagName: string, newTagName: string) => void;
3535
/** Function to call when tag is deleted */
36-
onTagDeleted?: (tag: ITag) => void;
36+
onTagDeleted?: (tagName: string) => void;
3737
/** Always show tag input box */
3838
showTagInputBox?: boolean;
3939
/** Always show tag search box */
@@ -219,20 +219,25 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
219219
}, () => this.props.onChange(tags));
220220
}
221221

222-
private updateTag = (oldTag: ITag, newTag: ITag) => {
223-
if (oldTag === newTag) {
222+
private updateTag = (tag: ITag, newTag: ITag) => {
223+
if (tag === newTag) {
224224
return;
225225
}
226226
if (!newTag.name.length) {
227227
toast.warn(strings.tags.warnings.emptyName);
228228
return;
229229
}
230-
if (newTag.name !== oldTag.name && this.state.tags.some((t) => t.name === newTag.name)) {
230+
const nameChange = tag.name !== newTag.name;
231+
if (nameChange && this.state.tags.some((t) => t.name === newTag.name)) {
231232
toast.warn(strings.tags.warnings.existingName);
232233
return;
233234
}
235+
if (nameChange && this.props.onTagRenamed) {
236+
this.props.onTagRenamed(tag.name, newTag.name);
237+
return;
238+
}
234239
const tags = this.state.tags.map((t) => {
235-
return (t.name === oldTag.name) ? newTag : t;
240+
return (t.name === tag.name) ? newTag : t;
236241
});
237242
this.setState({
238243
tags,
@@ -389,6 +394,10 @@ export class TagInput extends React.Component<ITagInputProps, ITagInputState> {
389394
if (!tag) {
390395
return;
391396
}
397+
if (this.props.onTagDeleted) {
398+
this.props.onTagDeleted(tag.name);
399+
return;
400+
}
392401
const index = this.state.tags.indexOf(tag);
393402
const tags = this.state.tags.filter((t) => t.name !== tag.name);
394403
this.setState({

src/react/components/pages/editorPage/editorPage.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import "./editorPage.scss";
2828
import EditorSideBar from "./editorSideBar";
2929
import { EditorToolbar } from "./editorToolbar";
3030
import Alert from "../../common/alert/alert";
31+
import Confirm from "../../common/confirm/confirm";
3132
// tslint:disable-next-line:no-var-requires
3233
const tagColors = require("../../common/tagColors.json");
3334

@@ -120,6 +121,8 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
120121
private loadingProjectAssets: boolean = false;
121122
private toolbarItems: IToolbarItemRegistration[] = ToolbarItemFactory.getToolbarItems();
122123
private canvas: RefObject<Canvas> = React.createRef();
124+
private renameTagConfirm: React.RefObject<Confirm> = React.createRef();
125+
private deleteTagConfirm: React.RefObject<Confirm> = React.createRef();
123126

124127
public async componentDidMount() {
125128
const projectId = this.props.match.params["projectId"];
@@ -232,8 +235,20 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
232235
onLockedTagsChange={this.onLockedTagsChanged}
233236
onTagClick={this.onTagClicked}
234237
onCtrlTagClick={this.onCtrlTagClicked}
238+
onTagRenamed={this.confirmTagRenamed}
239+
onTagDeleted={this.confirmTagDeleted}
235240
/>
236241
</div>
242+
<Confirm title={strings.editorPage.tags.rename.title}
243+
ref={this.renameTagConfirm}
244+
message={strings.editorPage.tags.rename.confirmation}
245+
confirmButtonColor="danger"
246+
onConfirm={this.onTagRenamed}/>
247+
<Confirm title={strings.editorPage.tags.delete.title}
248+
ref={this.deleteTagConfirm}
249+
message={strings.editorPage.tags.delete.confirmation}
250+
confirmButtonColor="danger"
251+
onConfirm={this.onTagDeleted}/>
237252
</div>
238253
</SplitPane>
239254
<Alert show={this.state.showInvalidRegionWarning}
@@ -288,6 +303,22 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
288303
}, () => this.canvas.current.applyTag(tag.name));
289304
}
290305

306+
private confirmTagRenamed = (tagName: string, newTagName: string): void => {
307+
this.renameTagConfirm.current.open(tagName, newTagName);
308+
}
309+
310+
private onTagRenamed = (tagName: string, newTagName: string): void => {
311+
debugger;
312+
}
313+
314+
private confirmTagDeleted = (tagName: string): void => {
315+
this.deleteTagConfirm.current.open(tagName);
316+
}
317+
318+
private onTagDeleted = (tagName: string): void => {
319+
debugger;
320+
}
321+
291322
private onCtrlTagClicked = (tag: ITag): void => {
292323
const locked = this.state.lockedTags;
293324
this.setState({

0 commit comments

Comments
 (0)