import { __ } from '@wordpress/i18n'; import Icon from '../utils/Icon' import * as rsssl_api from "../utils/api"; import useFields from "../Settings/FieldsData"; import useProgress from "./Progress/ProgressData"; import useMenu from "../Menu/MenuData"; import DOMPurify from "dompurify"; import {useState} from "@wordpress/element"; const TaskElement = (props) => { const {dismissNotice, getProgressData} = useProgress(); const {getField, setHighLightField, showSavedSettingsNotice, updateFieldAttribute} = useFields(); const {setSelectedSubMenuItem} = useMenu(); const [processing, setProcessing] = useState(false); const handleClick = async () => { setHighLightField(props.notice.output.highlight_field_id); let highlightField = getField(props.notice.output.highlight_field_id); await setSelectedSubMenuItem(highlightField.menu_id); } const handleFix = (fix_id) => { let data = {}; data.fix_id = fix_id; setProcessing(true); rsssl_api.doAction('fix', data).then( ( response ) => { setProcessing(false); showSavedSettingsNotice(response.msg); getProgressData(); }); } const handleClearCache = async (cache_id) => { setProcessing(true) let data = {}; data.cache_id = cache_id; try { // First clear the cache on the server await rsssl_api.doAction('clear_cache', data); // If this is the 404 resources cache clear, update our field states if (cache_id === 'rsssl_homepage_contains_404_resources') { // Update the disabled state for both 404-related fields updateFieldAttribute('404_blocking_threshold', 'disabled', false); updateFieldAttribute('404_blocking_lockout_duration', 'disabled', false); } // Show notice and refresh progress data showSavedSettingsNotice(__('Re-started test', 'really-simple-ssl')); await getProgressData(); } catch (error) { console.error('Error clearing cache:', error); } finally { setProcessing(false); } } let notice = props.notice; let premium = notice.output.icon==='premium'; //treat links to rsssl.com and internal links different. let urlIsExternal = notice.output.url && notice.output.url.indexOf('really-simple-ssl.com') !== -1; return(
{ notice.output.label }

{/* nosemgrep: react-dangerouslysetinnerhtml */} {urlIsExternal && notice.output.url && {__("More info", "really-simple-ssl")} } {notice.output.clear_cache_id && handleClearCache(notice.output.clear_cache_id ) }>{__("Re-check", "really-simple-ssl")} } {notice.output.fix_id && handleFix(notice.output.fix_id ) }> {!processing && __("Fix", "really-simple-ssl")} {processing && } } {!premium && !urlIsExternal && notice.output.url && {!processing && __("View", "really-simple-ssl")} {processing && } } {!premium && notice.output.highlight_field_id && handleClick()}>{__("View", "really-simple-ssl")} } {notice.output.plusone && 1} {notice.output.dismissible && notice.output.status!=='completed' &&
}
); } export default TaskElement;