UNPKG

@finos/legend-studio

Version:
103 lines 9.94 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { useEffect } from 'react'; import { observer } from 'mobx-react-lite'; import { EntityDiffViewState } from '../../../stores/editor-state/entity-diff-editor-state/EntityDiffViewState.js'; import { EntityDiffSideBarItem } from '../../editor/edit-panel/diff-editor/EntityDiffView.js'; import { clsx, PanelLoadingIndicator, ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, ResizablePanelSplitterLine, CloudDownloadIcon, RefreshIcon, InfoCircleIcon, } from '@finos/legend-art'; import { Link } from 'react-router-dom'; import { EntityChangeConflictSideBarItem } from '../../editor/edit-panel/diff-editor/EntityChangeConflictEditor.js'; import { EntityChangeConflictEditorState } from '../../../stores/editor-state/entity-diff-editor-state/EntityChangeConflictEditorState.js'; import { generateReviewRoute } from '../../../stores/LegendStudioRouter.js'; import { LEGEND_STUDIO_TEST_ID } from '../../LegendStudioTestID.js'; import { flowResult } from 'mobx'; import { entityDiffSorter } from '../../../stores/EditorSDLCState.js'; import { useEditorStore } from '../EditorStoreProvider.js'; import { ActionAlertType, ActionAlertActionType, } from '@finos/legend-application'; import { useLegendStudioApplicationStore } from '../../LegendStudioBaseStoreProvider.js'; export const WorkspaceUpdater = observer(() => { const editorStore = useEditorStore(); const applicationStore = useLegendStudioApplicationStore(); const sdlcState = editorStore.sdlcState; const currentEditorState = editorStore.currentEditorState; const workspaceUpdaterState = editorStore.workspaceUpdaterState; // Actions const updateWorkspace = () => { if (editorStore.hasUnpushedChanges) { editorStore.setActionAlertInfo({ message: 'You have unpushed changes', prompt: 'This action will discard these changes and refresh the application', type: ActionAlertType.CAUTION, onEnter: () => editorStore.setBlockGlobalHotkeys(true), onClose: () => editorStore.setBlockGlobalHotkeys(false), actions: [ { label: 'Proceed to update workspace', type: ActionAlertActionType.PROCEED_WITH_CAUTION, handler: () => { editorStore.setIgnoreNavigationBlocking(true); flowResult(workspaceUpdaterState.updateWorkspace()).catch(applicationStore.alertUnhandledError); }, }, { label: 'Abort', type: ActionAlertActionType.PROCEED, default: true, }, ], }); } else { flowResult(workspaceUpdaterState.updateWorkspace()).catch(applicationStore.alertUnhandledError); } }; const refreshWorkspaceUpdater = applicationStore.guardUnhandledError(() => flowResult(workspaceUpdaterState.refreshWorkspaceUpdater())); const isDispatchingAction = workspaceUpdaterState.isUpdatingWorkspace || sdlcState.isCheckingIfWorkspaceIsOutdated || workspaceUpdaterState.isRefreshingWorkspaceUpdater; // Conflicts const conflicts = editorStore.changeDetectionState.potentialWorkspaceUpdateConflicts; const isSelectedConflict = (conflict) => currentEditorState instanceof EntityChangeConflictEditorState && conflict.entityPath === currentEditorState.entityPath; const openPotentialConflict = (conflict) => () => workspaceUpdaterState.openPotentialWorkspaceUpdateConflict(conflict); // Changes const changes = editorStore.changeDetectionState.aggregatedProjectLatestChanges; const changesWithoutConflicts = changes.filter((change) => !conflicts .map((conflict) => conflict.entityPath) .includes(change.entityPath)); const isSelectedDiff = (diff) => currentEditorState instanceof EntityDiffViewState && diff.oldPath === currentEditorState.fromEntityPath && diff.newPath === currentEditorState.toEntityPath; const openChange = (diff) => () => workspaceUpdaterState.openProjectLatestChange(diff); // Committed Reviews const commitedReviews = workspaceUpdaterState.committedReviewsBetweenWorkspaceBaseAndProjectLatest; // since the project latest changes can be affected by other users, we refresh it more proactively useEffect(() => { flowResult(workspaceUpdaterState.refreshWorkspaceUpdater()).catch(applicationStore.alertUnhandledError); }, [applicationStore, workspaceUpdaterState]); return (_jsxs("div", { className: "panel workspace-updater", children: [_jsxs("div", { className: "panel__header side-bar__header", children: [_jsx("div", { className: "panel__header__title workspace-updater__header__title", children: _jsx("div", { className: "panel__header__title__content side-bar__header__title__content", children: "WORKSPACE UPDATER" }) }), _jsxs("div", { className: "panel__header__actions side-bar__header__actions", children: [_jsx("button", { className: clsx('panel__header__action side-bar__header__action workspace-updater__refresh-btn', { 'workspace-updater__refresh-btn--loading': workspaceUpdaterState.isRefreshingWorkspaceUpdater, }), onClick: refreshWorkspaceUpdater, disabled: isDispatchingAction, tabIndex: -1, title: "Refresh", children: _jsx(RefreshIcon, {}) }), _jsx("button", { className: "panel__header__action side-bar__header__action workspace-updater__update-btn", onClick: updateWorkspace, disabled: !sdlcState.isWorkspaceOutdated || isDispatchingAction, tabIndex: -1, title: "Update workspace", children: _jsx(CloudDownloadIcon, {}) })] })] }), _jsxs("div", { className: "panel__content side-bar__content", children: [_jsx(PanelLoadingIndicator, { isLoading: isDispatchingAction }), _jsxs(ResizablePanelGroup, { orientation: "horizontal", children: [_jsx(ResizablePanel, { size: 400, minSize: 28, children: _jsxs("div", { className: "panel side-bar__panel", children: [_jsxs("div", { className: "panel__header", children: [_jsxs("div", { className: "panel__header__title", children: [_jsx("div", { className: "panel__header__title__content", children: "CHANGES" }), _jsx("div", { className: "side-bar__panel__title__info", title: 'All changes made to project since the revision the workspace is created.\nPotential workspace update conflicts are also shown if they exist', children: _jsx(InfoCircleIcon, {}) })] }), _jsx("div", { className: "side-bar__panel__header__changes-count", "data-testid": LEGEND_STUDIO_TEST_ID.SIDEBAR_PANEL_HEADER__CHANGES_COUNT, children: changes.length })] }), _jsxs("div", { className: "panel__content", children: [conflicts .slice() .sort((a, b) => a.entityName.localeCompare(b.entityName)) .map((conflict) => (_jsx(EntityChangeConflictSideBarItem, { conflict: conflict, isSelected: isSelectedConflict(conflict), openConflict: openPotentialConflict(conflict) }, `conflict-${conflict.entityPath}`))), Boolean(conflicts.length) && Boolean(changesWithoutConflicts.length) && (_jsx("div", { className: "diff-panel__item-section-separator" })), changesWithoutConflicts .slice() .sort(entityDiffSorter) .map((diff) => (_jsx(EntityDiffSideBarItem, { diff: diff, isSelected: isSelectedDiff(diff), openDiff: openChange(diff) }, diff.key)))] })] }) }), _jsx(ResizablePanelSplitter, { children: _jsx(ResizablePanelSplitterLine, { color: "var(--color-dark-grey-100)" }) }), _jsx(ResizablePanel, { minSize: 28, children: _jsxs("div", { className: "panel side-bar__panel", children: [_jsxs("div", { className: "panel__header", children: [_jsxs("div", { className: "panel__header__title", children: [_jsx("div", { className: "panel__header__title__content", children: "COMMITTED REVIEWS" }), _jsx("div", { className: "side-bar__panel__title__info", title: "All committed reviews in the project since the revision the workspace is created", children: _jsx(InfoCircleIcon, {}) })] }), _jsx("div", { className: "side-bar__panel__header__changes-count", "data-testid": LEGEND_STUDIO_TEST_ID.SIDEBAR_PANEL_HEADER__CHANGES_COUNT, children: commitedReviews.length })] }), _jsx("div", { className: "panel__content", children: commitedReviews.map((review) => (_jsx(Link, { className: "side-bar__panel__item workspace-updater__review__link", rel: "noopener noreferrer", target: "_blank", to: generateReviewRoute(review.projectId, review.id), title: 'See review detail', children: _jsxs("div", { className: "workspace-updater__review", children: [_jsx("span", { className: "workspace-updater__review__name", children: review.title }), _jsx("span", { className: "workspace-updater__review__info", children: review.author.name })] }) }, review.id))) })] }) })] })] })] })); }); //# sourceMappingURL=WorkspaceUpdater.js.map