/** * 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 { observer } from 'mobx-react-lite'; import { useEditorStore } from '../EditorStoreProvider.js'; import { noop } from '@finos/legend-shared'; import { clsx, ResizablePanel, ResizablePanelGroup, ResizablePanelSplitter, ResizablePanelSplitterLine, InfoCircleIcon, TimesIcon, Dialog, PanelContent, Modal, ModalBody, ModalFooter, ModalHeader, ModalFooterButton, } from '@finos/legend-art'; import type { EntityChangeConflict, EntityDiff, } from '@finos/legend-server-sdlc'; import { EntityChangeConflictEditor, EntityChangeConflictSideBarItem, } from '../editor-group/diff-editor/EntityChangeConflictEditor.js'; import { EntityChangeConflictEditorState } from '../../../stores/editor/editor-state/entity-diff-editor-state/EntityChangeConflictEditorState.js'; import type { EntityDiffViewerState } from '../../../stores/editor/editor-state/entity-diff-editor-state/EntityDiffEditorState.js'; import { EntityDiffSideBarItem, EntityDiffView, } from '../editor-group/diff-editor/EntityDiffView.js'; import { EntityDiffViewState } from '../../../stores/editor/editor-state/entity-diff-editor-state/EntityDiffViewState.js'; import { entityDiffSorter } from '../../../stores/editor/EditorSDLCState.js'; import { flowResult } from 'mobx'; import { useApplicationStore } from '@finos/legend-application'; export const WorkspaceSyncConflictResolver = observer(() => { const editorStore = useEditorStore(); const applicationStore = useApplicationStore(); const updateState = editorStore.localChangesState.workspaceSyncState; const updateConflictState = updateState.workspaceSyncConflictResolutionState; const currentDiffEditorState = updateConflictState.currentDiffEditorState; const openMergedEditorStates = updateConflictState.openMergedEditorStates; const conflicts = updateConflictState.pendingConflicts; const hadResolvedAllConflicts = !conflicts.length; const changes = updateConflictState.changes; const openConflict = (conflict: EntityChangeConflict): (() => void) => (): void => { updateConflictState.openConflict(conflict); }; const isSelectedConflict = (conflict: EntityChangeConflict): boolean => currentDiffEditorState instanceof EntityChangeConflictEditorState && conflict.entityPath === currentDiffEditorState.entityPath; const closeTabOnMiddleClick = (conflictState: EntityDiffViewerState): React.MouseEventHandler => (event): void => { if (event.nativeEvent.button === 1) { updateConflictState.closeConflict(conflictState); } }; const closeTab = (conflictState: EntityDiffViewerState): React.MouseEventHandler => (event): void => updateConflictState.closeConflict(conflictState); const openTab = (conflictState: EntityDiffViewerState): (() => void) => (): void => updateConflictState.openState(conflictState); const isSelectedDiff = (diff: EntityDiff): boolean => currentDiffEditorState instanceof EntityDiffViewState && diff.oldPath === currentDiffEditorState.fromEntityPath && diff.newPath === currentDiffEditorState.toEntityPath; const openChange = (diff: EntityDiff): (() => void) => (): void => { updateConflictState.openConflictResolutionChange(diff); }; const applyResolutions = (): void => { if (!conflicts.length) { flowResult(updateState.applyResolutionChanges()).catch( applicationStore.alertUnhandledError, ); } }; const abort = (): void => updateState.resetConflictState(); return (
All Changes
CHANGES
{changes.length + conflicts.length}
{!hadResolvedAllConflicts && ( <> {conflicts .toSorted((a, b) => a.entityName.localeCompare(b.entityName), ) .map((conflict) => ( ))} {Boolean(conflicts.length) && Boolean(changes.length) && (
)} {changes.toSorted(entityDiffSorter).map((diff) => ( ))} )} {hadResolvedAllConflicts && changes .toSorted(entityDiffSorter) .map((diff) => ( ))}
{openMergedEditorStates.map((mergedState) => (
))}
{updateConflictState.currentDiffEditorState instanceof EntityChangeConflictEditorState && ( )} {updateConflictState.currentDiffEditorState instanceof EntityDiffViewState && ( )}
); });