Skip to content

Commit

Permalink
fix: Resolve design issues (#439)
Browse files Browse the repository at this point in the history
* Fix: Global search and pagination in modify page (#423)

* feat: change theme to dark mode

* fix: dashboard table dark mode

* feat-dark mode

* feat:dark mode

* fix: lead page in dark mode

* fix

* text to white in deallocate page

* fix

* fix issue: removed filter options, fix to logout shimmering

* feat: added refresh button to approve assets page

* fix

* fix: modify table

* removed comments

---------

Co-authored-by: AidrinVargheseEXP <[email protected]>
Co-authored-by: Ashish Sam T George <[email protected]>

* fix: Increase timeout of gunicorn to 120 seconds (#427)

* fix: Make the background color of all the pages uniform (#436)

* fix: Reset field values when an asset is succefully created (#438)

* fix : Design improvments at frontend, bug fix (#437)

* fix : Design improvments at frontend, bug fix

* fix: remov extra loading icon

* fix : resolve more error handling to user tasks

---------

Co-authored-by: Aidrin Varghese <[email protected]>
Co-authored-by: AidrinVargheseEXP <[email protected]>
Co-authored-by: AnanthanCJ <[email protected]>
  • Loading branch information
4 people authored Jul 25, 2024
1 parent 2099fb9 commit 550685d
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,19 @@ def generate_missing_fields_csv(missing_fields_assets):
csv_writer.writerow(asset.values())

return output

@staticmethod
def generate_missing_fields_xlsx(missing_fields_assets):
if missing_fields_assets:
df = pd.DataFrame(missing_fields_assets)
output = io.BytesIO()
df.to_excel(output, index=False)
output.seek(0)
# return output.getvalue()
return output
else:
# return None
return io.BytesIO()

@staticmethod
def generate_zip_file_csv(csv_file_one, csv_file_two):
Expand All @@ -263,35 +276,12 @@ def generate_zip_file_csv(csv_file_one, csv_file_two):
zip_content.seek(0)
return zip_content

class AssetImportView(APIView):
def post(self, request, *args, **kwargs):
file_obj = request.FILES.get('file')
file_type = request.GET.get('file_type')

if not file_obj:
return Response({'error': 'No file uploaded'}, status=status.HTTP_400_BAD_REQUEST)

try:
file_content = file_obj.read()
result = AssetImportService.parse_and_add_assets(file_content, request.user, file_type)

# Generate CSV files
skipped_fields_csv = AssetImportService.generate_missing_fields_csv(result['skipped_fields_assets'])
missing_fields_csv = AssetImportService.generate_missing_fields_csv(result['missing_fields_assets'])

# Generate zip file
zip_content = AssetImportService.generate_zip_file_csv(skipped_fields_csv, missing_fields_csv)

# Encode zip content to base64
zip_base64 = base64.b64encode(zip_content.getvalue()).decode('utf-8')

response_data = {
'message': result['message'],
'added_assets_count': result['added_assets_count'],
'skipped_assets_count': result['skipped_assets_count'],
'zip_file': zip_base64
}

return Response(response_data, status=status.HTTP_200_OK)
except Exception as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
@staticmethod
def generate_zip_file_xlsx(xlsx_file_one, xlsx_file_two):
zip_content = io.BytesIO()
with zipfile.ZipFile(zip_content, "w") as zf:
zf.writestr("skipped_fields.xlsx", xlsx_file_one.getvalue())
zf.writestr("missing_fields.xlsx", xlsx_file_two.getvalue())

zip_content.seek(0)
return zip_content
9 changes: 5 additions & 4 deletions exam_frontend/src/components/AddAsset/AddAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,16 @@ const AddAsset: React.FC = ({
import.meta.env["VITE_ADD_ASSET_URL"],
formData
);
message.success("Asset creation done successfully");
message.success(submitResponse.data?.message);
handleResetForm();
return;
} else {
message.error("Please fill in all mandatory fields.");
}
} catch (error) {
console.error("Error fetching asset type or asset creation :", error);
message.error(
"Failed to fetch asset type or submit form data. Please try again later."
error.data?.message
);
return;
} finally {
Expand All @@ -439,11 +440,11 @@ const AddAsset: React.FC = ({
import.meta.env["VITE_ADD_ASSET_URL"],
formData
);
message.success("Asset created successfully");
message.success(response.data?.message);
return;
} catch (error) {
console.error("Error in asset creation :", error);
message.error("Failed to create an asset. Please try again later.");
message.error(error.data?.message);
return;
} finally {
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ export const AssignmentHandler: React.FC<AssignmentHandlerProps> = ({
(requestData: any) =>
axiosInstance.post("/asset/assign_asset", requestData),
{
onSuccess: () => {
message.success("Successfully Assigned");
onSuccess: (response) => {
message.success(response.data?.message);
setLoading(false);
assetDataRefetch();
closeAssignDrawer();
},
onError: (error) => {
message.error("Unsuccessful, the asset may be already assigned");
message.error(error.data?.message);
setLoading(false);
closeAssignDrawer();
},
Expand Down
4 changes: 2 additions & 2 deletions exam_frontend/src/components/CardComponent/CardComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ const CardComponent: React.FC<CardType> = ({
"Content-Type": "application/json",
},
});
message.success("Asset Details Successfully Updated");
message.success(response.data?.message);
} catch (error) {
console.error("Error updating data:", error);
message.error("Error Updating Asset Details. Please try again.");
message.error(er);
}
setIsLoading(false); // Set loading to false when update completes
assetDataRefetch();
Expand Down
56 changes: 29 additions & 27 deletions exam_frontend/src/components/DropDown/DropDown.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
import React, { useState } from 'react';
import { DownOutlined } from '@ant-design/icons';
import { Dropdown, Button, Menu } from 'antd';
import { Dropdown, Button, MenuProps } from 'antd';

interface DropDownProps {
onSelect: (key: string) => void;
items?: { label: string; key: string; icon?: React.ReactNode }[];
buttonLabel?: string;
buttonLabel?: React.ReactNode;
disabled?: boolean;
}

const DropDown: React.FC<DropDownProps> = ({ onSelect, items = [], buttonLabel = "Submit" }) => {
const [loadings, setLoadings] = useState<boolean[]>([]);

const enterLoading = (index: number) => {
setLoadings((state) => {
const newLoadings = [...state];
newLoadings[index] = true;
return newLoadings;
});
const DropDown: React.FC<DropDownProps> = ({
onSelect,
items = [],
buttonLabel = "Submit",
disabled = false
}) => {
const [loading, setLoading] = useState(false);

const handleMenuClick: MenuProps['onClick'] = (e) => {
setLoading(true);
onSelect(e.key);
setTimeout(() => {
setLoadings((state) => {
const newLoadings = [...state];
newLoadings[index] = false;
return newLoadings;
});
setLoading(false);
}, 6000);
};

const menuItems = items.map(item => ({
key: item.key,
label: (
<span onClick={() => onSelect(item.key)}>
{item.label}
</span>
),
label: item.label,
icon: item.icon,
}));

const menuProps = {
items: menuItems,
onClick: handleMenuClick,
};

return (
<Dropdown menu={{ items: menuItems }}>
<Dropdown menu={menuProps} disabled={disabled}>
<Button
icon={<DownOutlined />}
style={{
borderRadius: '7px',
border: '1px solid #d9d9d9',
background: '#1677ff',
color: 'white',
height: '41px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
loading={loadings[0]}
onClick={() => enterLoading(0)}

disabled={disabled}
>
{buttonLabel}
<span style={{ marginRight: '8px' }}>{buttonLabel}</span>
<DownOutlined />
</Button>
</Dropdown>
);
};

export default DropDown;
export default DropDown;
46 changes: 0 additions & 46 deletions exam_frontend/src/components/Export/Export.tsx

This file was deleted.

Loading

0 comments on commit 550685d

Please sign in to comment.