mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
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:
@@ -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 />
|
||||
|
||||
@@ -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[] = [
|
||||
{
|
||||
|
||||
@@ -58,6 +58,8 @@ export interface AppConfig {
|
||||
error?: string;
|
||||
isNewServer?: boolean;
|
||||
isNewUser?: boolean;
|
||||
defaultHideUnavailableTools?: boolean;
|
||||
defaultHideUnavailableConversions?: boolean;
|
||||
}
|
||||
|
||||
export type AppConfigBootstrapMode = 'blocking' | 'non-blocking';
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user