Skip to content

Commit

Permalink
feat: remove link by rowId wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 15, 2020
1 parent e39faee commit a381e7d
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 65 deletions.
46 changes: 26 additions & 20 deletions app/containers/Products/ProductRowItemContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
faShareAlt
} from '@fortawesome/free-solid-svg-icons';
import createLinkedProductMutation from 'mutations/linked_product/createLinkedProductMutation';
import updateLinkedProductMutation from 'mutations/linked_product/updateLinkedProductMutation';
// Import updateLinkedProductMutation from 'mutations/linked_product/updateLinkedProductMutation';
import InnerModal from './InnerProductBenchmarkModal';
import LinkedProductModal from './LinkedProductModal';

Expand Down Expand Up @@ -165,33 +165,37 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({

// TODO: GET ID OF PRODUCT LINK (add to db function?)
const removeLinkedProduct = async (removeLink: number) => {
const variables = {
input: {
linkedProduct: {
productId: product.rowId,
linkedProductId: removeLink,
isDeleted: true
}
}
};
console.log(removeLink);
// Const variables = {
// input: {
// id: removeLink.id
// linkedProduct: {
// productId: product.rowId,
// linkedProductId: removeLink,
// isDeleted: true
// }
// }
// };

const response = await updateLinkedProductMutation(
relay.environment,
variables
);
handleUpdateProductCount((productCount += 1));
console.log(response);
// const response = await updateLinkedProductMutation(
// relay.environment,
// variables
// );
// handleUpdateProductCount((productCount += 1));
// console.log(response);
};

const linkData = [];

product?.linkedProduct?.edges?.forEach((edge) => {
const dataObject = {productRowId: null};
dataObject.productRowId = edge.node.rowId;
const dataObject = {productRowId: null, linkId: null};
dataObject.productRowId = edge.node.linkedProductId;
dataObject.linkId = edge.node.rowId;
linkData.push(dataObject);
});

const saveLinkedProducts = async (newData: IChangeEvent) => {
console.log(newData);
const previousLinks = [];
const newLinks = [];

Expand All @@ -209,10 +213,10 @@ export const ProductRowItemComponent: React.FunctionComponent<Props> = ({
console.log(response);
}
});
previousLinks.forEach(async (id) => {
previousLinks.forEach(async (id, index) => {
if (!newLinks.includes(id)) {
console.log('REMOVE:', id);
const response = await removeLinkedProduct(id);
const response = await removeLinkedProduct(newData[index]);
console.log(response);
}
});
Expand Down Expand Up @@ -414,6 +418,8 @@ export default createFragmentContainer(ProductRowItemComponent, {
edges {
node {
rowId
rowId
linkedProductId
}
}
}
Expand Down
37 changes: 36 additions & 1 deletion app/server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8535,6 +8535,41 @@ input LinkedProductPatch {
updatedBy: Int
}

type LinkedProductReturn {
linkedProductId: Int
productName: String
productState: CiipProductState
rowId: Int
}

"""A connection to a list of `LinkedProductReturn` values."""
type LinkedProductReturnsConnection {
"""
A list of edges which contains the `LinkedProductReturn` and cursor to aid in pagination.
"""
edges: [LinkedProductReturnsEdge!]!

"""A list of `LinkedProductReturn` objects."""
nodes: [LinkedProductReturn]!

"""Information to aid in pagination."""
pageInfo: PageInfo!

"""
The count of *all* `LinkedProductReturn` you could get from the connection.
"""
totalCount: Int!
}

"""A `LinkedProductReturn` edge in the connection."""
type LinkedProductReturnsEdge {
"""A cursor for use in pagination."""
cursor: Cursor

"""The `LinkedProductReturn` at the end of the edge."""
node: LinkedProductReturn
}

"""A connection to a list of `LinkedProduct` values."""
type LinkedProductsConnection {
"""
Expand Down Expand Up @@ -10010,7 +10045,7 @@ type Product implements Node {
based pagination. May not be used with `last`.
"""
offset: Int
): ProductsConnection!
): LinkedProductReturnsConnection!

"""Reads and enables pagination through a set of `LinkedProduct`."""
linkedProductsByLinkedProductId(
Expand Down
Loading

0 comments on commit a381e7d

Please sign in to comment.