Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud code bug #616

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/B4ACodeTree/B4ACodeTree.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ export default class B4ACodeTree extends React.Component {
}
else if (selected.text === 'public') {
source = publicFolderPlaceholder
} else {
source = 'Select a file to view'
}
}
}
Expand Down Expand Up @@ -269,7 +271,7 @@ export default class B4ACodeTree extends React.Component {
else if (this.state.isFolderSelected === true) {
content = this.state.source && this.state.source !== '' ? <B4aEmptyState
margin="46px 0 0 0"
imgSrc={folderInfoIcon}
// imgSrc={folderInfoIcon}
description={this.state.source} /> : <div></div>;
}
else if (this.state.selectedFile) {
Expand All @@ -294,7 +296,7 @@ export default class B4ACodeTree extends React.Component {
</div>;
} else {
content = (
<B4aEmptyState imgSrc={folderInfoIcon} description="Select a file to edit" margin="46px 0 0 0" />
<B4aEmptyState description="Select a file to edit" margin="46px 0 0 0" />
);
}

Expand Down
54 changes: 48 additions & 6 deletions src/components/B4ACodeTree/B4ATreeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,43 @@ const getConfig = (files) => {
return {
plugins: ['contextmenu', 'dnd', 'sort', 'types', 'unique', 'changed'],
core: {
'check_callback': true,
'check_callback': async function (operation, node, node_parent) {
if (operation === 'create_node' && node.type === 'new-folder') {
const originalInputName = node.text;
const folderList = [];
node_parent.children.forEach(child => {
const childNode = $('#tree').jstree('get_node', child);
if ((childNode.type === 'new-folder' || childNode.type === 'folder') && childNode.text === node.text) {
folderList.push(childNode);
node.text = folderList.length ? `${originalInputName} (${folderList.length})` : `${originalInputName}`;
}
});
}
if (operation === 'create_node' && node.type === 'new-file') {
const duplicate = node_parent.children.find(child => {
const childNode = $('#tree').jstree('get_node', child);
if ((childNode.type === 'new-file' || childNode.type === 'default') && childNode.text === node.text) {return true;}
return false;
});
if (duplicate) {
overwriteFileModal.text = node.text + ' file already exists. Do you want to overwrite?'
// Show alert and wait for the user response
const alertResponse = await MySwal.fire(overwriteFileModal);
if (alertResponse.value) {
$('#tree').jstree('delete_node', duplicate);
const newNodeId = $('#tree').jstree('create_node', node_parent.id, node);
$('#tree').jstree('deselect_all');
$('#tree').jstree('select_node', newNodeId);
}
}
}
return true;
},
'data': files,
'theme': {
'name': 'default-dark',
}
},
'multiple': false,
},
contextmenu: {items: customMenu},
types: {
Expand Down Expand Up @@ -309,10 +341,20 @@ const selectFileOnTree = (nodeId) => {
$('#tree').jstree().select_node(nodeId); // select specified node
}

const sanitizeHTML = (str) => {
return str.replace(/[^\w. ]/gi, function (c) {
return '&#' + c.charCodeAt(0) + ';';
});
const sanitizeHTML = (filename) => {
const illegalRe = /[\/\?<>\\:\*\|"]/g; // Illegal characters for filenames
const controlRe = /[\x00-\x1f\x80-\x9f]/g; // Illegal control characters
const scriptTagRe = /<script.*?>.*?<\/script>|script/gi; // Script tags, case-insensitive and global match

// Remove illegal and control characters
let cleanedFilename = filename.replace(illegalRe, '') .replace(controlRe, '').replace(scriptTagRe, '');

// Truncate to 200 characters if necessary
if (cleanedFilename.length > 200) {
cleanedFilename = cleanedFilename.substring(0, 200);
}

return cleanedFilename;
};

export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,8 @@ export default class B4aPermissionsDialog extends React.Component {
);
} else if (pointer) {
// get class info from schema
const { type, targetClass } = columns[key];
const selectedCol = columns.find(col => col.name === key);
const { type, targetClass } = selectedCol;

const pillText = type + (targetClass ? `<${targetClass}>` : '');

Expand Down
4 changes: 3 additions & 1 deletion src/components/Sidebar/SidebarSection.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import Icon from 'components/Icon/Icon.react';
import { Link } from 'react-router-dom';
import React from 'react';
import styles from 'components/Sidebar/B4aSidebar.scss';
import { amplitudeLogEvent } from 'lib/amplitudeEvents';

const sendEvent = () => {
// eslint-disable-next-line no-undef
back4AppNavigation && back4AppNavigation.atApiReferenceIntroEvent && back4AppNavigation.atApiReferenceIntroEvent()
// back4AppNavigation && back4AppNavigation.atApiReferenceIntroEvent && back4AppNavigation.atApiReferenceIntroEvent()
amplitudeLogEvent('at API Reference Introduction');
}

const SidebarSection = ({ active, children, name, link, icon, style, primaryBackgroundColor, secondaryBackgroundColor, isCollapsed, onClick, badge }) => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/Sidebar/SidebarSubItem.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { Link } from "react-router-dom";
import React from "react";
import styles from "components/Sidebar/B4aSidebar.scss";
import B4aBadge from "components/B4aBadge/B4aBadge.react";
import { amplitudeLogEvent } from 'lib/amplitudeEvents';

const sendEvent = () => {
back4AppNavigation &&
back4AppNavigation.atApiReferenceIntroEvent &&
back4AppNavigation.atApiReferenceIntroEvent();
// back4AppNavigation &&
// back4AppNavigation.atApiReferenceIntroEvent &&
// back4AppNavigation.atApiReferenceIntroEvent();
amplitudeLogEvent('at API Reference Introduction');
};

let SidebarSubItem = ({ active, name, action, link, children, badge }) => {
Expand Down
Loading