@@ -134,13 +208,10 @@ const KeyPair = ({
);
};
-const envMapping = {
- Development: "dev",
- Staging: "staging",
- Production: "prod",
- Testing: "test",
-};
-
+/**
+ * This is the main component for the dashboard (aka the screen with all the encironemnt variable & secrets)
+ * @returns
+ */
export default function Dashboard() {
const [data, setData] = useState();
const [fileState, setFileState] = useState([]);
@@ -196,6 +267,9 @@ export default function Dashboard() {
};
}, [buttonReady]);
+ /**
+ * Reorder rows alphabetically or in the opprosite order
+ */
const reorderRows = () => {
setSortMethod(
sortMethod == "alphabetical" ? "-alphabetical" : "alphabetical"
@@ -259,7 +333,7 @@ export default function Dashboard() {
const deleteRow = (id) => {
setButtonReady(true);
- setData(data.filter((row) => row[0] !== id)); // filter by id
+ setData(data.filter((row) => row[0] !== id));
};
const modifyValue = (value, id) => {
@@ -286,6 +360,7 @@ export default function Dashboard() {
setButtonReady(true);
};
+ // For speed purposes and better perforamance, we are using useCallback
const listenChangeValue = useCallback((value, id) => {
modifyValue(value, id);
}, []);
@@ -298,14 +373,24 @@ export default function Dashboard() {
modifyVisibility(value, id);
}, []);
+ /**
+ * Save the changes of environment variables and push them to the database
+ */
const savePush = async () => {
+ // Format the new object with environment variables
let obj = Object.assign(
{},
...data.map((row) => ({ [row[2]]: [row[3], row[4]] }))
);
+
+ // Once "Save changed is clicked", disable that button
setButtonReady(false);
pushKeys(obj, router.query.id, env);
+ /**
+ * Check which integrations are active for this project and environment
+ * If there are any, update environment variables for those integrations
+ */
let integrations = await getWorkspaceIntegrations({
workspaceId: router.query.id,
});
@@ -325,6 +410,7 @@ export default function Dashboard() {
}
});
+ // If this user has never saved environment variables before, show them a prompt to read docs
if (!hasUserEverPushed) {
setCheckDocsPopUpVisible(true);
await registerUserAction({ action: "first_time_secrets_pushed" });
@@ -340,7 +426,7 @@ export default function Dashboard() {
setBlurred(!blurred);
};
- // This function downloads the secrets as an .env file
+ // This function downloads the secrets as a .env file
const download = () => {
const file = data
.map((item) => [item[2], item[3]].join("="))
@@ -357,21 +443,19 @@ export default function Dashboard() {
deleteRow(id);
};
+ /**
+ * This function copies the project id to the clipboard
+ */
function copyToClipboard() {
- // Get the text field
var copyText = document.getElementById("myInput");
- // Select the text field
copyText.select();
copyText.setSelectionRange(0, 99999); // For mobile devices
- // Copy the text inside the text field
navigator.clipboard.writeText(copyText.value);
setProjectIdCopied(true);
setTimeout(() => setProjectIdCopied(false), 2000);
- // Alert the copied text
- // alert("Copied the text: " + copyText.value);
}
return data ? (