Skip to content

Commit

Permalink
fix: load form only if active
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada-codes committed Jan 28, 2022
1 parent 49992c2 commit 6b5897a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
13 changes: 4 additions & 9 deletions src/components/molecules/FormEditor/FormEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,8 @@ const FormContainer = styled.div`
}
`;

interface IProps {
formSchema: any;
formUiSchema: any;
isActive: boolean;
}

const FormEditor = ({formSchema, formUiSchema, isActive}: IProps) => {
const FormEditor = (props: {formSchema: any; formUiSchema: any}) => {
const {formSchema, formUiSchema} = props;
const selectedResource = useSelector(selectedResourceSelector);
const [formData, setFormData] = useState<any>();
const dispatch = useAppDispatch();
Expand All @@ -124,7 +119,7 @@ const FormEditor = ({formSchema, formUiSchema, isActive}: IProps) => {

useDebounce(
() => {
if (selectedResource && isActive) {
if (selectedResource) {
let formString = stringify(formData);
const content = mergeManifests(selectedResource.text, formString);

Expand All @@ -134,7 +129,7 @@ const FormEditor = ({formSchema, formUiSchema, isActive}: IProps) => {
}
},
DEFAULT_EDITOR_DEBOUNCE,
[formData, selectedResource, isActive]
[formData, selectedResource]
);

useEffect(() => {
Expand Down
15 changes: 5 additions & 10 deletions src/components/organisms/ActionsPane/ActionsPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,12 @@ const ActionsPane = (props: {contentHeight: string}) => {
>
{uiState.isFolderLoading || previewLoader.isLoading ? (
<S.Skeleton active />
) : (
) : activeTabKey === 'form' ? (
<FormEditor
isActive={activeTabKey === 'form'}
formSchema={resourceKindHandler.formEditorOptions.editorSchema}
formUiSchema={resourceKindHandler.formEditorOptions.editorUiSchema}
/>
)}
) : null}
</TabPane>
)}
{selectedResource && resourceKindHandler && !isKustomizationResource(selectedResource) && (
Expand All @@ -461,13 +460,9 @@ const ActionsPane = (props: {contentHeight: string}) => {
>
{uiState.isFolderLoading || previewLoader.isLoading ? (
<S.Skeleton active />
) : (
<FormEditor
isActive={activeTabKey === 'metadataForm'}
formSchema={getFormSchema('metadata')}
formUiSchema={getUiSchema('metadata')}
/>
)}
) : activeTabKey === 'metadataForm' ? (
<FormEditor formSchema={getFormSchema('metadata')} formUiSchema={getUiSchema('metadata')} />
) : null}
</TabPane>
)}
</S.Tabs>
Expand Down

0 comments on commit 6b5897a

Please sign in to comment.