ToolJet/frontend/src/Editor/AppVersionsManager/CreateVersionModal.jsx
Kiran Ashok e5d75bd4cf
Feat :: Editor UI revamp (#7275)
* temp commit ::  editor redesign

* fix :: components panel ui

* style updates

* fix :: arrangement widget list

* fix :: light mode widget list

* style fixes query manager

* updates

* updates heaer styles

* global settings fix

* left sidebar states and icon change

* cleanup

* minor fixes :: review

* fix opacity mode toggle

* detailing in hover states , bugfixes

* fix :: coloring whole app , debugger ui

* cleanup

* fix :: revert some changes , fix statistics widget

* feat :: navbar with new layout

* fix :: lint warnings

* cleanup

* cleanup

* minor fixes

* fix :: reusing serchbox

* removed unwanted prop

* Revert "cleanup"

This reverts commit b18abe19fb.

* fix :: icons sidebar

* fix :: padding searchbar

* style fix

* radix :: dark theme for portals

* fix :: icon styles

* fix :: all codehinter styles

* update :: base bg color app

* fix :: viewer color

* minor fixes :: icon left sidebar

* typo

* fix :: styling save message header

* icon :: fix for layout and inspector queries

* fix :: canvas and editor bg

* fix :: release btn style

* fix :: navbar border

* undo redo tooltip

* fix :: page input

* remove released btn icon

* fix :: for icon not loading proper in inspector

* fix :: dark mode toggle icon size

* fix :: share  app ui

* fix :: style fixes , inspector runpy icon

* fix :: ui runpy codehinter

* fix :: inputs in gds connection

* cleanup

* fix :: copilot codehinter ui

* fix :: share modal button

* fix :: canvas bg text

* style fix debugger

* fix :: whole dahsboard layout and border for all codehinters

* fix :: icon fills

* fix :: icon fill color sidebar

* darkmode fill color

* minor style fix

* Widget inspector redesign (#7355)

* Setup Storybook

* Update storybook config

* Add tab and toggle group component

* Created list component

* Properties tab

* update codehinter dropdown components

* Refactor styling

* Inspector header changes

* Fix es lint issue

* Fix

* feat :: styling color picker styles panel

* Fix color picker alignment

* feat :: remove alpha

* Fix UI bugs

* fix :: color picker

* Ui fix

* Backward compatible pagination changes

* fix

* Feedback changes

* UI feedback

* Check fix

* Fix

* fix :: canvas bg popover

* Styles fix

* Fix conflct issues

* minor style fix style tab

* Fix

* review comments fix :: hovering in color picker

* Code review and design feedback

* UI feedback

* Fix UI styles

* Fix pagination issue

* fix :: dark mode issues in select , number input

* fix :: remove extra boreder

* fix :: table column popover ui and component popover inspector

* fix :: datepickre input table column

* fix :: colopicker in table column inspector

* fix :: link column type ui in table

* fix :: column delete ui and delete not triggering

* Fix list item not dragging

* fix :: closing of popover on link column select

* style fix table popover

* Pass dark mode to Event manager button

* fix :: ux event manager

* cleanup

* cleanup

* fix :: delete page modal ui

---------

Co-authored-by: stepinfwd <stepinfwd@gmail.com>

* style fixes

---------

Co-authored-by: Nakul Nagargade <133095394+nakulnagargade@users.noreply.github.com>
2023-09-04 13:30:39 +05:30

140 lines
4.4 KiB
JavaScript

import React, { useState } from 'react';
import { appVersionService } from '@/_services';
import AlertDialog from '@/_ui/AlertDialog';
import { toast } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
import Select from '@/_ui/Select';
import { useAppVersionStore } from '@/_stores/appVersionStore';
import { shallow } from 'zustand/shallow';
export const CreateVersion = ({
appId,
appVersions,
setAppVersions,
setAppDefinitionFromVersion,
showCreateAppVersion,
setShowCreateAppVersion,
}) => {
const [isCreatingVersion, setIsCreatingVersion] = useState(false);
const [versionName, setVersionName] = useState('');
const { t } = useTranslation();
const { editingVersion } = useAppVersionStore(
(state) => ({
editingVersion: state.editingVersion,
}),
shallow
);
const createVersion = () => {
if (versionName.trim().length > 25) {
toast.error('Version name should not be longer than 25 characters');
return;
}
if (versionName.trim() == '') {
toast.error('Version name should not be empty');
return;
}
setIsCreatingVersion(true);
appVersionService
.create(appId, versionName, editingVersion.id)
.then(() => {
toast.success('Version Created');
appVersionService.getAll(appId).then((data) => {
setVersionName('');
setIsCreatingVersion(false);
setAppVersions(data.versions);
const latestVersion = data.versions.at(0);
setAppDefinitionFromVersion(latestVersion);
setShowCreateAppVersion(false);
});
})
.catch((error) => {
toast.error(error?.error);
setIsCreatingVersion(false);
});
};
const options = appVersions.map((version) => {
return { label: version.name, value: version };
});
return (
<AlertDialog
show={showCreateAppVersion}
closeModal={() => {
setVersionName('');
setShowCreateAppVersion(false);
}}
title={t('editor.appVersionManager.createVersion', 'Create new version')}
>
<form
onSubmit={(e) => {
e.preventDefault();
createVersion();
}}
>
<div className="mb-3 pb-2">
<div className="col tj-app-input">
<label className="form-label" data-cy="version-name-label">
{t('editor.appVersionManager.versionName', 'Version Name')}
</label>
<input
type="text"
onChange={(e) => setVersionName(e.target.value)}
className="form-control"
data-cy="version-name-input-field"
placeholder={t('editor.appVersionManager.enterVersionName', 'Enter version name')}
disabled={isCreatingVersion}
value={versionName}
autoFocus={true}
minLength="1"
maxLength="25"
/>
</div>
</div>
<div className="mb-4 pb-2 version-select">
<label className="form-label" data-cy="create-version-from-label">
{t('editor.appVersionManager.createVersionFrom', 'Create version from')}
</label>
<div className="ts-control" data-cy="create-version-from-input-field">
<Select
options={options}
defaultValue={options.find((option) => option?.value?.id === editingVersion?.id)}
onChange={(version) => {
setAppDefinitionFromVersion(version, false);
}}
useMenuPortal={false}
width="100%"
maxMenuHeight={100}
/>
</div>
</div>
<div className="mb-3">
<div className="col d-flex justify-content-end">
<button
className="btn mx-2"
data-cy="cancel-button"
onClick={() => {
setVersionName('');
setShowCreateAppVersion(false);
}}
type="button"
>
{t('globals.cancel', 'Cancel')}
</button>
<button
className={`btn btn-primary ${isCreatingVersion ? 'btn-loading' : ''}`}
data-cy="create-new-version-button"
type="submit"
>
{t('editor.appVersionManager.createVersion', 'Create Version')}
</button>
</div>
</div>
</form>
</AlertDialog>
);
};