@finos/legend-studio
Version:
57 lines • 4.17 kB
JavaScript
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 { forwardRef, useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import { WorkspaceType } from '@finos/legend-server-sdlc';
import { compareLabelFn, CustomSelectorInput, PlusIcon, UserIcon, UsersIcon, GitBranchIcon, } from '@finos/legend-art';
import { generateSetupRoute } from '../../stores/LegendStudioRouter.js';
import { useWorkspaceSetupStore } from './WorkspaceSetupStoreProvider.js';
import { useLegendStudioApplicationStore } from '../LegendStudioBaseStoreProvider.js';
const formatOptionLabel = (option) => (_jsxs("div", { className: "workspace-setup__workspace__label", children: [_jsx("div", { className: "workspace-setup__workspace__label-icon", children: option.value.workspaceType === WorkspaceType.GROUP ? (_jsx(UsersIcon, {})) : (_jsx(UserIcon, {})) }), _jsx("div", { className: "workspace-setup__workspace__label__name", children: option.label })] }));
export const WorkspaceSelector = observer(forwardRef(function WorkspaceSelector(props, ref) {
const { onChange, create } = props;
const setupStore = useWorkspaceSetupStore();
const applicationStore = useLegendStudioApplicationStore();
const currentWorkspaceCompositeId = setupStore.currentWorkspaceCompositeId;
const options = setupStore.currentProjectWorkspaceOptions.sort(compareLabelFn);
const selectedOption = options.find((option) => setupStore.buildWorkspaceCompositeId(option.value) ===
currentWorkspaceCompositeId) ?? null;
const isLoadingOptions = setupStore.loadProjectsState.isInProgress ||
setupStore.loadWorkspacesState.isInProgress;
const onSelectionChange = (val) => {
if ((val !== null || selectedOption !== null) &&
(!val || !selectedOption || val.value !== selectedOption.value)) {
setupStore.setCurrentWorkspaceIdentifier(val?.value);
onChange(Boolean(selectedOption));
applicationStore.navigator.goTo(generateSetupRoute(setupStore.currentProjectId ?? '', val?.value.workspaceId, val?.value.workspaceType));
}
};
useEffect(() => {
if (setupStore.currentProjectWorkspaces && !currentWorkspaceCompositeId) {
onChange(false);
}
}, [setupStore.currentProjectWorkspaces, setupStore.currentProjectId, currentWorkspaceCompositeId, onChange]);
const workspaceSelectorPlacerHold = isLoadingOptions
? 'Loading workspaces'
: !setupStore.currentProjectId
? 'In order to select a workspace, a project must be selected'
: options.length
? 'Choose an existing workspace'
: 'You have no workspaces. Please create one';
return (_jsxs("div", { className: "workspace-setup-selector", children: [_jsx("div", { className: "workspace-setup-selector__icon-box", children: _jsx(GitBranchIcon, { className: "workspace-setup-selector__icon" }) }), _jsx(CustomSelectorInput, { className: "workspace-setup-selector__input", allowCreating: false, ref: ref, options: options, disabled: !setupStore.currentProjectId || isLoadingOptions, isLoading: isLoadingOptions, onChange: onSelectionChange, formatOptionLabel: formatOptionLabel, value: selectedOption, placeholder: workspaceSelectorPlacerHold, isClearable: true, escapeClearsValue: true, darkMode: true }), _jsx("button", { className: "workspace-setup-selector__action btn--dark", onClick: create, tabIndex: -1, title: "Create a Workspace", children: _jsx(PlusIcon, {}) })] }));
}));
//# sourceMappingURL=WorkspaceSelector.js.map