Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/action/ActionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ enum ActionType {
IMPORT_EXTERNAL_VOCABULARIES = "IMPORT_EXTERNAL_VOCABULARIES",
LOAD_EXCEL_TEMPLATE = "LOAD_EXCEL_TEMPLATE",

OPEN_CONTEXTS_FOR_EDITING = "OPEN_CONTEXTS_FOR_EDITING",

ADD_CRUMB = "ADD_CRUMB",
REMOVE_CRUMB = "REMOVE_CRUMB",

Expand Down
28 changes: 0 additions & 28 deletions src/action/AsyncWorkspaceActions.ts

This file was deleted.

34 changes: 3 additions & 31 deletions src/component/MainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import { changeView } from "../action/SyncActions";
import Utils from "../util/Utils";
import Mask from "./misc/Mask";
import "./MainView.scss";
import { openForEditing } from "../action/AsyncWorkspaceActions";
import Constants from "../util/Constants";
import Routing from "../util/Routing";
import { Configuration, DEFAULT_CONFIGURATION } from "../model/Configuration";
import Breadcrumbs from "./breadcrumb/Breadcrumbs";
Expand All @@ -45,50 +43,27 @@ interface MainViewProps extends HasI18n, RouteComponentProps<any> {
user: User;
configuration: Configuration;
loadUser: () => Promise<any>;
openContextsForEditing: (contexts: string[]) => Promise<any>;
loadTermStates: () => void;
sidebarExpanded: boolean;
desktopView: boolean;
changeView: () => void;
}

interface MainViewState {
loadingWorkspace: boolean;
}

export class MainView extends React.Component<MainViewProps, MainViewState> {
export class MainView extends React.Component<MainViewProps> {
constructor(props: MainViewProps) {
super(props);
this.state = { loadingWorkspace: false };
}

public componentDidMount(): void {
this.props.loadTermStates();
if (this.props.user === EMPTY_USER) {
Routing.saveOriginalTarget();
this.props.loadUser().then(() => {
this.loadWorkspace();
});
} else {
this.loadWorkspace();
this.props.loadUser();
}

window.addEventListener("resize", this.handleResize, false);
}

private loadWorkspace() {
let contexts = Utils.extractQueryParams(
this.props.location.search,
Constants.WORKSPACE_EDITABLE_CONTEXT_PARAM
);
if (contexts.length > 0) {
this.setState({ loadingWorkspace: true });
this.props
.openContextsForEditing(contexts)
.then(() => this.setState({ loadingWorkspace: false }));
}
}

public componentWillUnmount(): void {
window.removeEventListener("resize", this.handleResize, false);
}
Expand All @@ -108,8 +83,7 @@ export class MainView extends React.Component<MainViewProps, MainViewState> {

if (
user === EMPTY_USER ||
this.props.configuration === DEFAULT_CONFIGURATION ||
this.state.loadingWorkspace
this.props.configuration === DEFAULT_CONFIGURATION
) {
return this.renderPlaceholder();
}
Expand Down Expand Up @@ -224,8 +198,6 @@ export default connect(
loadUser: () => dispatch(loadUser()),
changeView: () => dispatch(changeView()),
loadTermStates: () => dispatch(loadTermStates()),
openContextsForEditing: (contexts: string[]) =>
dispatch(openForEditing(contexts)),
};
}
)(
Expand Down
62 changes: 0 additions & 62 deletions src/component/__tests__/MainView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import Generator from "../../__tests__/environment/Generator";
import Constants from "../../util/Constants";
import Breadcrumbs from "../breadcrumb/Breadcrumbs";
import { vi } from "vitest";
import { flushPromises } from "../../__tests__/environment/Environment";

describe("MainView", () => {
let loadUser: () => Promise<any>;
let logout: () => void;
let changeView: () => void;
let openContextsForEditing: () => Promise<any>;
let loadTermStates: () => void;

const nonEmptyUser = new User({
Expand All @@ -39,7 +37,6 @@ describe("MainView", () => {
let actions: {
loadUser: () => Promise<any>;
logout: () => void;
openContextsForEditing: (contexts: string[]) => Promise<any>;
changeView: () => void;
loadTermStates: () => void;
};
Expand All @@ -48,12 +45,10 @@ describe("MainView", () => {
loadUser = vi.fn().mockResolvedValue({});
logout = vi.fn();
changeView = vi.fn();
openContextsForEditing = vi.fn().mockResolvedValue({});
loadTermStates = vi.fn();
actions = {
loadUser,
logout,
openContextsForEditing,
changeView,
loadTermStates,
};
Expand All @@ -75,63 +70,6 @@ describe("MainView", () => {
expect(loadUser).toHaveBeenCalled();
});

it("opens vocabularies for editing after loading user when their context IRIs are specified in query", async () => {
const contextsToEdit = [Generator.generateUri(), Generator.generateUri()];
const routing = routingProps();
routing.location.search = contextsToEdit
.map((c) => `edit-context=${encodeURIComponent(c)}`)
.join("&");
shallow(
<MainView
user={EMPTY_USER}
sidebarExpanded={true}
desktopView={true}
configuration={DEFAULT_CONFIGURATION}
{...actions}
{...intlFunctions()}
{...routing}
/>
);
await flushPromises();
expect(openContextsForEditing).toHaveBeenCalledWith(contextsToEdit);
});

it("opens vocabularies for editing when their context IRIs are specified in query", () => {
const contextsToEdit = [Generator.generateUri(), Generator.generateUri()];
const routing = routingProps();
routing.location.search = contextsToEdit
.map((c) => `edit-context=${encodeURIComponent(c)}`)
.join("&");
shallow(
<MainView
user={nonEmptyUser}
sidebarExpanded={true}
desktopView={true}
configuration={DEFAULT_CONFIGURATION}
{...actions}
{...intlFunctions()}
{...routing}
/>
);

expect(openContextsForEditing).toHaveBeenCalledWith(contextsToEdit);
});

it("does not attempt to open vocabularies when no context IRIs are provided in query", () => {
shallow(
<MainView
user={nonEmptyUser}
sidebarExpanded={true}
desktopView={true}
configuration={DEFAULT_CONFIGURATION}
{...actions}
{...intlFunctions()}
{...routingProps()}
/>
);
expect(openContextsForEditing).not.toHaveBeenCalled();
});

it("does not load user when it is already present in store", () => {
shallow(
<MainView
Expand Down
1 change: 0 additions & 1 deletion src/util/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const constants = {
EMPTY_ASSET_IRI: "http://empty",
LAST_COMMENTED_ASSET_LIMIT: 5,
ANNOTATOR_TUTORIAL: {},
WORKSPACE_EDITABLE_CONTEXT_PARAM: "edit-context",
TIMESTAMP_PARAM_FORMAT: "yyyyMMdd'T'HHmmss'Z'",
FTS_SNIPPET_TEXT_SIZE: 250,
// Search debounce delay in milliseconds
Expand Down