Skip to content

Commit

Permalink
Site Editor: Fix obsolete getLocationWithParams usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Dec 30, 2024
1 parent a28455c commit 4bb1d08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 10 additions & 7 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ import {
TEMPLATE_PART_POST_TYPE,
} from '../../utils/constants';

const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );
const { CreatePatternModal, useAddPatternCategory } = unlock(
editPatternsPrivateApis
);
const { CreateTemplatePartModal } = unlock( editorPrivateApis );

export default function AddNewPattern() {
const history = useHistory();
const location = useLocation();
const [ showPatternModal, setShowPatternModal ] = useState( false );
const [ showTemplatePartModal, setShowTemplatePartModal ] =
useState( false );
Expand Down Expand Up @@ -159,21 +160,23 @@ export default function AddNewPattern() {
return;
}
try {
const {
params: { postType, categoryId },
} = history.getLocationWithParams();
let currentCategoryId;
// When we're not handling template parts, we should
// add or create the proper pattern category.
if ( postType !== TEMPLATE_PART_POST_TYPE ) {
if (
location.query.postType !== TEMPLATE_PART_POST_TYPE
) {
/*
* categoryMap.values() returns an iterator.
* Iterator.prototype.find() is not yet widely supported.
* Convert to array to use the Array.prototype.find method.
*/
const currentCategory = Array.from(
categoryMap.values()
).find( ( term ) => term.name === categoryId );
).find(
( term ) =>
term.name === location.query.categoryId
);
if ( currentCategory ) {
currentCategoryId =
currentCategory.id ||
Expand All @@ -194,7 +197,7 @@ export default function AddNewPattern() {
// category.
if (
! currentCategoryId &&
categoryId !== 'my-patterns'
location.query.categoryId !== 'my-patterns'
) {
history.navigate(
`/pattern?categoryId=${ PATTERN_DEFAULT_CATEGORY }`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import DataViewItem from './dataview-item';
import AddNewItem from './add-new-view';
import { unlock } from '../../lock-unlock';

const { useHistory } = unlock( routerPrivateApis );
const { useHistory, useLocation } = unlock( routerPrivateApis );

const EMPTY_ARRAY = [];

Expand Down Expand Up @@ -85,6 +85,7 @@ function RenameItemModalContent( { dataviewId, currentTitle, setIsRenaming } ) {

function CustomDataViewItem( { dataviewId, isActive } ) {
const history = useHistory();
const location = useLocation();
const { dataview } = useSelect(
( select ) => {
const { getEditedEntityRecord } = select( coreStore );
Expand Down Expand Up @@ -145,10 +146,10 @@ function CustomDataViewItem( { dataviewId, isActive } ) {
}
);
if ( isActive ) {
const {
params: { postType },
} = history.getLocationWithParams();
history.replace( { postType } );
history.replace( {
postType:
location.query.postType,
} );
}
onClose();
} }
Expand Down

0 comments on commit 4bb1d08

Please sign in to comment.