Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental - filtering items based on query string filter #193

Merged
merged 6 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"!examples/*",
"packages/*"
],
"version": "7.2.0"
"version": "7.3.0-alpha.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ exports[`<ImageElement /> renders the correct image 1`] = `
Object {
"sizes": "(min-width: 500px) 500px, 100vw",
"src": "https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&fit=crop",
"srcSet": "https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=320&h=320&auto=format&fit=crop 320w,https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&fit=crop 500w",
"srcSet": "https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=125&h=125&auto=format&fit=crop 125w,https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=250&h=250&auto=format&fit=crop 250w,https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&fit=crop 500w",
}
`;

exports[`<ImageElement /> renders the correct image with correct options 1`] = `
Object {
"sizes": "(min-width: 500px) 500px, 100vw",
"src": "https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&q=77&lossless=false&fit=clip",
"srcSet": "https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=320&h=320&auto=format&q=77&lossless=false&fit=clip 320w,https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&q=77&lossless=false&fit=clip 500w",
"srcSet": "https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=125&h=125&auto=format&q=77&lossless=false&fit=clip 125w,https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=250&h=250&auto=format&q=77&lossless=false&fit=clip 250w,https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&q=77&lossless=false&fit=clip 500w",
}
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/camelcase */
import React from "react";
import { getGatsbyImageData } from "../src/image-element/get-gatsby-image-data";
import React from 'react';
import { getGatsbyImageData } from '../src/image-element/get-gatsby-image-data';
import TestRenderer from 'react-test-renderer';
import { ImageElement } from '../src';

Expand All @@ -25,9 +25,10 @@ describe('<ImageElement />', () => {
it('generates the srcset', () => {
const data = getGatsbyImageData({ image: images[0] });
expect(data.images.fallback.srcSet).toMatchInlineSnapshot(`
"https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=320&h=320&auto=format&fit=crop 320w,
https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&fit=crop 500w"
`);
"https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=125&h=125&auto=format&fit=crop 125w,
https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=250&h=250&auto=format&fit=crop 250w,
https://assets-us-01.kc-usercontent.com:443/0fe3ab32-97a8-005d-6928-eda983ea70a5/44299668-b37b-4224-a115-1fd66f7d7b36/Yprofile.jpg?w=500&h=500&auto=format&fit=crop 500w"
`);
});

it('generates the correct dimensions', () => {
Expand Down Expand Up @@ -57,10 +58,11 @@ describe('<ImageElement />', () => {
fit: 'clip',
quality: 77,
lossless: false,
}} />,
}}
/>,
);
expect(
testRenderer.root.findByProps({ 'data-main-image': '' }).props.fallback,
).toMatchSnapshot();
});
});
});
2 changes: 2 additions & 0 deletions packages/gatsby-source-kontent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ This plugin does not need to use `yarn`, if want to use it in you project, see [
- `includeRawContent` - \<`boolean`\> allows to include `internal.content` property as a part fo the GraphQL model. Turned off by default.
- `experimental`:
- `managementApiTriggersUpdate` - \<`boolean`\> allows to handle [workflow step change Management API webhook trigger](https://docs.kontent.ai/reference/webhooks-reference#a-management-api-triggers). Turned off by default.
- `additionalItemFilterParams` - \<`string`\> Additional item [filter parameters](https://docs.kontent.ai/reference/delivery-api#tag/Filtering-content) to reduce the content in GraphQL model. Example `system.collection=marketing&system.workflow_step[neq]=archived` Empty by default.

\* required property

### Logging
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-kontent/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kentico/gatsby-source-kontent",
"description": "Source plugin providing Kontent data from REST Delivery API",
"version": "7.2.0",
"version": "7.3.0-alpha.0",
"main": "index.js",
"license": "MIT",
"author": {
Expand Down
11 changes: 5 additions & 6 deletions packages/gatsby-source-kontent/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const loadAllKontentItems = async (

const response = await axios.get(
`${getProtocolAndDomain(config)}/${
config.projectId
}/items-feed?language=${language}`,
config.projectId
}/items-feed?language=${language}${config?.experimental?.additionalItemFilterParams ? '&' + config.experimental.additionalItemFilterParams : ''}`,
{
headers,
raxConfig: {
Expand Down Expand Up @@ -136,16 +136,15 @@ const loadKontentItem = async (
modularKontent: { [key: string]: KontentItemInput };
}> => {

let headers = ensureAuthorizationHeader(config);
let headers = ensureAuthorizationHeader(config);
headers = ensureTrackingHeader(headers);
if (waitForLoadingNewContent) {
headers = ensureNewContentHeader(headers)
}

const response = await axios.get(
`${getProtocolAndDomain(config)}/${
config.projectId
}/items?system.id=${itemId}&language=${language}`,
`${getProtocolAndDomain(config)}/${config.projectId
}/items?system.id=${itemId}&language=${language}${config?.experimental?.additionalItemFilterParams ? '&' + config.experimental.additionalItemFilterParams : ''}`,
{
headers,
raxConfig: {
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-source-kontent/src/pluginOptionsSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const pluginOptionsSchema = ({ Joi }: { Joi: any }): any => {
managementApiTriggersUpdate: Joi.boolean()
.description("Turn on experimental handling of management API triggers for update.")
.default(false),
additionalItemFilterParams : Joi.string()
.description("Additional item filter parameters to reduce the content in GraphQL model.")
.default("")
})
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-source-kontent/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface CustomPluginOptions extends PluginOptions {
includeRawContent: boolean = false;
experimental: {
managementApiTriggersUpdate: boolean = false;
additionalItemFilterParams: string = "";
};
}

Expand Down
Loading