Skip to content

Commit

Permalink
#25835-fixed-surfer-seo-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofBrylski committed Dec 4, 2024
1 parent 7a2778b commit fdd63bc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
1 change: 0 additions & 1 deletion plugins/field-config/plugin-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const handlePluginFormConfig = ({ name, config, formik }) => {
if (index == null || !type) return;
const ctd = formik.values.surferSeoAnalyzer[index].content_type;
const { sourceFields } = getCachedElement(validFieldsCacheKey);
console.log(sourceFields);

const keysToClearOnCtdChange = ['source'];

Expand Down
45 changes: 34 additions & 11 deletions plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { handleManagePlugin } from './manage/index.js';
import { handlePluginFormConfig } from './field-config/plugin-form/index.js';
import { createSidebar } from './sidebar/index.js';
import { parsePluginSettings } from '../common/helpers.js';
import i18n from 'i18next';

const setupSurferSeo = () => {
(() => {
if (void 0 !== window.surferGuidelines) return;
// if (void 0 !== window.surferGuidelines) return;
window.surferGuidelines = {
init(...i) {
window.__sg_in = i;
Expand Down Expand Up @@ -41,26 +42,48 @@ const appendStyles = () => {
};

registerFn(pluginInfo, (handler, _, { getPluginSettings, getLanguage }) => {
const getSettings = (contentType) => {
const pluginConfig = parsePluginSettings(getPluginSettings());
return pluginConfig?.[contentType?.name];
};

setupSurferSeo();
appendStyles();

const pluginConfig = parsePluginSettings(getPluginSettings());
const language = getLanguage();
if (language !== i18n.language) {
i18n.changeLanguage(language);
}

handler.on('flotiq.plugins.manage::form-schema', (data) =>
handleManagePlugin(data),
);

handler.on('flotiq.form.field::config', (data) => {
if (
data.contentType?.id === pluginInfo.id &&
data.contentType?.nonCtdSchema &&
data.name
) {
return handlePluginFormConfig(data);
}
return handlePluginFormConfig(data);
});

handler.on(
'flotiq.form.sidebar-panel::add',
({ contentType, contentObject }) => {
const ctdConfig = getSettings(contentType);
if (!ctdConfig) return;

return createSidebar(contentObject?.id);
},
);

handler.on('flotiq.form::add', ({ formik, contentType }) => {
const ctdConfig = getSettings(contentType);
if (!ctdConfig) return;

const source = formik.values[ctdConfig.source];
window.surferGuidelines.setHtml(source);
});

handler.on('flotiq.form.sidebar-panel::add', ({ formik }) => {
return createSidebar(formik, pluginConfig);
handler.on('flotiq.language::changed', ({ language }) => {
if (language !== i18n.language) {
i18n.changeLanguage(language);
}
});
});
5 changes: 1 addition & 4 deletions plugins/manage/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
addObjectToCache,
getCachedElement,
} from '../../common/plugin-element-cache.js';
import { addObjectToCache } from '../../common/plugin-element-cache.js';
import {
getValidFields,
validFieldsCacheKey,
Expand Down
8 changes: 3 additions & 5 deletions plugins/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
getCachedElement,
} from '../../common/plugin-element-cache.js';

export const createSidebar = (formik, pluginConfig) => {
const containerCacheKey = `${pluginInfo.id}-surferseo-content-analyzer-container`;
export const createSidebar = (id) => {
const containerCacheKey = `${pluginInfo.id}-${id || ''}-surferseo-content-analyzer-container`;
let contentAnalyzerContainer = getCachedElement(containerCacheKey)?.element;

if (!contentAnalyzerContainer) {
Expand All @@ -14,13 +14,11 @@ export const createSidebar = (formik, pluginConfig) => {

window.surferGuidelines.init(
contentAnalyzerContainer.querySelector('#surfer-guidelines-placeholder'),
'sharing-token',
null,
);

addElementToCache(contentAnalyzerContainer, containerCacheKey);
}

console.log(formik, pluginConfig);

return contentAnalyzerContainer;
};
2 changes: 1 addition & 1 deletion plugins/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
width: 100%;
border: 0;
border-radius: 0.5rem;
height: 400px;
height: 450px;
overflow-y: scroll;
}

0 comments on commit fdd63bc

Please sign in to comment.