Skip to content

Commit

Permalink
changes for : #361 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielc-n committed Sep 11, 2024
1 parent 760fa75 commit 3a51358
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@babel/eslint-parser": "^7.5.4",
"@babel/preset-env": "^7.25.4",
"@babel/preset-react": "^7.17.12",
"@mui/icons-material": "^5.8.4",
"@netlify/plugin-nextjs": "^4.8.0",
"@playwright/test": "^1.36.2",
"@svgr/webpack": "^5.5.0",
Expand Down Expand Up @@ -118,8 +119,7 @@
"postcss": "^8.4.21",
"prettier": "^2.8.3",
"source-map-explorer": "^2.5.3",
"tailwindcss": "^3.2.4",
"@mui/icons-material": "^5.8.4"
"tailwindcss": "^3.2.4"
},
"peerDependencies": {
"@material-ui/core": "^4.x",
Expand Down Expand Up @@ -205,6 +205,7 @@
"proskomma-core": "^0.10.4",
"proskomma-json-tools": "^0.8.16",
"proskomma-react-hooks": "2.4.0",
"random-words": "^2.0.1",
"raw-loader": "^4.0.2",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.1",
Expand Down Expand Up @@ -248,4 +249,4 @@
"word-aligner": "$word-aligner",
"@mui/lab": "$@mui/lab"
}
}
}
50 changes: 40 additions & 10 deletions renderer/src/layouts/editor/InnerFramePopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
StyledSwitch,
} from './pdfGenInterface/pdfGenWrappers/fieldPicker/customMuiComponent';
import { WrapperTemplate } from './pdfGenInterface/pdfGenWrappers/WrapperTemplate';
import { generate } from "random-words";

export default function InnerFramePopup() {
const {
Expand Down Expand Up @@ -57,15 +58,15 @@ export default function InnerFramePopup() {
const { t } = useTranslation();

//advenceMode allow adding new Wrapper
const [advanceMode, setAdvenceMode] = useState(false);
const [advanceMode, setAdvanceMode] = useState(false);
const [infoProject, setInfoProject] = useState(
findProjectInfo(selectedProject, projects),
);

//the selected headerInfo
const [headerInfo, setHeaderInfo] = useState('{"sizes":"9on11","fonts":"allGentium","pages":"EXECUTIVE"}');
// const [headerInfo, setHeaderInfo] = useState('{}');
const [nameFile, setNameFile] = useState('');
const [nameFile, setNameFile] = useState("");
const [folder, setFolder] = useState(null);
//zoom of the preview
const [kitchenFaucet, setKitchenFaucet] = useState('{}');
Expand Down Expand Up @@ -196,22 +197,32 @@ export default function InnerFramePopup() {

useEffect(() => {
let validationJson = global.PdfGenStatic.validateConfig(JSON.parse(kitchenFaucet));
console.log('call ! validationJson ==',validationJson);
if (validationJson.length === 0) {
let header = JSON.parse(headerInfo);
// console.log('header ==',header);
console.log('header ==',header);
if (
header.workingDir &&
header.outputPath &&
folder &&
header.sizes &&
header.fonts &&
header.pages
)
) {
if(!header.outputPath && folder) {
setHeaderInfo((prev) => {
let data = { ...JSON.parse(prev) };
data['outputPath'] = folder + '/' + generate({exactly: 5, wordsPerString:1}).join("-") + '.pdf';
data['verbose'] = false;
return JSON.stringify(data);
});
}
setIsJsonValidate(true);
}
} else {
setIsJsonValidate(false);
}
// console.log("kitchenFaucet==",kitchenFaucet);
}, [kitchenFaucet, headerInfo]);
}, [selected, headerInfo, orderSelection, folder, kitchenFaucet]);

const openFileDialogSettingData = async () => {
try {
Expand All @@ -227,6 +238,7 @@ export default function InnerFramePopup() {
}
if (chosenFolder.filePaths.length > 0) {
setFolder(chosenFolder.filePaths[0]);
setMessagePrint((prev) => prev + '\n' + 'folder selected : ' + chosenFolder.filePaths[0]);
} else {
// Handle case where no folder was selected
console.log('No folder was selected');
Expand All @@ -236,6 +248,24 @@ export default function InnerFramePopup() {
}
};

useEffect(() => {
if (folder && nameFile == '') {
setHeaderInfo((prev) => {
let data = { ...JSON.parse(prev) };
data['outputPath'] = folder + '/' + generate({exactly: 5, wordsPerString:1}).join("-") + '.pdf';
data['verbose'] = false;
return JSON.stringify(data);
});
} else if (folder && nameFile !== '') {
setHeaderInfo((prev) => {
let data = { ...JSON.parse(prev) };
data['outputPath'] = folder + '/' + nameFile + '.pdf';
data['verbose'] = false;
return JSON.stringify(data);
});
}
}, [folder]);

useEffect(() => {
if (folder && nameFile !== '') {
setHeaderInfo((prev) => {
Expand All @@ -245,7 +275,7 @@ export default function InnerFramePopup() {
return JSON.stringify(data);
});
}
}, [nameFile, folder]);
}, [nameFile]);

useEffect(() => {
const fs = window.require('fs');
Expand All @@ -269,7 +299,7 @@ export default function InnerFramePopup() {

const handleInputChange = (e) => {
const value = e.target.value;
const regex = /^[a-zA-Z_]*$/; // Regular expression to allow only letters and underscores
const regex = /^[a-zA-Z_-]*$/; // Regular expression to allow only letters, underscores and dashes

if (regex.test(value)) {
setNameFile(value); // Update state only if the input matches the regex
Expand Down Expand Up @@ -414,7 +444,7 @@ export default function InnerFramePopup() {
}}>
<StyledSwitch
onChange={() =>
setAdvenceMode((prev) => !prev)
setAdvanceMode((prev) => !prev)
}
/>
<div
Expand Down Expand Up @@ -522,7 +552,7 @@ export default function InnerFramePopup() {
handleInputChange(e);
}}
value={nameFile}
placeholder={'your file name here'}
placeholder={'your file name here (no special characters allowed)'}
/>
<Button
style={
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18676,6 +18676,13 @@ raf@^3.3.0, raf@^3.4.1:
dependencies:
performance-now "^2.1.0"

random-words@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/random-words/-/random-words-2.0.1.tgz#cc4564385d040c9fad2b817621a0041a1ecc90f6"
integrity sha512-nZNJAmgcFmtJMTDDIUCm/iK4R6RydC6NvALvWhYItXQrgYGk1F7Gww416LpVROFQtfVd5TaLEf4WuSsko03N7w==
dependencies:
seedrandom "^3.0.5"

randomatic@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed"
Expand Down Expand Up @@ -20078,6 +20085,11 @@ scroll-into-view-if-needed@^2.2.20:
dependencies:
compute-scroll-into-view "^1.0.20"

seedrandom@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down

0 comments on commit 3a51358

Please sign in to comment.