Skip to content

Commit

Permalink
Add/Remove component from adapter complete
Browse files Browse the repository at this point in the history
  • Loading branch information
AnumQ committed Aug 4, 2024
1 parent 106bc74 commit 56016c2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 47 deletions.
26 changes: 25 additions & 1 deletion app/api/AdapterApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AdapterAPI {
const URL = `${API_URL}/api/adapters/${organisationName}`;
return await request(URL, functionName);
}

static async createAdapter(adapter: IPartialAdapter, organisationName: string) {
const functionName = 'createAdapter';
const URL = `${API_URL}/api/adapters/${organisationName}`;
Expand All @@ -20,6 +20,30 @@ class AdapterAPI {
return await request(URL, functionName, 'PUT', 'json', adapter);
}

static async updateComponentInAdapter(
componentName: string,
adapterName: string,
organisationName: string,
updateType: string
) {
const URL = `${API_URL}/api/components/organisation/${organisationName}/${componentName}/adapters/${adapterName}`;
if (updateType === 'add') {
return await AdapterAPI.addComponentToAdapter(URL, componentName);
} else {
return await AdapterAPI.removeComponentFromAdapter(URL, componentName);
}
}

static async addComponentToAdapter(URL: string, adapterName: string) {
const functionName = 'addComponentToAdapter';
return await request(URL, functionName, 'PUT', 'json', { name: adapterName });
}

static async removeComponentFromAdapter(URL: string, adapterName: string) {
const functionName = 'removeComponentFromAdapter';
return await request(URL, functionName, 'DELETE', 'json', { name: adapterName });
}

static async deleteAdapter(name: string, organisationName: string) {
const functionName = 'deleteAdapter';
const URL = `${API_URL}/api/adapters/${organisationName}/${name}`;
Expand Down
77 changes: 32 additions & 45 deletions app/routes/adapter.$name.update/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRequestParam, getFormData } from '../../utils/requestUtils';
export const action = async ({ request, params }: ActionFunctionArgs) => {
const actionName = 'action update';
const formData = await request.formData();
const name = getRequestParam(params.name, 'name');
const adapterName = getRequestParam(params.name, 'name');
const shortDescription = getFormData(
formData.get('shortDescription'),
'shortDescription',
Expand All @@ -21,48 +21,35 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {

let response = null;

// switch (actionType) {
// case 'UPDATE_CLIENT_IN_ASSET':
// let clientUpdateType = getFormData(
// formData.get('updateType'),
// 'updateType',
// actionName
// );
// const clientName = getFormData(formData.get('clientName'), 'clientName', actionName);
// response = await AssetApi.updateClientInAsset(
// clientName,
// id,
// orgName,
// clientUpdateType
// );
// return json({ ok: response.status === 204 ? true : false });
// case 'UPDATE_ADAPTER_IN_ASSET':
// let adapterUpdateType = getFormData(
// formData.get('updateType'),
// 'updateType',
// actionName
// );
// const adapterName = getFormData(formData.get('adapterName'), 'adapterName', actionName);
// response = await AssetApi.updateAdapterInAsset(
// adapterName,
// id,
// orgName,
// adapterUpdateType
// );
// return json({ ok: response.status === 204 ? true : false });
// default:
// response = await AdapterAPI.updateAdapter(
// {
// name: name,
// shortDescription: shortDescription as string,
// note: note as string,
// },
// orgName
// );

// console.log("response.status")
// console.log(response.status)
// return json({ ok: response.status === 200 ? true : false });

return redirect(`/adapter/${name}`);
switch (actionType) {
case 'UPDATE_COMPONENT_IN_ADAPTER':
let clientUpdateType = getFormData(
formData.get('updateType'),
'updateType',
actionName
);
const componentName = getFormData(
formData.get('componentName'),
'componentName',
actionName
);
response = await AdapterAPI.updateComponentInAdapter(
componentName,
adapterName,
orgName,
clientUpdateType
);
return json({ ok: response.status === 204 ? true : false });
default:
response = await AdapterAPI.updateAdapter(
{
name: adapterName,
shortDescription: shortDescription as string,
note: note as string,
},
orgName
);
return redirect(`/adapter/${adapterName}`);
}
// return json({ ok: response.status === 200 ? true : false });
};
2 changes: 1 addition & 1 deletion app/routes/adapter.$name/ComponentSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ComponentSelector: React.FC<ComponentSelectorProps> = ({ items, selectedIt
toggleSwitch={(name, isChecked) => {
submit(
{
clientName: name,
componentName: name,
updateType: isChecked ? 'add' : 'remove',
actionType: 'UPDATE_COMPONENT_IN_ADAPTER',
},
Expand Down

0 comments on commit 56016c2

Please sign in to comment.