Skip to content

Commit

Permalink
[Chore] Removed deprecated props, updated samples to use clientFactory (
Browse files Browse the repository at this point in the history
#1784)

* [Chore] Removed deprecated props, updated samples to use clientFactory (#1783)

* Updated Angular sample and exposed GraphQLRequestClient

* Upgraded React app, removed deprecated defaultProps property

* Updated node-headless-ssr-experience-edge and vue samples

* Updated comments

* Updated CHANGELOG

* Updated CHANGELOG
  • Loading branch information
illiakovalenko authored Apr 26, 2024
1 parent ab836ca commit a41c8bb
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 64 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ Our versioning strategy is as follows:
- Minor: may include breaking changes in framework packages (e.g. framework upgrades, new features, improvements)
- Major: may include breaking changes in core packages (e.g. major architectural changes, major features)

## Unreleased


## 22.0.0

### 🛠 Breaking Changes
Expand All @@ -30,6 +27,10 @@ Our versioning strategy is as follows:

* `[sitecore-jss-react]` Deprecated `media` prop is removed from Image component. Use `field` prop instead ([#1780](https://github.com/Sitecore/jss/pull/1780)).

* `[templates/react]` `[templates/angular]` `[templates/vue]` `[templates/node-headless-ssr-experience-edge]` `[sitecore-jss-react]` `[sitecore-jss-nextjs]` ([#1783](https://github.com/Sitecore/jss/pull/1783)):
* GraphQL-based services can now only be initialized with clientFactory parameter. Previously deprecated option of providing endpoint and apiKey has been removed
* Removed deprecated _defaultProps_ react component property

* `[templates/nextjs]` GraphQL-based services can now only be initialized with clientFactory parameter. Previously deprecated option of providing endpoint and apiKey has been removed ([#1780](https://github.com/Sitecore/jss/pull/1780)).

* `[templates/nextjs]` `[templates/react]` `[templates/vue]` `[templates/angular]` Deprecated JSS_APP_NAME environment variable has been removed ([#1780](https://github.com/Sitecore/jss/pull/1780)).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
GraphQLRequestClientFactoryConfig,
GraphQLRequestClient,
} from '@sitecore-jss/sitecore-jss-angular';
import { environment as env } from '../../environments/environment';

// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application

/**
* Creates a new GraphQLRequestClientFactory instance
* @returns GraphQLRequestClientFactory instance
*/
export const createGraphQLClientFactory = () => {
let clientConfig: GraphQLRequestClientFactoryConfig;

if (env.graphQLEndpoint && env.sitecoreApiKey) {
clientConfig = {
endpoint: env.graphQLEndpoint,
apiKey: env.sitecoreApiKey,
};
} else {
throw new Error('Please configure your graphQLEndpoint and sitecoreApiKey.');
}

return GraphQLRequestClient.createClientFactory(clientConfig);
};

export const clientFactory = createGraphQLClientFactory();
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
constants,
} from '@sitecore-jss/sitecore-jss-angular';
import { environment as env } from '../../environments/environment';
import { clientFactory } from './client-factory';

export class DictionaryServiceFactory {
create(): DictionaryService {
return process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL
? new GraphQLDictionaryService({
endpoint: env.graphQLEndpoint,
apiKey: env.sitecoreApiKey,
clientFactory,
siteName: env.sitecoreSiteName,
/*
The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
constants,
} from '@sitecore-jss/sitecore-jss-angular';
import { environment } from '../../environments/environment';
import { clientFactory } from './client-factory';

export class LayoutServiceFactory {
create(): LayoutService {
return process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL
? new GraphQLLayoutService({
endpoint: environment.graphQLEndpoint,
apiKey: environment.sitecoreApiKey,
clientFactory,
siteName: environment.sitecoreSiteName,
})
: new RestLayoutService({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
GraphQLRequestClientFactoryConfig,
GraphQLRequestClient,
} from '@sitecore-jss/sitecore-jss';
import { config } from './config';

// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application

/**
* Creates a new GraphQLRequestClientFactory instance
* @returns GraphQLRequestClientFactory instance
*/
export const createGraphQLClientFactory = () => {
let clientConfig: GraphQLRequestClientFactoryConfig;

if (config.endpoint && config.apiKey) {
clientConfig = {
endpoint: config.endpoint,
apiKey: config.apiKey,
};
} else {
throw new Error('Please configure your endpoint and apiKey.');
}

return GraphQLRequestClient.createClientFactory(clientConfig);
};

export const clientFactory = createGraphQLClientFactory();
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ import 'dotenv/config';
import { GraphQLLayoutService } from '@sitecore-jss/sitecore-jss/layout';
import { GraphQLDictionaryService } from '@sitecore-jss/sitecore-jss/i18n';
import { config } from './config';
import { clientFactory } from './client-factory';

const server = express();

const layoutService = new GraphQLLayoutService({
endpoint: config.endpoint,
apiKey: config.apiKey,
clientFactory,
siteName: config.siteName,
});

const dictionaryService = new GraphQLDictionaryService({
endpoint: config.endpoint,
apiKey: config.apiKey,
clientFactory,
siteName: config.siteName,
/*
The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss-react';
import config from '../temp/config';

// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application

/**
* Creates a new GraphQLRequestClientFactory instance
* @returns GraphQLRequestClientFactory instance
*/
export const createGraphQLClientFactory = () => {
let clientConfig;

if (config.graphQLEndpoint && config.sitecoreApiKey) {
clientConfig = {
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
};
} else {
throw new Error('Please configure your graphQLEndpoint and sitecoreApiKey.');
}

return GraphQLRequestClient.createClientFactory(clientConfig);
};

export const clientFactory = createGraphQLClientFactory();
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
constants,
} from '@sitecore-jss/sitecore-jss-react';
import config from '../temp/config';
import { clientFactory } from './client-factory';

export class DictionaryServiceFactory {
create() {
return process.env.REACT_APP_FETCH_WITH === constants.FETCH_WITH.GRAPHQL
? new GraphQLDictionaryService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
clientFactory,
siteName: config.sitecoreSiteName,
/*
The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
constants,
} from '@sitecore-jss/sitecore-jss-react';
import config from '../temp/config';
import { clientFactory } from './client-factory';

export class LayoutServiceFactory {
create() {
return process.env.REACT_APP_FETCH_WITH === constants.FETCH_WITH.GRAPHQL
? new GraphQLLayoutService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
clientFactory,
siteName: config.sitecoreSiteName,
})
: new RestLayoutService({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss-vue';
import config from '../temp/config';

// The GraphQLRequestClientFactory serves as the central hub for executing GraphQL requests within the application

/**
* Creates a new GraphQLRequestClientFactory instance
* @returns GraphQLRequestClientFactory instance
*/
export const createGraphQLClientFactory = () => {
let clientConfig;

if (config.graphQLEndpoint && config.sitecoreApiKey) {
clientConfig = {
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
};
} else {
throw new Error('Please configure your graphQLEndpoint and sitecoreApiKey.');
}

return GraphQLRequestClient.createClientFactory(clientConfig);
};

export const clientFactory = createGraphQLClientFactory();
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
constants,
} from '@sitecore-jss/sitecore-jss-vue';
import config from '../temp/config';
import { clientFactory } from './client-factory';

export class DictionaryServiceFactory {
create() {
return process.env.VUE_APP_FETCH_WITH === constants.FETCH_WITH.GRAPHQL
? new GraphQLDictionaryService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
clientFactory,
siteName: config.sitecoreSiteName,
/*
The Dictionary Service needs a root item ID in order to fetch dictionary phrases for the current
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GraphQLLayoutService, RestLayoutService, constants } from '@sitecore-jss/sitecore-jss-vue';
import config from '../temp/config';
import { clientFactory } from './client-factory';

export class LayoutServiceFactory {
create() {
return process.env.VUE_APP_FETCH_WITH === constants.FETCH_WITH.GRAPHQL
? new GraphQLLayoutService({
endpoint: config.graphQLEndpoint,
apiKey: config.sitecoreApiKey,
clientFactory,
siteName: config.sitecoreSiteName,
})
: new RestLayoutService({
Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss-angular/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export {
RetryStrategy,
DefaultRetryStrategy,
GraphQLClientError,
GraphQLRequestClientFactoryConfig,
GraphQLRequestClient,
} from '@sitecore-jss/sitecore-jss/graphql';
export {
constants,
Expand Down
6 changes: 1 addition & 5 deletions packages/sitecore-jss-nextjs/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
(props: LinkProps, ref): JSX.Element | null => {
const {
field,
editable,
editable = true,
children,
internalLinkMatcher = /^\//g,
showLinkTextWithChildrenPresent,
Expand Down Expand Up @@ -72,10 +72,6 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
}
);

Link.defaultProps = {
editable: true,
};

Link.displayName = 'NextLink';

Link.propTypes = {
Expand Down
6 changes: 1 addition & 5 deletions packages/sitecore-jss-nextjs/src/components/NextImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Image, { ImageProps as NextImageProperties } from 'next/image';
type NextImageProps = ImageProps & Partial<NextImageProperties>;

export const NextImage: React.FC<NextImageProps> = ({
editable,
editable = true,
imageParams,
field,
mediaUrlPrefix,
Expand Down Expand Up @@ -105,8 +105,4 @@ NextImage.propTypes = {
),
};

NextImage.defaultProps = {
editable: true,
};

NextImage.displayName = 'NextImage';
14 changes: 7 additions & 7 deletions packages/sitecore-jss-nextjs/src/components/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ export type RichTextProps = ReactRichTextProps & {
const prefetched: { [cacheKey: string]: boolean } = {};

export const RichText = (props: RichTextProps): JSX.Element => {
const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, ...rest } = props;
const {
internalLinksSelector = 'a[href^="/"]',
prefetchLinks = true,
editable = true,
...rest
} = props;
const hasText = props.field && props.field.value;
const isEditing = props.editable && props.field && props.field.editable;
const isEditing = editable && props.field && props.field.editable;

const router = useRouter();
const richTextRef = useRef<HTMLElement>(null);
Expand Down Expand Up @@ -77,9 +82,4 @@ RichText.propTypes = {
...RichTextPropTypes,
};

RichText.defaultProps = {
tag: 'div',
editable: true,
};

RichText.displayName = 'NextRichText';
6 changes: 1 addition & 5 deletions packages/sitecore-jss-react/src/components/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DateFieldProps {
export const DateField: React.FC<DateFieldProps> = ({
field,
tag,
editable,
editable = true,
render,
...otherProps
}) => {
Expand Down Expand Up @@ -68,8 +68,4 @@ DateField.propTypes = {
render: PropTypes.func,
};

DateField.defaultProps = {
editable: true,
};

DateField.displayName = 'Date';
6 changes: 1 addition & 5 deletions packages/sitecore-jss-react/src/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const getEEMarkup = (
};

export const Image: React.FC<ImageProps> = ({
editable,
editable = true,
imageParams,
field,
mediaUrlPrefix,
Expand Down Expand Up @@ -206,8 +206,4 @@ Image.propTypes = {
),
};

Image.defaultProps = {
editable: true,
};

Image.displayName = 'Image';
6 changes: 1 addition & 5 deletions packages/sitecore-jss-react/src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type LinkProps = React.DetailedHTMLProps<
};

export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
({ field, editable, showLinkTextWithChildrenPresent, ...otherProps }, ref) => {
({ field, editable = true, showLinkTextWithChildrenPresent, ...otherProps }, ref) => {
const children = otherProps.children as React.ReactNode;
const dynamicField: LinkField | LinkFieldValue = field;

Expand Down Expand Up @@ -143,8 +143,4 @@ export const LinkPropTypes = {

Link.propTypes = LinkPropTypes;

Link.defaultProps = {
editable: true,
};

Link.displayName = 'Link';
7 changes: 1 addition & 6 deletions packages/sitecore-jss-react/src/components/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface RichTextProps {
}

export const RichText: React.FC<RichTextProps> = forwardRef(
({ field, tag, editable, ...otherProps }, ref) => {
({ field, tag = 'div', editable = true, ...otherProps }, ref) => {
if (!field || (!field.editable && !field.value)) {
return null;
}
Expand Down Expand Up @@ -52,9 +52,4 @@ export const RichTextPropTypes = {

RichText.propTypes = RichTextPropTypes;

RichText.defaultProps = {
tag: 'div',
editable: true,
};

RichText.displayName = 'RichText';
Loading

0 comments on commit a41c8bb

Please sign in to comment.