From 32f264692aea6bd22f7a61d6d34af6f1b2d689de Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Thu, 9 Jul 2026 14:44:44 +0200 Subject: [PATCH] [kbss-cvut/termit#397] Remove obsolete support for vocabulary editing workspaces. --- src/action/ActionType.ts | 2 - src/action/AsyncWorkspaceActions.ts | 28 ---------- src/component/MainView.tsx | 34 ++----------- src/component/__tests__/MainView.test.tsx | 62 ----------------------- src/util/Constants.ts | 1 - 5 files changed, 3 insertions(+), 124 deletions(-) delete mode 100644 src/action/AsyncWorkspaceActions.ts diff --git a/src/action/ActionType.ts b/src/action/ActionType.ts index d8569be17..2c210eaf7 100644 --- a/src/action/ActionType.ts +++ b/src/action/ActionType.ts @@ -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", diff --git a/src/action/AsyncWorkspaceActions.ts b/src/action/AsyncWorkspaceActions.ts deleted file mode 100644 index ecac6e708..000000000 --- a/src/action/AsyncWorkspaceActions.ts +++ /dev/null @@ -1,28 +0,0 @@ -import ActionType from "./ActionType"; -import { ThunkDispatch } from "../util/Types"; -import Ajax, { content } from "../util/Ajax"; -import Constants from "../util/Constants"; -import { - asyncActionFailure, - asyncActionRequest, - asyncActionSuccess, -} from "./SyncActions"; -import { ErrorData } from "../model/ErrorInfo"; -import * as SyncActions from "./SyncActions"; -import Message from "../model/Message"; -import MessageType from "../model/MessageType"; - -export function openForEditing(contexts: string[]) { - const action = { type: ActionType.OPEN_CONTEXTS_FOR_EDITING }; - return (dispatch: ThunkDispatch) => { - dispatch(asyncActionRequest(action, true)); - return Ajax.put(`${Constants.API_PREFIX}/workspace`, content(contexts)) - .then(() => dispatch(asyncActionSuccess(action))) - .catch((error: ErrorData) => { - dispatch(asyncActionFailure(action, error)); - return dispatch( - SyncActions.publishMessage(new Message(error, MessageType.ERROR)) - ); - }); - }; -} diff --git a/src/component/MainView.tsx b/src/component/MainView.tsx index e0aa4d12c..3f4ec31d9 100644 --- a/src/component/MainView.tsx +++ b/src/component/MainView.tsx @@ -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"; @@ -45,50 +43,27 @@ interface MainViewProps extends HasI18n, RouteComponentProps { user: User; configuration: Configuration; loadUser: () => Promise; - openContextsForEditing: (contexts: string[]) => Promise; loadTermStates: () => void; sidebarExpanded: boolean; desktopView: boolean; changeView: () => void; } -interface MainViewState { - loadingWorkspace: boolean; -} - -export class MainView extends React.Component { +export class MainView extends React.Component { 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); } @@ -108,8 +83,7 @@ export class MainView extends React.Component { if ( user === EMPTY_USER || - this.props.configuration === DEFAULT_CONFIGURATION || - this.state.loadingWorkspace + this.props.configuration === DEFAULT_CONFIGURATION ) { return this.renderPlaceholder(); } @@ -224,8 +198,6 @@ export default connect( loadUser: () => dispatch(loadUser()), changeView: () => dispatch(changeView()), loadTermStates: () => dispatch(loadTermStates()), - openContextsForEditing: (contexts: string[]) => - dispatch(openForEditing(contexts)), }; } )( diff --git a/src/component/__tests__/MainView.test.tsx b/src/component/__tests__/MainView.test.tsx index a6371786c..21a264ba7 100644 --- a/src/component/__tests__/MainView.test.tsx +++ b/src/component/__tests__/MainView.test.tsx @@ -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; let logout: () => void; let changeView: () => void; - let openContextsForEditing: () => Promise; let loadTermStates: () => void; const nonEmptyUser = new User({ @@ -39,7 +37,6 @@ describe("MainView", () => { let actions: { loadUser: () => Promise; logout: () => void; - openContextsForEditing: (contexts: string[]) => Promise; changeView: () => void; loadTermStates: () => void; }; @@ -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, }; @@ -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( - - ); - 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( - - ); - - expect(openContextsForEditing).toHaveBeenCalledWith(contextsToEdit); - }); - - it("does not attempt to open vocabularies when no context IRIs are provided in query", () => { - shallow( - - ); - expect(openContextsForEditing).not.toHaveBeenCalled(); - }); - it("does not load user when it is already present in store", () => { shallow(