File size: 1,593 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import page, { type Callback, type Context } from '@automattic/calypso-router';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import { setSelectedSiteId } from 'calypso/state/ui/actions';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import { A4A_PLUGINS_LINK } from '../../components/sidebar-menu/lib/constants';
import MainSidebar from '../../components/sidebar-menu/main';

// Reset selected site id for multi-site view since it is never reset
// and the plugins component behaves differently when there
// is a selected site which is incorrect for multi-site view
const resetSite = ( context: Context ) => {
	const state = context.store.getState();
	const siteId = getSelectedSiteId( state );
	if ( siteId ) {
		context.store.dispatch( setSelectedSiteId( null ) );
	}
};

export const pluginsContext: Callback = ( context ) => {
	const { slug } = context.params;
	const redirectPath = slug
		? `${ A4A_PLUGINS_LINK }/manage/sites/${ slug }`
		: `${ A4A_PLUGINS_LINK }/manage/sites`;

	page.redirect( redirectPath );
};

export const pluginManagementContext: Callback = ( context, next ) => {
	resetSite( context );
	context.secondary = <MainSidebar path={ context.path } />;
	context.primary = (
		<>
			<PageViewTracker title="Plugins" path={ context.path } />
		</>
	);
	next();
};

export const pluginDetailsContext: Callback = ( context, next ) => {
	resetSite( context );
	context.secondary = <MainSidebar path={ context.path } />;
	context.primary = (
		<>
			<PageViewTracker title="Plugins" path={ context.path } />
		</>
	);
	next();
};