Skip to content

Commit

Permalink
updated the backednd call
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi2506 committed Jan 25, 2024
1 parent 98f5d79 commit 5d60fc4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 39 deletions.
5 changes: 3 additions & 2 deletions metecho/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,15 @@ def get_unsaved_changes(scratch_org, *, originating_user_id):
)
get_unsaved_changes_job = job(get_unsaved_changes)

def get_nonsource_components(scratch_org,*,desired_type,originating_user_id):
def get_nonsource_components(*,scratch_org,desired_type,originating_user_id):
try:
scratch_org.refresh_from_db()
data= desired_type["desiredType"]
with dataset_env(scratch_org) as (project_config, org_config, sf, schema, repo):
components=ListComponents(
org_config=org_config,
project_config=project_config,
task_config=TaskConfig({"options":{"metadata_type":desired_type}}),
task_config=TaskConfig({"options":{"metadata_type":data}}),
)()

scratch_org.metadatatype_changes[desired_type]=[cmp["MemberName"] for cmp in components]
Expand Down
4 changes: 2 additions & 2 deletions metecho/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,12 +1476,12 @@ def queue_get_unsaved_changes(self, *, force_get=False, originating_user_id):

get_unsaved_changes_job.delay(self, originating_user_id=originating_user_id)

def queue_get_nonsource_components(self,*,desired_type,originating_user_id):
def queue_get_nonsource_components(self,*,originating_user_id,desiredType: str):
from .jobs import get_nonsource_components_job
self.currently_refreshing_changes = True
self.save()
self.notify_changed(originating_user_id=originating_user_id)
get_nonsource_components_job.delay(self,desired_type,originating_user_id=originating_user_id)
get_nonsource_components_job.delay(self,desired_type=desiredType,originating_user_id=originating_user_id)

def finalize_get_unsaved_changes(self, *, error=None, originating_user_id):
self.currently_refreshing_changes = False
Expand Down
4 changes: 3 additions & 1 deletion metecho/api/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from django.contrib.auth import get_user_model
from django.contrib.sites.shortcuts import get_current_site
from django.db.models import Case, IntegerField, Q, When
Expand Down Expand Up @@ -74,7 +75,7 @@
)

User = get_user_model()

logger = logging.getLogger()

class RepoPushPermission(BasePermission):
"""
Expand Down Expand Up @@ -716,6 +717,7 @@ def listmetadata(self,request,pk=None):
{"error": _("Requesting user did not create Org.")},
status=status.HTTP_403_FORBIDDEN,
)
logger.info(serializer.validated_data["desiredType"])
scratch_org.queue_get_nonsource_components(**serializer.validated_data,originating_user_id=str(request.user.id))
return Response(
self.get_serializer(scratch_org).data, status=status.HTTP_202_ACCEPTED
Expand Down
57 changes: 23 additions & 34 deletions src/js/components/tasks/retrieveMetadata/changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import classNames from 'classnames';
import React, { ChangeEvent, RefObject, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { OBJECT_TYPES } from '@/js/utils/constants';
import { ApiError } from '@/js/utils/api';
import { ThunkDispatch } from '@/js/store';
import { useDispatch } from 'react-redux';
import apiFetch, { addUrlParams } from '@/js/utils/api';
import {
BooleanObject,
MetadataCommit,
ModalCard,
} from '@/js/components/tasks/retrieveMetadata';
import { UseFormProps,useForm,useFormDefaults, } from '@/js/components/utils';
import { UseFormProps, useForm, useFormDefaults } from '@/js/components/utils';
import { Changeset } from '@/js/store/orgs/reducer';
import { mergeChangesets, splitChangeset } from '@/js/utils/helpers';

Expand Down Expand Up @@ -144,7 +146,7 @@ const ChangesForm = ({
}: Props) => {
const { t } = useTranslation();
const [expandedPanels, setExpandedPanels] = useState<BooleanObject>({});

const dispatch = useDispatch<ThunkDispatch>();
// remove ignored changes from full list
const { remaining: filteredChanges } = splitChangeset(
changeset,
Expand Down Expand Up @@ -184,45 +186,32 @@ const ChangesForm = ({
});
};

const handlemetadataToggle = (groupName: string) => {

const handlemetadataToggle = async (groupName: string) => {
setExpandedPanels({
...expandedPanels,
[groupName]: !expandedPanels[groupName],
});
const match = groupName.match(/changes-(.+)/);

// Check if there is a match and get the group name
const alpha = match ? match[1] : null;
if (expandedPanels[groupName]) {
const {inputs,
errors,
handleInputChange,
setInputs,
handleSubmit,
resetForm,} =
useForm({
fields: {
desiredType: groupName,
} as Components,
objectType: OBJECT_TYPES.ORG,
url: window.api_urls.scratch_org_listmetadata(id),
onSuccess: handleSuccess,
onError: handleError,
shouldSubscribeToObject: false,
});
await apiFetch({
url: window.api_urls.scratch_org_listmetadata(id),
dispatch,
opts: {
method: 'POST',
body: JSON.stringify({
desiredType: alpha,
}),
headers: {
'Content-Type': 'application/json',
},
},
});
}
};

const handleSuccess = () => {
/* istanbul ignore else */

};

// eslint-disable-next-line handle-callback-err
const handleError = (
err: ApiError,
fieldErrors: { [key: string]: string },
) => {

};

const updateChecked = (changes: Changeset, checked: boolean) => {
if (checked) {
setChanges(mergeChangesets(inputs.changes, changes));
Expand Down

0 comments on commit 5d60fc4

Please sign in to comment.