Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor:code formatted by precommit
  • Loading branch information
AishDani committed May 15, 2024
commit 46ec28e0c7b36ecc95e3bda1914dea4d0eeeb1f7
177 changes: 88 additions & 89 deletions ui/src/components/DestinationStack/Actions/LoadStacks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext, useState } from 'react';
import { AsyncSelect, Icon, cbModal } from '@contentstack/venus-components';
import { AsyncSelect, Icon, cbModal } from '@contentstack/venus-components';

import { AppContext } from '../../../context/app/app.context';
import { DEFAULT_DROPDOWN, IDropDown, INewMigration } from '../../../context/app/app.interface';
Expand Down Expand Up @@ -116,27 +116,25 @@ const LoadStacks = (props: LoadFileFormatProps) => {
const stackChanged = selectedStack?.value !== data?.value;
const stackCleared = data?.value === '' || data?.value === null || data === null;

if (name === 'stacks') {
setSelectedStack(() => ({ ...data }));

const newMigrationDataObj: INewMigration = {
...newMigrationData,
destination_stack: {
...newMigrationData?.destination_stack,
selectedStack: stackCleared ? DEFAULT_DROPDOWN : { ...data }
}
};

updateNewMigrationData(newMigrationDataObj);

if (!stackCleared) {

if (props?.handleStepChange) {
props?.handleStepChange(props?.currentStep, true);
}
if (name === 'stacks') {
setSelectedStack(() => ({ ...data }));

const newMigrationDataObj: INewMigration = {
...newMigrationData,
destination_stack: {
...newMigrationData?.destination_stack,
selectedStack: stackCleared ? DEFAULT_DROPDOWN : { ...data }
}
};

updateNewMigrationData(newMigrationDataObj);

if (!stackCleared) {
if (props?.handleStepChange) {
props?.handleStepChange(props?.currentStep, true);
}
}
}

};

const fetchData = async () => {
Expand Down Expand Up @@ -214,88 +212,89 @@ const LoadStacks = (props: LoadFileFormatProps) => {
});
};

const loadMoreOptions: any = async ({ search, skip, limit }: { search: string; skip: number; limit: number }) => {


const stackData = await getAllStacksInOrg(
newMigrationData?.destination_stack?.selectedOrg?.value
); //org id will always be there

const stackArray = validateArray(stackData?.data?.stacks)
? stackData?.data?.stacks?.map((stack: StackResponse) => ({
label: stack?.name,
value: stack?.api_key,
uid: stack?.api_key,
master_locale: stack?.master_locale,
locales: stack?.locales,
created_at: stack?.created_at
}))
: [];

stackArray.sort(
(a: IDropDown, b: IDropDown) =>{
(new Date(b?.created_at)?.getTime()) - (new Date(a?.created_at)?.getTime())}
);

setAllStack(stackArray);

//Set selected Stack
const selectedStackData = validateArray(stackArray)
? stackArray.find(
(stack: IDropDown) =>
stack?.value === newMigrationData?.destination_stack?.selectedStack?.value
)
: DEFAULT_DROPDOWN;

setSelectedStack(selectedStackData);

const newMigrationDataObj: INewMigration = {
...newMigrationData,
destination_stack: {
...newMigrationData?.destination_stack,
selectedStack: selectedStackData
}
};

updateNewMigrationData(newMigrationDataObj);

return {options: stackArray};

}
const onBlurDropdown = () => {

const loadMoreOptions: any = async ({
search,
skip,
limit
}: {
search: string;
skip: number;
limit: number;
}) => {
const stackData = await getAllStacksInOrg(
newMigrationData?.destination_stack?.selectedOrg?.value
); //org id will always be there

const stackArray = validateArray(stackData?.data?.stacks)
? stackData?.data?.stacks?.map((stack: StackResponse) => ({
label: stack?.name,
value: stack?.api_key,
uid: stack?.api_key,
master_locale: stack?.master_locale,
locales: stack?.locales,
created_at: stack?.created_at
}))
: [];

stackArray.sort((a: IDropDown, b: IDropDown) => {
new Date(b?.created_at)?.getTime() - new Date(a?.created_at)?.getTime();
});

setAllStack(stackArray);

//Set selected Stack
const selectedStackData = validateArray(stackArray)
? stackArray.find(
(stack: IDropDown) =>
stack?.value === newMigrationData?.destination_stack?.selectedStack?.value
)
: DEFAULT_DROPDOWN;

setSelectedStack(selectedStackData);

const newMigrationDataObj: INewMigration = {
...newMigrationData,
destination_stack: {
...newMigrationData?.destination_stack,
selectedStack: selectedStackData
}
};

updateNewMigrationData(newMigrationDataObj);

return { options: stackArray };
};
const onBlurDropdown = () => {
if (!isEmptyString(selectedStack?.value)) {
if (props?.handleStepChange) {
props?.handleStepChange(props?.currentStep, true);
}
}
};

return (
<div className="">

<div className="action-summary-wrapper ">
<div className="service_list ">
<div className="row">
<div className="col-12 pb-3 ">
<div style={{display:'flex'}}>
<div className="Dropdown-wrapper p-0 active ">
<AsyncSelect
version={'v2'}
loadMoreOptions={loadMoreOptions}
onChange={handleDropdownChange('stacks')}
onBlur={onBlurDropdown}
value={selectedStack}
isSearchable={true}
isClearable={true}
width='440px'
isDisabled={props?.stepComponentProps?.isSummary || false}
placeholder={'Stacks'}
limit={10}
/>
<div style={{ display: 'flex' }}>
<div className="Dropdown-wrapper p-0 active ">
<AsyncSelect
version={'v2'}
loadMoreOptions={loadMoreOptions}
onChange={handleDropdownChange('stacks')}
onBlur={onBlurDropdown}
value={selectedStack}
isSearchable={true}
isClearable={true}
width="440px"
isDisabled={props?.stepComponentProps?.isSummary || false}
placeholder={'Stacks'}
limit={10}
/>
</div>
</div>
</div>

</div>
<div className="col-12 pb-2">
<label className="title">Master Locale</label>
Expand Down
15 changes: 6 additions & 9 deletions ui/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ const Modal = (props: ProjectModalProps) => {
};

const nameValidation = (value: string) => {
if(!value){
if (!value) {
setInputValue(false);
return ;
}
else if (!/^[^\s].+[^\s]$/.test(value)) {
return;
} else if (!/^[^\s].+[^\s]$/.test(value)) {
setInputValue(false);
return 'Please enter project name.';
} else if (value && value?.length > 200) {
Expand Down Expand Up @@ -128,10 +127,10 @@ const Modal = (props: ProjectModalProps) => {
placeholder={namePlaceholder}
data-testid="title-input"
name="name"
maxLength='200'
maxLength="200"
error={(meta?.error || meta?.submitError) && meta?.touched}
/>
{meta?.error && (
{meta?.error && (
<ValidationMessage
testId="cs-description-error"
className="mt-2"
Expand All @@ -140,7 +139,6 @@ const Modal = (props: ProjectModalProps) => {
{meta?.error}
</ValidationMessage>
)}

</>
);
}}
Expand All @@ -149,7 +147,6 @@ const Modal = (props: ProjectModalProps) => {
<Field className="mb-30">
<FinalField name="description" validate={descValidation}>
{({ input, meta }): JSX.Element => {

return (
<>
<FieldLabel htmlFor="description" version="v2">
Expand All @@ -170,7 +167,7 @@ const Modal = (props: ProjectModalProps) => {
data-testid="description-input"
error={(meta?.error || meta?.submitError) && meta?.touched}
/>
{meta?.error && (
{meta?.error && (
<ValidationMessage
testId="cs-description-error"
className="mt-2"
Expand Down