PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / ManageMenu / ManageMenu.tsx

ManageMenu.tsx in Code Snippets 4.0.0-beta.1, at js/components/ManageMenu/ManageMenu.tsx

42 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useEffect, useMemo } from 'react'
2 import { fetchQueryParam } from '../../utils/urls'
3 import { Toolbar } from '../common/Toolbar'
4 import { CommunityCloud } from './CommunityCloud/CommunityCloud'
5 import { SnippetsTable } from './SnippetsTable'
6
7 const repositionTableOptionsSettings = () => {
8 const screenOptionsForm = document.getElementById('adv-settings')
9 const tableOptions = screenOptionsForm?.querySelector<HTMLFieldSetElement>('fieldset.table-options-prefs')
10 // Locate the first column-visibility fieldset that is NOT the table-options one.
11 // This relies on WordPress core rendering #adv-settings with .metabox-prefs fieldsets.
12 // Verified against WP 6.5+ (core/Screen_Options). If WP changes this structure the
13 // reordering will silently no-op, which is acceptable — it is a cosmetic improvement only.
14 const columns = Array.from(
15 screenOptionsForm?.querySelectorAll<HTMLFieldSetElement>('fieldset.metabox-prefs') ?? []
16 ).find(fieldset => !fieldset.classList.contains('table-options-prefs'))
17
18 if (screenOptionsForm && tableOptions && columns) {
19 screenOptionsForm.insertBefore(tableOptions, columns)
20 }
21 }
22
23 export const ManageMenu = () => {
24 const subpage = useMemo(() => fetchQueryParam('subpage'), [])
25
26 useEffect(() => {
27 if ('cloud-community' !== subpage) {
28 repositionTableOptionsSettings()
29 }
30 }, [subpage])
31
32 return (
33 <>
34 <Toolbar />
35
36 {'cloud-community' === subpage
37 ? <CommunityCloud />
38 : <SnippetsTable />}
39 </>
40 )
41 }
42