updated commit

This commit is contained in:
Irtiza-h30
2020-07-16 18:35:12 -04:00
parent 31a61fe804
commit 4fde4c4db9
3 changed files with 111 additions and 6 deletions

View File

@@ -1,11 +1,64 @@
import React from 'react'; import React from 'react';
import { useQuery } from '@apollo/react-hooks'; import { useQuery, useMutation } from '@apollo/react-hooks';
import { Alert } from 'antd'; import { Alert, notification } from 'antd';
import { GET_ALL_FIRMWARE } from 'graphql/queries'; import { GET_ALL_FIRMWARE, GET_TRACK_ASSIGNMENTS } from 'graphql/queries';
import { DELETE_TRACK_ASSIGNMENT, DELETE_FIRMWARE } from 'graphql/mutations';
import { Firmware as FirmwarePage, Loading } from '@tip-wlan/wlan-cloud-ui-library'; import { Firmware as FirmwarePage, Loading } from '@tip-wlan/wlan-cloud-ui-library';
const Firmware = () => { const Firmware = () => {
const { data, error, loading } = useQuery(GET_ALL_FIRMWARE); const { data, error, loading, refetch } = useQuery(GET_ALL_FIRMWARE);
const {
data: trackAssignmentData,
error: trackAssignmentError,
loading: trackAssignmentLoading,
refetch: refetchAssignmentData,
} = useQuery(GET_TRACK_ASSIGNMENTS);
const [deleteTrackAssignment] = useMutation(DELETE_TRACK_ASSIGNMENT);
const [deleteFirmware] = useMutation(DELETE_FIRMWARE);
const handleDeleteTrackAssignment = (firmwareTrackId, firmwareVersionId) => {
deleteTrackAssignment({
variables: {
firmwareTrackId,
firmwareVersionId,
},
})
.then(() => {
refetchAssignmentData();
notification.success({
message: 'Success',
description: 'Track Assignment successfully deleted.',
});
})
.catch(() =>
notification.error({
message: 'Error',
description: 'Track Assignment could not be deleted.',
})
);
};
const handleDeleteFirmware = id => {
deleteFirmware({
variables: {
id,
},
})
.then(() => {
refetch();
notification.success({
message: 'Success',
description: 'Firmware successfully deleted.',
});
})
.catch(() =>
notification.error({
message: 'Error',
description: 'Firmware could not be deleted.',
})
);
};
if (error) { if (error) {
return ( return (
@@ -13,11 +66,29 @@ const Firmware = () => {
); );
} }
if (loading) { if (trackAssignmentError) {
return (
<Alert
message="Error"
description="Failed to load Firmware Track Assignment data."
type="error"
showIcon
/>
);
}
if (loading || trackAssignmentLoading) {
return <Loading />; return <Loading />;
} }
return <FirmwarePage firmwareData={data && data.getAllFirmware} />; return (
<FirmwarePage
firmwareData={data && data.getAllFirmware}
trackAssignmentData={trackAssignmentData && trackAssignmentData.getAllFirmwareTrackAssignment}
onDeleteTrackAssignment={handleDeleteTrackAssignment}
onDeleteFirmware={handleDeleteFirmware}
/>
);
}; };
export default Firmware; export default Firmware;

View File

@@ -99,3 +99,26 @@ export const UPDATE_EQUIPMENT_FIRMWARE = gql`
} }
} }
`; `;
export const DELETE_TRACK_ASSIGNMENT = gql`
mutation UpdateEquipmentFirmware($firmwareTrackId: ID!, $firmwareVersionId: ID!) {
deleteFirmwareTrackAssignment(
firmwareTrackId: $firmwareTrackId
firmwareVersionId: $firmwareVersionId
) {
trackRecordId
firmwareVersionRecordId
modelId
createdTimestamp
lastModifiedTimestamp
}
}
`;
export const DELETE_FIRMWARE = gql`
mutation DeleteFirmware($id: ID!) {
deleteFirmware(id: $id) {
id
}
}
`;

View File

@@ -237,3 +237,14 @@ export const GET_ALL_FIRMWARE = gql`
} }
} }
`; `;
export const GET_TRACK_ASSIGNMENTS = gql`
query GetAllFirmwareTrackAssignment {
getAllFirmwareTrackAssignment {
modelId
firmwareVersionRecordId
trackRecordId
lastModifiedTimestamp
}
}
`;