/** * 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 { useState } from 'react'; import { observer } from 'mobx-react-lite'; import { clsx, Dialog, TimesIcon, PanelLoadingIndicator, PencilIcon, MarkdownTextViewer, Modal, PanelFormListItems, PanelFormTextField, PanelFormSection, PanelFormActions, PanelForm, PanelDivider, } from '@finos/legend-art'; import { LEGEND_STUDIO_TEST_ID } from '../../__lib__/LegendStudioTesting.js'; import { isNumber } from '@finos/legend-shared'; import { flowResult } from 'mobx'; import { useConditionedApplicationNavigationContext } from '@finos/legend-application'; import { LEGEND_STUDIO_DOCUMENTATION_KEY } from '../../__lib__/LegendStudioDocumentation.js'; import { LEGEND_STUDIO_APPLICATION_NAVIGATION_CONTEXT_KEY } from '../../__lib__/LegendStudioApplicationNavigationContext.js'; import { useLegendStudioApplicationStore } from '../LegendStudioFrameworkProvider.js'; import { useWorkspaceSetupStore } from './WorkspaceSetup.js'; import { DocumentationLink } from '@finos/legend-lego/application'; enum CREATE_PROJECT_MODAL_TAB { CREATE = 'CREATE', IMPORT = 'IMPORT', } const artifactIdPattern = new RegExp('^[a-z][a-z\\d_]*(?:-[a-z][a-z\\d_]*)*$'); const CreateNewProjectTab = observer(() => { const setupStore = useWorkspaceSetupStore(); const applicationStore = useLegendStudioApplicationStore(); const documentation = applicationStore.documentationService.getDocEntry( LEGEND_STUDIO_DOCUMENTATION_KEY.CREATE_PROJECT, ); const allowCreatingNewProject = setupStore.sdlcServerClient.features.canCreateProject; const [projectName, setProjectName] = useState(''); const [groupId, setGroupId] = useState(''); const [artifactId, setArtifactId] = useState(''); const isArtfactIdInvalid = artifactId !== '' && !artifactIdPattern.test(artifactId); const [description, setDescription] = useState(''); const changeDescription: React.ChangeEventHandler = ( event, ) => { setDescription(event.target.value); }; // tags const [tagValue, setTagValue] = useState(''); const [tagsArray, setTagsArray] = useState>([]); // NOTE: `showEditInput` is either boolean (to hide/show the add value button) or a number (index of the item being edited) const [showEditTagValueInput, setShowEditTagValueInput] = useState< boolean | number >(false); const showAddTagInput = (): void => setShowEditTagValueInput(true); const showEditTagInput = (value: string, idx: number): (() => void) => (): void => { setTagValue(value); setShowEditTagValueInput(idx); }; const hideAddOrEditTagInput = (): void => { setShowEditTagValueInput(false); setTagValue(''); }; const changeTagInputValue: React.ChangeEventHandler = ( event, ) => setTagValue(event.target.value); const addValue = (): void => { if (tagValue && !tagsArray.includes(tagValue)) { setTagsArray([...tagsArray, tagValue]); } hideAddOrEditTagInput(); }; const updateTag = (idx: number): (() => void) => (): void => { if (tagValue && !tagsArray.includes(tagValue)) { tagsArray[idx] = tagValue; setTagsArray(tagsArray); hideAddOrEditTagInput(); } }; const deleteTag = (idx: number): (() => void) => (): void => { const tags = [...tagsArray]; tags.splice(idx, 1); setTagsArray(tags); // Since we keep track of the value currently being edited using the index, we have to account for it as we delete entry if (isNumber(showEditTagValueInput) && showEditTagValueInput > idx) { setShowEditTagValueInput(showEditTagValueInput - 1); } }; const dispatchingActions = setupStore.createOrImportProjectState.isInProgress || setupStore.createWorkspaceState.isInProgress; const disableSubmit = dispatchingActions || !projectName || !artifactId || !groupId; const handleSubmit = (): void => { if (projectName && groupId && artifactId) { if (allowCreatingNewProject) { flowResult( setupStore.createProject( projectName, description, groupId, artifactId, tagsArray, ), ).catch(applicationStore.alertUnhandledError); } } }; if (!allowCreatingNewProject) { return (
SDLC server does not support creating new projects
{documentation?.markdownText && (
)}
); } return (
{ event.preventDefault(); handleSubmit(); }} > {documentation?.markdownText && (
)} setProjectName(value ?? '') } isReadOnly={false} />
Description