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

Commit

Permalink
Editor Page and canvas upates
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarlow12 authored and wbreza committed Apr 19, 2019
1 parent 2f6ff66 commit 0fa8dba
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 72 deletions.
2 changes: 0 additions & 2 deletions src/common/mockFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,8 +802,6 @@ export default class MockFactory {
save: jest.fn((project: IProject) => Promise.resolve(project)),
delete: jest.fn((project: IProject) => Promise.resolve()),
isDuplicate: jest.fn((project: IProject, projectList: IProject[]) => true),
renameTag: jest.fn(),
deleteTag: jest.fn(),
};
}

Expand Down
20 changes: 14 additions & 6 deletions src/react/components/pages/editorPage/canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,20 @@ export default class Canvas extends React.Component<ICanvasProps, ICanvasState>
return this.state.currentAsset.regions.filter((r) => selectedRegions.find((id) => r.id === id));
}

public updateCanvasToolsRegions = (): void => {
for (const region of this.state.currentAsset.regions) {
this.editor.RM.updateTagsById(
region.id,
CanvasHelpers.getTagsDescriptor(this.props.project.tags, region),
);
public updateCanvasToolsRegions = (asset?: IAssetMetadata): void => {
if (asset) {
this.setState({
currentAsset: asset,
});
this.clearAllRegions();
this.addRegionsToCanvasTools(asset.regions);
} else {
for (const region of this.state.currentAsset.regions) {
this.editor.RM.updateTagsById(
region.id,
CanvasHelpers.getTagsDescriptor(this.props.project.tags, region),
);
}
}
}

Expand Down
40 changes: 24 additions & 16 deletions src/react/components/pages/editorPage/editorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
</div>
<div className="editor-page-right-sidebar">
<TagInput
tags={this.state.project.tags}
tags={this.props.project.tags}
lockedTags={this.state.lockedTags}
selectedRegions={this.state.selectedRegions}
onChange={this.onTagsChanged}
Expand Down Expand Up @@ -313,13 +313,18 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
const assetService = new AssetService(project);
const asset = await assetService.renameTag(project.assets, tagName, newTagName, selectedAsset);

const projectService = new ProjectService();
const newProject = projectService.renameTag(project, tagName, newTagName);
await this.props.actions.saveProject(newProject);

const newProject: IProject = {
...project,
tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
}
this.setState({
selectedAsset: asset,
project: newProject,
selectedAsset: asset || selectedAsset,
}, async () => {
await this.props.actions.saveProject(newProject);
if (asset) {
this.canvas.current.updateCanvasToolsRegions(asset);
}
});
}

Expand All @@ -328,18 +333,21 @@ export default class EditorPage extends React.Component<IEditorPageProps, IEdito
}

private onTagDeleted = async (tagName: string): Promise<void> => {
const { project, selectedAsset } = this.state;
const assetService = new AssetService(project);
const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset);

const projectService = new ProjectService();
const newProject = projectService.deleteTag(project, tagName);
const { selectedAsset } = this.state;
const { project } = this.props;
const newProject: IProject = {
...project,
tags: project.tags.filter((t) => t.name !== tagName)
}
await this.props.actions.saveProject(newProject);
debugger;

this.setState({
selectedAsset: asset,
project: newProject,
});
const assetService = new AssetService(project);
const asset = await assetService.deleteTag(project.assets, tagName, selectedAsset);
if (asset) {
this.canvas.current.updateCanvasToolsRegions(asset);
this.setState({selectedAsset: asset});
}
}

private onCtrlTagClicked = (tag: ITag): void => {
Expand Down
3 changes: 3 additions & 0 deletions src/services/assetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ export class AssetService {
tagName: string,
transformer: (tags: string[]) => string[],
currentAsset?: IAssetMetadata): Promise<IAssetMetadata> {
if (!assets) {
return;
}
const assetKeys = Object.keys(assets);
// Loop over assets and update if necessary
for (const assetKey of assetKeys) {
Expand Down
29 changes: 0 additions & 29 deletions src/services/projectService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,33 +157,4 @@ describe("Project Service", () => {
await projectSerivce.delete(testProject);
expect(storageProviderMock.deleteFile.mock.calls).toHaveLength(assets.length + 1);
});

it("Deletes a tag from project", () => {
const tag = MockFactory.createTestTag();
const project: IProject = {
...MockFactory.createTestProject(),
tags: [tag],
};
const projectService = new ProjectService();
expect(projectSerivce.deleteTag(project, tag.name)).toEqual({
...project,
tags: [],
});
});

it("Renames a tag within project", () => {
const tag = MockFactory.createTestTag();
const project: IProject = {
...MockFactory.createTestProject(),
tags: [tag],
};
const projectService = new ProjectService();
expect(projectSerivce.renameTag(project, tag.name, "test")).toEqual({
...project,
tags: [{
name: "test",
color: expect.any(String),
}],
});
});
});
20 changes: 1 addition & 19 deletions src/services/projectService.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import _ from "lodash";
import shortid from "shortid";
import { StorageProviderFactory } from "../providers/storage/storageProviderFactory";
import { IProject, ISecurityToken, AppError, ErrorCode, AssetState, IAssetMetadata } from "../models/applicationState";
import { IProject, ISecurityToken, AppError, ErrorCode, AssetState } from "../models/applicationState";
import Guard from "../common/guard";
import { constants } from "../common/constants";
import { ExportProviderFactory } from "../providers/export/exportProviderFactory";
import { decryptProject, encryptProject } from "../common/utils";
import packageJson from "../../package.json";
import { AssetService } from "./assetService";
import { forEachAsync } from "../common/extensions/array";

/**
* Functions required for a project service
Expand All @@ -20,8 +18,6 @@ export interface IProjectService {
save(project: IProject, securityToken: ISecurityToken): Promise<IProject>;
delete(project: IProject): Promise<void>;
isDuplicate(project: IProject, projectList: IProject[]): boolean;
deleteTag(project: IProject, tagName: string): IProject;
renameTag(project: IProject, tagName: string, newTagName: string);
}

/**
Expand Down Expand Up @@ -104,20 +100,6 @@ export default class ProjectService implements IProjectService {
return (duplicateProjects !== undefined);
}

public deleteTag(project: IProject, tagName: string): IProject {
return {
...project,
tags: project.tags.filter((t) => t.name !== tagName),
};
}

public renameTag(project: IProject, tagName: string, newTagName: string): IProject {
return {
...project,
tags: project.tags.map((t) => (t.name === tagName) ? {...t, name: newTagName} : t),
};
}

private async saveExportSettings(project: IProject): Promise<void> {
if (!project.exportFormat || !project.exportFormat.providerType) {
return Promise.resolve();
Expand Down

0 comments on commit 0fa8dba

Please sign in to comment.