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

v4.3.4 #356

Merged
merged 11 commits into from
Nov 9, 2023
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harperdb-studio",
"version": "4.3.3",
"version": "4.3.4",
"description": "A UI for HarperDB",
"deploymentUrl": "studio.harperdb.io",
"private": true,
Expand Down
10 changes: 4 additions & 6 deletions src/components/instance/functions/manage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,26 +480,24 @@ function ManageIndex({ refreshCustomFunctions, loading }) {

async function revertFileChanges(selectedFile) {

// ditch local storage version
// unset local storage version
removeFileFromLocalStorage({ path: selectedFile.path });

// get file
//
const { error, message} = await getComponentFile({
// get canonical file version
const { error, message } = await getComponentFile({
auth,
url,
project: selectedFile.project,
file: getRelativeFilepath(selectedFile.path)
});

removeFileFromLocalStorage({ path: selectedFile.path });

if (error) {
return alert.error(message);
}

await refreshCustomFunctions();

// return canonical file content to caller
return message;

}
Expand Down
2 changes: 1 addition & 1 deletion src/components/instances/list/NewInstanceCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function NewInstanceCard() {
<div className="my-4">
<i className="fa fa-2x fa-plus-circle new-instance-plus" />
</div>
<span>Register User-Installed Instance</span>
<span>Register Enterprise Instance</span>
</CardBody>
</Card>
</Col>
Expand Down
5 changes: 4 additions & 1 deletion src/components/instances/new/TypeAWS.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React from 'react';
import { Row, Col, Card, CardBody, Button } from 'reactstrap';
import { useStoreState } from 'pullstate';
import AWSLogo from '../../shared/logos/AWSLogo';
import appState from '../../../functions/state/appState';

function TypeAWS({ setFormData }) {
const theme = useStoreState(appState, (s) => s.theme);
return (
<Card className="mb-3">
<CardBody className="instance-form-card-body">
<Row>
<Col xs="8" className="logo-header">
<AWSLogo />
<AWSLogo theme={theme} />
</Col>
<Col xs="4">
<Button
Expand Down
5 changes: 4 additions & 1 deletion src/components/instances/new/TypeVerizon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React from 'react';
import { Row, Col, Card, CardBody, Button } from 'reactstrap';
import { useStoreState } from 'pullstate';
import VerizonLogo from '../../shared/logos/VerizonLogo';
import appState from '../../../functions/state/appState';

function TypeVerizon({ setFormData }) {
const theme = useStoreState(appState, (s) => s.theme);
return (
<Card className="mb-3">
<CardBody className="instance-form-card-body">
<Row>
<Col xs="8" className="logo-header">
<VerizonLogo />
<VerizonLogo theme={theme} />
</Col>
<Col xs="4">
<Button
Expand Down
17 changes: 15 additions & 2 deletions src/components/shared/logos/AWSLogo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/components/shared/logos/VerizonLogo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/shared/webide/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Editor({ active, file, onFileChange, theme }) {
return null;
}

const filepathRelativeToComponentsDir = file.path.split('/').slice(1).join('/');
const filepathRelativeToComponentsDir = file?.path.split('/').slice(1).join('/');

// eslint-disable-next-line no-unused-vars
return <>
Expand Down
66 changes: 34 additions & 32 deletions src/components/shared/webide/EditorMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ import cn from 'classnames';
export function SaveButton({ onClick, disabled }) {

const [ loading, setLoading ] = useState(false);

return (
<button
type="button"
disabled={ disabled }
title="save file to instance"
className={ cn("save-code fas", {
disabled,
'fa-save': !loading,
'fa-spinner': loading,
'fa-spin': loading
}) }
className={
cn("save-code fas", {
disabled,
'fa-save': !loading,
'fa-spinner': loading,
'fa-spin': loading
})
}
onClick={
async () => {

setLoading(true);
setLoading(() => true);
await onClick();
setTimeout(() => {
setLoading(false);
}, 500);
setLoading(() => false);
}
} />
)
);

}

Expand Down Expand Up @@ -74,36 +75,37 @@ export function RestartOnSaveToggle({ onClick, restartAfterSave }) {
);
}

export function RevertFileButton({ onClick, disabled }) {
export function RevertFileButton({ onClick, disabled, loading }) {

return (
<button
type="button"
disabled={ disabled }
title="revert file to previously saved state"
className={
cn('revert-file fas fa-history', { disabled })
onClick={
async () => {
await onClick();
}
}
onClick={ onClick } />
className={
cn("revert-file fas", {
disabled,
'fa-history': !loading,
'fa-spinner': loading,
'fa-spin': loading,
})
} />
);

)
}

// TODO: convert to mapping children to a list instead of explicitly doing all of this
export default function EditorMenu({ SaveButton: SaveBtn, RestartInstanceButton: RestartInstanceBtn, RestartOnSaveToggle: RestartOnSaveTgl, RevertFileButton: RevertFileBtn }) {
return (
export default function EditorMenu({ children }) {

const keys = children?.map(() => crypto.randomUUID());

return children ? (
<ul className="editor-menu">
<li>
<SaveBtn />
</li>
<li>
<RestartInstanceBtn />
</li>
<li>
<RestartOnSaveTgl />
</li>
<li>
<RevertFileBtn />
</li>
{ children.map((child, index) => <li key={keys[index]}>{child}</li>) }
</ul>
)
) : null;
}
3 changes: 1 addition & 2 deletions src/components/shared/webide/FileMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import cn from 'classnames';
import { v4 as uuid } from 'uuid';


export function DeleteFolderButton({ onClick, disabled }) {
Expand Down Expand Up @@ -82,7 +81,7 @@ function FileMenu({ children }) {
return (
<ul className="file-menu">
{
children.map(child => <li className="file-menu-item" key={ uuid() }>{child}</li>)
children.map(child => <li className="file-menu-item" key={ crypto.randomUUID() }>{child}</li>)
}
</ul>
)
Expand Down
96 changes: 45 additions & 51 deletions src/components/shared/webide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function WebIDE({
const [ activeEditorWindow, setActiveEditorWindow ] = useState(EDITOR_WINDOWS.DEFAULT_WINDOW);
const [ previousActiveEditorWindow, setPreviousActiveEditorWindow ] = useState(null);
const [ restartAfterSave, setRestartAfterSave ] = useState(true);
const [ revertingFile, setRevertingFile ] = useState(false);

const hasProjects = fileTree?.entries?.length > 0;
const canAddFile = Boolean(hasProjects && selectedFolder); // can only add a file if a target folder is selected
Expand Down Expand Up @@ -233,57 +234,50 @@ function WebIDE({
} />
</Col>
<Col className="editor-window-container col-md-8">
<EditorMenu
SaveButton={
() => (
<SaveButton
disabled={ !(selectedFile && activeEditorWindow === EDITOR_WINDOWS.CODE_EDITOR_WINDOW) }
onClick={
async () => {
await onFileSave(selectedFile, restartAfterSave)
}
} />
)
}
RestartInstanceButton={
() => (
<RestartInstanceButton
restarting={restartingInstance}
onClick={
async () => {
await restartInstance();
}
} />
)
}
RestartOnSaveToggle={
() => (
<RestartOnSaveToggle
restartAfterSave={restartAfterSave}
onClick={
() => {
setRestartAfterSave(!restartAfterSave);
}
} />
)
}
RevertFileButton={
() => (
<RevertFileButton
disabled={!selectedFile?.cached}
onClick={
async () => {
const updatedContent = await onRevertFile(selectedFile);
setSelectedFile({
...selectedFile,
content: updatedContent,
cached: false
});
}
} />
)
}
/>
<EditorMenu>
<SaveButton
disabled={ !(selectedFile && activeEditorWindow === EDITOR_WINDOWS.CODE_EDITOR_WINDOW) }
onClick={
async () => {
await onFileSave(selectedFile, restartAfterSave)
}
} />
<RestartInstanceButton
restarting={restartingInstance}
onClick={
async () => {
await restartInstance();
}
} />
<RestartOnSaveToggle
restartAfterSave={restartAfterSave}
onClick={
() => {
setRestartAfterSave(!restartAfterSave);
}
} />
<RevertFileButton
loading={ revertingFile }
disabled={!(selectedFile?.cached && activeEditorWindow === EDITOR_WINDOWS.CODE_EDITOR_WINDOW)}
onClick={
async () => {

setRevertingFile(true);
try {
const updatedContent = await onRevertFile(selectedFile);
const updatedSelectedFile = {
...selectedFile,
content: updatedContent,
cached: false
};
setSelectedFile(updatedSelectedFile);
} finally {
setRevertingFile(false);
}

}
} />
</EditorMenu>
<EditorWindow>
<DefaultWindow
fileTree={fileTree}
Expand Down
5 changes: 2 additions & 3 deletions src/functions/api/instance/getComponents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from 'uuid';
import queryInstance from '../queryInstance';

// this 'addMetadata' logic probably belongs in src/functions/instance
Expand All @@ -11,7 +10,7 @@ function addMetadata(fileTree, path, rootDir, readOnly=false) {

if (path === rootDir) {
fileTree.path = rootDir;
fileTree.key = uuid();
fileTree.key = crypto.randomUUID();
}

for (const entry of fileTree.entries) {
Expand All @@ -27,7 +26,7 @@ function addMetadata(fileTree, path, rootDir, readOnly=false) {
const [ , project ] = newPath.split('/');
entry.project = project;
entry.path = newPath;
entry.key = uuid();
entry.key = crypto.randomUUID();
entry.readOnly = readOnly || !!entry.package;

addMetadata(entry, newPath, rootDir, entry.readOnly);
Expand Down