Skip to content

Commit

Permalink
checks correctly showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
danielc-n committed Sep 30, 2024
1 parent 038a173 commit 7e3b656
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 155 deletions.
139 changes: 37 additions & 102 deletions renderer/src/components/EditorPage/TextEditor/ChecksPopup.jsx
Original file line number Diff line number Diff line change
@@ -1,144 +1,79 @@
/* eslint-disable no-unused-vars */
import React, { useEffect, useRef, useState, useContext, Fragment } from 'react';
import React, { useEffect, useState } from 'react';
import { XMarkIcon } from '@heroicons/react/24/solid';
import { Dialog, Transition } from '@headlessui/react';
import { SnackBar } from '@/components/SnackBar';
import { Disclosure } from '@headlessui/react';
import { ChevronUpIcon } from '@heroicons/react/20/solid';
import { randomUUID } from 'crypto';
// import * as logger from '../../logger';

export default function ChecksPopup({
openChecksPopup,
setOpenChecksPopup,
content
}) {
const cancelButtonRef = useRef(null);
// const [groupedData, setGroupedData] = useRef({});
export default function ChecksContent({ content }) {
const [openSnackBar, setOpenSnackBar] = useState(false);
const [snackText, setSnackText] = useState('');
const [groupedData, setGroupedData] = useState({});
const [error, setError] = useState('');

const removeSection = () => {
setOpenChecksPopup(false);
};

const isArray = Array.isArray(content);


useEffect(() => {
if (isArray) {
let tmpGroupedData = {};
let currentName = "";
for (let check of content) {
// console.log("check==", check);
currentName = check.name;
if (!tmpGroupedData[currentName]) {
tmpGroupedData[currentName] = [];
}
delete check.name;
tmpGroupedData[currentName].push(check);
}
console.log("tmpGroupedData ==", tmpGroupedData)
setGroupedData(tmpGroupedData);
}
}, [content]);

useEffect(() => {
console.log("groupedData ==", groupedData)
console.log("groupedData ==", groupedData);
}, [groupedData]);

// const groupedData = () => {
// let group = {};
// if (isArray) {
// content.forEach(test => {
// test.issues.reduce((acc, curr) => {
// if (!acc[curr.name]) {
// acc[curr.name] = [];
// }
// acc[curr.name].push(curr);

// return acc;
// }, {});
// });
// console.log("content ==", content);
// } else {
// return [];
// }
// }

return (
<>
<Transition
show={openChecksPopup}
as={Fragment}
enter='transition duration-100 ease-out'
enterFrom='transform scale-95 opacity-0'
enterTo='transform scale-100 opacity-100'
leave='transition duration-75 ease-out'
leaveFrom='transform scale-100 opacity-100'
leaveTo='transform scale-95 opacity-0'>
<Dialog
as='div'
className='fixed inset-0 z-10 overflow-y-auto'
initialFocus={cancelButtonRef}
static
open={openChecksPopup}
onClose={removeSection}>
<Dialog.Overlay className='fixed inset-0 bg-black opacity-50' />
<div className='flex items-center justify-center min-h-screen'>
<div className='relative bg-white rounded-lg shadow-xl w-full max-w-3xl mx-auto my-8 p-4'>
<div className='bg-primary flex justify-between items-center rounded-t-lg p-4'>
<h1 className='text-white font-bold text-lg'>Checks</h1>
<button
type='button'
className='text-white'
onClick={removeSection}>
<XMarkIcon className='h-6 w-6' />
</button>
</div>
<div className='bg-gray-50 p-6 rounded-b-lg max-h-[75vh] overflow-y-auto'>
{Object.keys(groupedData).length > 0 ? (
Object.keys(groupedData).map((key) => (
<Disclosure key={key}>
{({ open }) => (
<>
<Disclosure.Button className='flex justify-between w-full px-4 py-2 text-sm font-medium text-left text-gray-700 bg-gray-200 rounded-lg hover:bg-gray-300 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75'>
<span>{key}</span>
<ChevronUpIcon
className={`${open ? '' : 'transform rotate-180'
} w-5 h-5 text-gray-500`}
/>
</Disclosure.Button>
<Disclosure.Panel className='px-4 pt-4 pb-2 text-sm text-gray-700'>
<ul className='space-y-2'>
{groupedData[key].map((item, index) => (
<li key={index} className='border p-2 rounded bg-white shadow-sm'>
{item.args.cv}
</li>
))}
</ul>
</Disclosure.Panel>
</>
)}
</Disclosure>
))
) : (
<p className='text-center text-gray-500'>No content available.</p>
)}
</div>
</div>
</div>
</Dialog>
</Transition>
<div className='container mx-auto'>
<div className='bg-primary flex justify-between items-center p-4 rounded-lg'>
<h2 className='text-white font-bold text-lg'>Checks</h2>
</div>
<div className='bg-gray-50 p-6 rounded-lg max-h-[75vh] overflow-y-auto'>
{Object.keys(groupedData).length > 0 ? (
Object.keys(groupedData).map((key) => (
<Disclosure key={key}>
{({ open }) => (
<>
<Disclosure.Button className='flex justify-between w-full px-4 py-2 text-sm font-medium text-left text-gray-700 bg-gray-200 rounded-lg hover:bg-gray-300 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75'>
<span>{key}</span>
<ChevronUpIcon
className={`${open ? '' : 'transform rotate-180'} w-5 h-5 text-gray-500`}
/>
</Disclosure.Button>
<Disclosure.Panel className='px-4 pt-4 pb-2 text-sm text-gray-700'>
<ul className='space-y-2'>
{groupedData[key].map((item, index) => (
<li key={index} className='border p-2 rounded bg-white shadow-sm'>
{item.args.cv}
</li>
))}
</ul>
</Disclosure.Panel>
</>
)}
</Disclosure>
))
) : (
<p className='text-center text-gray-500'>No content available.</p>
)}
</div>
<SnackBar
openSnackBar={openSnackBar}
setOpenSnackBar={setOpenSnackBar}
snackText={snackText}
setSnackText={setSnackText}
error={error}
/>
</>
</div>
);
}
14 changes: 0 additions & 14 deletions renderer/src/components/EditorPage/TextEditor/EditorMenuBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default function EditorMenuBar(props) {
setVerseNumber,
handleSelectedFont,
setTriggerVerseInsert,
checks,
handleEditorFontSize,
editorFontSize,
} = props;
Expand Down Expand Up @@ -117,19 +116,6 @@ export default function EditorMenuBar(props) {
/>
</div>
</div>
<div
title="Launch checks"
className="flex items-center mr-auto"
>
<div>
<Cog8ToothIcon
aria-label="close-lock"
className="h-5 mr-3 w-5 text-white cursor-pointer"
aria-hidden="true"
onClick={() => checks()}
/>
</div>
</div>
</div>
<div className="mx-2.5 min-h-[33px] flex items-center justify-center">
<div className="flex items-center">
Expand Down
38 changes: 0 additions & 38 deletions renderer/src/components/EditorPage/TextEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ import EditorMenuBar from './EditorMenuBar';
import Editor from './Editor';
import ChecksPopup from './ChecksPopup';
import { PipelineHandler, pipelines } from 'proskomma-json-tools';
import checker from 'perf-checks';

export default function TextEditor() {
const { state, actions } = useContext(ScribexContext);
const { verbose } = state;
const [selectedBook, setSelectedBook] = useState();
const [openChecksPopup, setOpenChecksPopup] = useState(false);
const [bookChange, setBookChange] = useState(false);
const [chapterNumber, setChapterNumber] = useState(1);
const [verseNumber, setVerseNumber] = useState(1);
const [triggerVerseInsert, setTriggerVerseInsert] = useState(false);
const [contentPopUp, setContentPopUp] = useState({});
// const [newVerChapNumber, setInsertNumber] = useState('');
// const [insertVerseRChapter, setInsertVerseRChapter] = useState('');

Expand Down Expand Up @@ -95,39 +92,6 @@ export default function TextEditor() {
}
}, [htmlPerf, state.sequenceIds, perfState]);

const checks = async () => {
const fse = window.require('fs-extra');
const path = window.require('path');
// const checker = window.require('/home/daniel/Documents/Projects/temp/scribe-scripture-editor/renderer/src/components/EditorPage/TextEditor/utils/doChecks/index.js');

const usfmContent = { usfm: "\\id MRK" };
const spec = fse.readJsonSync('/home/daniel/Documents/Projects/temp/scribe-scripture-editor/renderer/src/components/EditorPage/TextEditor/utils/ks.json');

if (perfActions && htmlPerf) {
// const perfContent = { perf: fse.readJsonSync('/home/daniel/Documents/Projects/temp/scribe-scripture-editor/renderer/src/components/EditorPage/TextEditor/utils/doChecks/MARK_titus_aligned_eng.json') };
const perfContent = await perfActions.getPerf();

let ret = checker({ content: { perf: perfContent }, spec, contentType: "perf" });
// const { PipelineHandler } = require('proskomma-json-tools');
// if (perfState.usfmText) {
// const pipelineH = new PipelineHandler(pipelines);
// console.log(pipelineH.listPipelinesNames());
// console.log("type of perfState.usfmText ==", perfState.usfmText);

// let output = await pipelineH.runPipeline("usfmToPerfPipeline", {
// usfm: perfState.usfmText,
// selectors: { "lang": "fra", "abbr": "fraLSG" }
// });
setContentPopUp(ret);
setOpenChecksPopup(true);
console.log(ret);
}
// }


// console.log("usfmText ==",);
}

const _props = {
...state,
...perfState,
Expand All @@ -148,7 +112,6 @@ export default function TextEditor() {
handleSelectedFont,
triggerVerseInsert,
setTriggerVerseInsert,
checks
};
return (
<>
Expand All @@ -161,7 +124,6 @@ export default function TextEditor() {
<EditorMenuBar {..._props} />
<Editor {..._props} />
</div>
<ChecksPopup openChecksPopup={openChecksPopup} setOpenChecksPopup={setOpenChecksPopup} content={contentPopUp} />
</>
);
}
44 changes: 43 additions & 1 deletion renderer/src/layouts/editor/EditorSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
import { ReferenceContext } from '@/components/context/ReferenceContext';
import { ProjectContext } from '@/components/context/ProjectContext';
import ResourcesPopUp from '@/components/Resources/ResourcesPopUp';
import ChecksPopup from '@/components/EditorPage/TextEditor/ChecksPopup';
import { classNames } from '@/util/classNames';
import TaNavigation from '@/components/EditorPage/Reference/TA/TaNavigation';
import TwNavigation from '@/components/EditorPage/Reference/TW/TwNavigation';
Expand All @@ -16,6 +17,7 @@ import SquaresPlusIcon from '@/icons/Common/SquaresPlus.svg';
import { Cog8ToothIcon } from '@heroicons/react/24/outline';
import ConfirmationModal from './ConfirmationModal';
import * as logger from '../../logger';
import checker from 'perf-checks';

export default function EditorSection({
title,
Expand Down Expand Up @@ -47,6 +49,7 @@ export default function EditorSection({
const [openResourcePopUp, setOpenResourcePopUp] = useState(false);
const [openModal, setOpenModal] = useState(false);
const [projectScriptureDir, setProjectScriptureDir] = useState();
const [contentChecks, setContentChecks] = useState({});
const { t } = useTranslation();
const {
state: {
Expand Down Expand Up @@ -169,6 +172,40 @@ export default function EditorSection({
}
};

const checks = async () => {
const fse = window.require('fs-extra');
const path = window.require('path');
// const checker = window.require('/home/daniel/Documents/Projects/temp/scribe-scripture-editor/renderer/src/components/EditorPage/TextEditor/utils/doChecks/index.js');

const usfmContent = { usfm: "\\id MRK" };
const spec = fse.readJsonSync('/home/daniel/Documents/Projects/temp/scribe-scripture-editor/renderer/src/components/EditorPage/TextEditor/utils/ks.json');

const perfActions = false;
if (perfActions && htmlPerf) {
// const perfContent = { perf: fse.readJsonSync('/home/daniel/Documents/Projects/temp/scribe-scripture-editor/renderer/src/components/EditorPage/TextEditor/utils/doChecks/MARK_titus_aligned_eng.json') };
const perfContent = await perfActions.getPerf();

let ret = checker({ content: { perf: perfContent }, spec, contentType: "perf" });
// const { PipelineHandler } = require('proskomma-json-tools');
// if (perfState.usfmText) {
// const pipelineH = new PipelineHandler(pipelines);
// console.log(pipelineH.listPipelinesNames());
// console.log("type of perfState.usfmText ==", perfState.usfmText);

// let output = await pipelineH.runPipeline("usfmToPerfPipeline", {
// usfm: perfState.usfmText,
// selectors: { "lang": "fra", "abbr": "fraLSG" }
// });
setContentChecks(ret);
// setOpenChecksPopup(true);
console.log(ret);
}
// }


// console.log("usfmText ==",);
}

useEffect(() => {
// Since we are adding reference resources from different places the data we have are inconsistant.
// Looking for flavor from the flavors because flavor is only available for scripture and gloss(obs), not for Translation resources
Expand Down Expand Up @@ -357,6 +394,7 @@ export default function EditorSection({
referenceResources.selectedResource = 'checks';
setLoadResource(true);
setReferenceResources(referenceResources);
checks();
}}
>
<Cog8ToothIcon
Expand All @@ -367,7 +405,7 @@ export default function EditorSection({
</button>
</div>
</div>
) : (
) : referenceResources.selectedResource !== 'checks' ? (
<div
style={{
fontFamily: 'sans-serif',
Expand All @@ -381,6 +419,10 @@ export default function EditorSection({
>
{children}
</div>
) : (
<ChecksPopup
content={contentChecks}
/>
)}

{/* //div 12 */}
Expand Down

0 comments on commit 7e3b656

Please sign in to comment.