fix tool disabling for docs and others (#5722)

# Description of Changes

<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.
This commit is contained in:
Anthony Stirling
2026-02-13 23:15:06 +00:00
committed by GitHub
parent 27bd34c29b
commit 946196de43
13 changed files with 223 additions and 43 deletions

View File

@@ -7,8 +7,8 @@ import { FilesModalProvider } from "@app/contexts/FilesModalContext";
import { ToolWorkflowProvider } from "@app/contexts/ToolWorkflowContext";
import { HotkeyProvider } from "@app/contexts/HotkeyContext";
import { SidebarProvider } from "@app/contexts/SidebarContext";
import { PreferencesProvider } from "@app/contexts/PreferencesContext";
import { AppConfigProvider, AppConfigProviderProps, AppConfigRetryOptions } from "@app/contexts/AppConfigContext";
import { PreferencesProvider, usePreferences } from "@app/contexts/PreferencesContext";
import { AppConfigProvider, AppConfigProviderProps, AppConfigRetryOptions, useAppConfig } from "@app/contexts/AppConfigContext";
import { RightRailProvider } from "@app/contexts/RightRailContext";
import { ViewerProvider } from "@app/contexts/ViewerContext";
import { SignatureProvider } from "@app/contexts/SignatureContext";
@@ -70,6 +70,24 @@ export interface AppProvidersProps {
appConfigProviderProps?: Partial<AppConfigProviderOverrides>;
}
// Component to sync server defaults to preferences when AppConfig loads
function ServerDefaultsSync() {
const { config } = useAppConfig();
const { updateServerDefaults } = usePreferences();
useEffect(() => {
if (config) {
const serverDefaults = {
hideUnavailableTools: config.defaultHideUnavailableTools ?? false,
hideUnavailableConversions: config.defaultHideUnavailableConversions ?? false,
};
updateServerDefaults(serverDefaults);
}
}, [config, updateServerDefaults]);
return null;
}
/**
* Core application providers
* Contains all providers needed for the core
@@ -86,6 +104,7 @@ export function AppProviders({ children, appConfigRetryOptions, appConfigProvide
>
<ScarfTrackingInitializer />
<AppConfigLoader />
<ServerDefaultsSync />
<FileContextProvider enableUrlSync={true} enablePersistence={true}>
<AppInitializer />
<BrandingAssetManager />

View File

@@ -1,4 +1,4 @@
import React, { useState, useRef, forwardRef, useEffect } from "react";
import React, { useState, useRef, forwardRef, useEffect, useMemo } from "react";
import { Stack, Divider, Menu, Indicator } from "@mantine/core";
import { useTranslation } from 'react-i18next';
import { useNavigate, useLocation } from 'react-router-dom';
@@ -34,7 +34,7 @@ const QuickAccessBar = forwardRef<HTMLDivElement>((_, ref) => {
const location = useLocation();
const { isRainbowMode } = useRainbowThemeContext();
const { openFilesModal, isFilesModalOpen } = useFilesModalContext();
const { handleReaderToggle, handleToolSelect, selectedToolKey, leftPanelView, toolRegistry, readerMode, resetTool } = useToolWorkflow();
const { handleReaderToggle, handleToolSelect, selectedToolKey, leftPanelView, toolRegistry, readerMode, resetTool, toolAvailability } = useToolWorkflow();
const { hasUnsavedChanges } = useNavigationState();
const { actions: navigationActions } = useNavigationActions();
const { getToolNavigation } = useSidebarNavigation();
@@ -119,14 +119,14 @@ const QuickAccessBar = forwardRef<HTMLDivElement>((_, ref) => {
);
};
const mainButtons: ButtonConfig[] = [
const mainButtons: ButtonConfig[] = useMemo(() => [
{
id: 'read',
name: t("quickAccess.reader", "Reader"),
icon: <LocalIcon icon="menu-book-rounded" width="1.25rem" height="1.25rem" />,
size: 'md',
size: 'md' as const,
isRound: false,
type: 'navigation',
type: 'navigation' as const,
onClick: () => {
setActiveButton('read');
handleReaderToggle();
@@ -136,9 +136,9 @@ const QuickAccessBar = forwardRef<HTMLDivElement>((_, ref) => {
id: 'automate',
name: t("quickAccess.automate", "Automate"),
icon: <LocalIcon icon="automation-outline" width="1.25rem" height="1.25rem" />,
size: 'md',
size: 'md' as const,
isRound: false,
type: 'navigation',
type: 'navigation' as const,
onClick: () => {
setActiveButton('automate');
// If already on automate tool, reset it directly
@@ -149,7 +149,14 @@ const QuickAccessBar = forwardRef<HTMLDivElement>((_, ref) => {
}
}
},
];
].filter(button => {
// Filter out buttons for disabled tools
// 'read' is always available (viewer mode)
if (button.id === 'read') return true;
// Check if tool is actually available (not just present in registry)
const availability = toolAvailability[button.id as keyof typeof toolAvailability];
return availability?.available !== false;
}), [t, setActiveButton, handleReaderToggle, selectedToolKey, resetTool, handleToolSelect, toolAvailability]);
const middleButtons: ButtonConfig[] = [
{

View File

@@ -58,6 +58,8 @@ export interface AppConfig {
error?: string;
isNewServer?: boolean;
isNewUser?: boolean;
defaultHideUnavailableTools?: boolean;
defaultHideUnavailableConversions?: boolean;
}
export type AppConfigBootstrapMode = 'blocking' | 'non-blocking';

View File

@@ -8,13 +8,16 @@ interface PreferencesContextValue {
value: UserPreferences[K]
) => void;
resetPreferences: () => void;
updateServerDefaults: (defaults: Partial<UserPreferences>) => void;
}
const PreferencesContext = createContext<PreferencesContextValue | undefined>(undefined);
export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
export const PreferencesProvider: React.FC<{
children: React.ReactNode;
}> = ({ children }) => {
const [preferences, setPreferences] = useState<UserPreferences>(() => {
// Load preferences synchronously on mount
// Load preferences synchronously on mount with hardcoded defaults
return preferencesService.getAllPreferences();
});
@@ -34,12 +37,19 @@ export const PreferencesProvider: React.FC<{ children: React.ReactNode }> = ({ c
setPreferences(preferencesService.getAllPreferences());
}, []);
const updateServerDefaults = useCallback((defaults: Partial<UserPreferences>) => {
preferencesService.setServerDefaults(defaults);
// Reload preferences to apply server defaults
setPreferences(preferencesService.getAllPreferences());
}, []);
return (
<PreferencesContext.Provider
value={{
preferences,
updatePreference,
resetPreferences,
updateServerDefaults,
}}
>
{children}

View File

@@ -689,7 +689,7 @@ export function useTranslatedToolCatalog(): TranslatedToolCatalog {
subcategoryId: SubcategoryId.AUTOMATION,
maxFiles: -1,
supportedFormats: CONVERT_SUPPORTED_FORMATS,
endpoints: ["handleData"],
endpoints: ["automate"],
synonyms: getSynonyms(t, "automate"),
automationSettings: null,
},
@@ -808,6 +808,7 @@ export function useTranslatedToolCatalog(): TranslatedToolCatalog {
categoryId: ToolCategoryId.ADVANCED_TOOLS,
subcategoryId: SubcategoryId.DEVELOPER_TOOLS,
link: devApiLink,
endpoints: ["dev-api-docs"],
synonyms: getSynonyms(t, "devApi"),
supportsAutomate: false,
automationSettings: null
@@ -820,6 +821,7 @@ export function useTranslatedToolCatalog(): TranslatedToolCatalog {
categoryId: ToolCategoryId.ADVANCED_TOOLS,
subcategoryId: SubcategoryId.DEVELOPER_TOOLS,
link: "https://docs.stirlingpdf.com/Configuration/Folder%20Scanning/",
endpoints: ["dev-folder-scanning-docs"],
synonyms: getSynonyms(t, "devFolderScanning"),
supportsAutomate: false,
automationSettings: null
@@ -832,6 +834,7 @@ export function useTranslatedToolCatalog(): TranslatedToolCatalog {
categoryId: ToolCategoryId.ADVANCED_TOOLS,
subcategoryId: SubcategoryId.DEVELOPER_TOOLS,
link: "https://docs.stirlingpdf.com/Configuration/Single%20Sign-On%20Configuration/",
endpoints: ["dev-sso-guide-docs"],
synonyms: getSynonyms(t, "devSsoGuide"),
supportsAutomate: false,
automationSettings: null
@@ -844,6 +847,7 @@ export function useTranslatedToolCatalog(): TranslatedToolCatalog {
categoryId: ToolCategoryId.ADVANCED_TOOLS,
subcategoryId: SubcategoryId.DEVELOPER_TOOLS,
link: "https://docs.stirlingpdf.com/Paid-Offerings/#activating-your-license",
endpoints: ["dev-airgapped-docs"],
synonyms: getSynonyms(t, "devAirgapped"),
supportsAutomate: false,
automationSettings: null

View File

@@ -42,6 +42,7 @@ export default function HomePage() {
handleBackToTools,
readerMode,
setLeftPanelView,
toolAvailability,
} = useToolWorkflow();
const { openFilesModal } = useFilesModalContext();
@@ -249,19 +250,21 @@ export default function HomePage() {
<AppsIcon sx={{ fontSize: '1.5rem' }} />
<span className="mobile-bottom-button-label">{t('quickAccess.allTools', 'Tools')}</span>
</button>
<button
className="mobile-bottom-button"
aria-label={t('quickAccess.automate', 'Automate')}
onClick={() => {
handleToolSelect('automate');
if (isMobile) {
setActiveMobileView('tools');
}
}}
>
<LocalIcon icon="automation-outline" width="1.5rem" height="1.5rem" />
<span className="mobile-bottom-button-label">{t('quickAccess.automate', 'Automate')}</span>
</button>
{toolAvailability['automate']?.available !== false && (
<button
className="mobile-bottom-button"
aria-label={t('quickAccess.automate', 'Automate')}
onClick={() => {
handleToolSelect('automate');
if (isMobile) {
setActiveMobileView('tools');
}
}}
>
<LocalIcon icon="automation-outline" width="1.5rem" height="1.5rem" />
<span className="mobile-bottom-button-label">{t('quickAccess.automate', 'Automate')}</span>
</button>
)}
<button
className="mobile-bottom-button"
aria-label={t('home.mobile.openFiles', 'Open files')}

View File

@@ -38,6 +38,12 @@ export const DEFAULT_PREFERENCES: UserPreferences = {
const STORAGE_KEY = 'stirlingpdf_preferences';
class PreferencesService {
private serverDefaults: Partial<UserPreferences> = {};
setServerDefaults(defaults: Partial<UserPreferences>): void {
this.serverDefaults = defaults;
}
getPreference<K extends keyof UserPreferences>(
key: K
): UserPreferences[K] {
@@ -53,6 +59,10 @@ class PreferencesService {
} catch (error) {
console.error('Error reading preference:', key, error);
}
// Use server defaults if available, otherwise use hardcoded defaults
if (key in this.serverDefaults && this.serverDefaults[key] !== undefined) {
return this.serverDefaults[key]!;
}
return DEFAULT_PREFERENCES[key];
}
@@ -75,16 +85,18 @@ class PreferencesService {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored) {
const preferences = JSON.parse(stored) as Partial<UserPreferences>;
// Merge with defaults to ensure all preferences exist
// Merge with server defaults first, then stored preferences
return {
...DEFAULT_PREFERENCES,
...this.serverDefaults,
...preferences,
};
}
} catch (error) {
console.error('Error reading preferences', error);
}
return { ...DEFAULT_PREFERENCES };
// Merge server defaults with hardcoded defaults
return { ...DEFAULT_PREFERENCES, ...this.serverDefaults };
}
clearAllPreferences(): void {

View File

@@ -1,6 +1,6 @@
import { useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Stack, Paper, Text, Loader, Group, MultiSelect } from '@mantine/core';
import { Button, Stack, Paper, Text, Loader, Group, MultiSelect, Switch } from '@mantine/core';
import { alert } from '@app/components/toast';
import RestartConfirmationModal from '@app/components/shared/config/RestartConfirmationModal';
import { useRestartServer } from '@app/components/shared/config/useRestartServer';
@@ -9,6 +9,11 @@ import PendingBadge from '@app/components/shared/config/PendingBadge';
import { useLoginRequired } from '@app/hooks/useLoginRequired';
import LoginRequiredBanner from '@app/components/shared/config/LoginRequiredBanner';
interface UISettingsData {
defaultHideUnavailableTools?: boolean;
defaultHideUnavailableConversions?: boolean;
}
interface EndpointsSettingsData {
toRemove?: string[];
groupsToRemove?: string[];
@@ -31,11 +36,24 @@ export default function AdminEndpointsSection() {
sectionName: 'endpoints',
});
const {
settings: uiSettings,
setSettings: setUiSettings,
loading: uiLoading,
saving: uiSaving,
fetchSettings: fetchUiSettings,
saveSettings: saveUiSettings,
isFieldPending: isUiFieldPending,
} = useAdminSettings<UISettingsData>({
sectionName: 'ui',
});
useEffect(() => {
if (loginEnabled) {
fetchSettings();
fetchUiSettings();
}
}, [loginEnabled, fetchSettings]);
}, [loginEnabled, fetchSettings, fetchUiSettings]);
const handleSave = async () => {
if (!validateLoginEnabled()) {
@@ -54,8 +72,29 @@ export default function AdminEndpointsSection() {
}
};
const handleUiSave = async () => {
if (!validateLoginEnabled()) {
return;
}
try {
await saveUiSettings();
alert({
alertType: 'success',
title: t('admin.success', 'Success'),
body: t('admin.settings.saveSuccess', 'Settings saved successfully. Restart required for changes to take effect.'),
});
} catch (_error) {
alert({
alertType: 'error',
title: t('admin.error', 'Error'),
body: t('admin.settings.saveError', 'Failed to save settings'),
});
}
};
// Override loading state when login is disabled
const actualLoading = loginEnabled ? loading : false;
const actualLoading = loginEnabled ? (loading || uiLoading) : false;
if (actualLoading) {
return (
@@ -77,11 +116,16 @@ export default function AdminEndpointsSection() {
'auto-redact',
'auto-rename',
'auto-split-pdf',
'automate',
'booklet-imposition',
'cert-sign',
'compare',
'compress-pdf',
'crop',
'dev-airgapped-docs',
'dev-api-docs',
'dev-folder-scanning-docs',
'dev-sso-guide-docs',
'edit-table-of-contents',
'eml-to-pdf',
'extract-image-scans',
@@ -109,6 +153,7 @@ export default function AdminEndpointsSection() {
'pdf-to-text',
'pdf-to-word',
'pdf-to-xml',
'pipeline',
'rearrange-pages',
'remove-annotations',
'remove-blanks',
@@ -143,6 +188,9 @@ export default function AdminEndpointsSection() {
'Security',
'Other',
'Advance',
'Automation',
'DeveloperTools',
'DeveloperDocs',
// Tool Groups
'CLI',
'Python',
@@ -224,18 +272,61 @@ export default function AdminEndpointsSection() {
disabled={!loginEnabled}
/>
</div>
<Paper bg="var(--mantine-color-blue-light)" p="sm" radius="sm">
<Text size="xs" c="dimmed">
{t('admin.settings.endpoints.note', 'Note: Disabling endpoints restricts API access but does not remove UI components. Restart required for changes to take effect.')}
</Text>
</Paper>
</Stack>
</Paper>
<Group justify="flex-end">
<Button onClick={handleSave} loading={saving} size="sm" disabled={!loginEnabled}>
{t('admin.settings.save', 'Save Changes')}
{t('admin.settings.save', 'Save Endpoint Settings')}
</Button>
</Group>
<Paper withBorder p="md" radius="md">
<Stack gap="md">
<div>
<Text fw={600} size="sm" mb="xs">{t('admin.settings.endpoints.userDefaults', 'User Preference Defaults')}</Text>
<Text size="xs" c="dimmed">
{t('admin.settings.endpoints.userDefaultsDescription', 'Set default values for user preferences. Users can override these in their personal settings.')}
</Text>
</div>
<Switch
label={
<Group gap="xs">
<span>{t('admin.settings.endpoints.defaultHideUnavailableTools.label', 'Hide unavailable tools by default')}</span>
<PendingBadge show={isUiFieldPending('defaultHideUnavailableTools')} />
</Group>
}
description={t('admin.settings.endpoints.defaultHideUnavailableTools.description', 'Remove disabled tools instead of showing them greyed out')}
checked={uiSettings.defaultHideUnavailableTools || false}
onChange={(e) => {
if (!loginEnabled) return;
setUiSettings({ ...uiSettings, defaultHideUnavailableTools: e.currentTarget.checked });
}}
disabled={!loginEnabled}
/>
<Switch
label={
<Group gap="xs">
<span>{t('admin.settings.endpoints.defaultHideUnavailableConversions.label', 'Hide unavailable conversions by default')}</span>
<PendingBadge show={isUiFieldPending('defaultHideUnavailableConversions')} />
</Group>
}
description={t('admin.settings.endpoints.defaultHideUnavailableConversions.description', 'Remove disabled conversion options instead of showing them greyed out')}
checked={uiSettings.defaultHideUnavailableConversions || false}
onChange={(e) => {
if (!loginEnabled) return;
setUiSettings({ ...uiSettings, defaultHideUnavailableConversions: e.currentTarget.checked });
}}
disabled={!loginEnabled}
/>
</Stack>
</Paper>
<Group justify="flex-end">
<Button onClick={handleUiSave} loading={uiSaving} size="sm" disabled={!loginEnabled}>
{t('admin.settings.save', 'Save User Defaults')}
</Button>
</Group>