Skip to content

Commit

Permalink
Merge pull request #131 from kthcloud/beta
Browse files Browse the repository at this point in the history
Upgrade team page and logs view
  • Loading branch information
pierrelefevre authored Dec 14, 2023
2 parents f8a0029 + 83555b9 commit 055554a
Show file tree
Hide file tree
Showing 12 changed files with 839 additions and 288 deletions.
4 changes: 2 additions & 2 deletions src/api/deploy/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const getDeployment = async (token, id) => {
};

export const getDeployments = async (token, all = false) => {
const allQuery = all ? "?all=true" : "";
const url = `${process.env.REACT_APP_DEPLOY_API_URL}/deployments${allQuery}`;
const allQuery = all ? "&all=true" : "";
const url = `${process.env.REACT_APP_DEPLOY_API_URL}/deployments?shared=true${allQuery}`;
const res = await fetch(url, {
method: "GET",
headers: {
Expand Down
36 changes: 35 additions & 1 deletion src/api/deploy/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export const createTeam = async (token, name, description) => {
}
throw res;
}

return await res.json();
};

export const deleteTeam = async (token, teamId) => {
Expand All @@ -74,11 +76,43 @@ export const addMembers = async (token, teamId, members) => {
const url = `${process.env.REACT_APP_DEPLOY_API_URL}/teams/${teamId}`;
const body = { members: members };

await fetch(url, {
let res = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(body),
});

if (!res.ok) {
const body = await res.json();
if (body) {
throw body;
}
throw res;
}

return await res.json();
};

export const updateTeam = async (token, teamId, body) => {
const url = `${process.env.REACT_APP_DEPLOY_API_URL}/teams/${teamId}`;

let res = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
},
body: JSON.stringify(body),
});

if (!res.ok) {
const body = await res.json();
if (body) {
throw body;
}
throw res;
}

return await res.json();
};
4 changes: 2 additions & 2 deletions src/api/deploy/vms.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getVM = async (token, id) => {
};

export const getVMs = async (token, all = false) => {
const allQuery = all ? "?all=true" : "";
const url = `${process.env.REACT_APP_DEPLOY_API_URL}/vms${allQuery}`;
const allQuery = all ? "&all=true" : "";
const url = `${process.env.REACT_APP_DEPLOY_API_URL}/vms?shared=true${allQuery}`;
const response = await fetch(url, {
method: "GET",
headers: {
Expand Down
7 changes: 3 additions & 4 deletions src/components/Gravatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const Gravatar = ({ user, fallback, ...props }) => {
const uri = encodeURI(`https://www.gravatar.com/avatar/${hash}?d=404`);

const response = await fetch(uri);
console.log(response);
if (response.ok) {
return uri;
}
Expand All @@ -27,11 +26,9 @@ const Gravatar = ({ user, fallback, ...props }) => {
const gravatarUri = await gravatar();
setHasFetched(true);
if (gravatarUri) {
console.log("found gravatar: " + gravatarUri + " for user " + user.email);
setUserAvatar(gravatarUri);
return;
}
console.log("no gravatar found for user " + user.email);
};

useEffect(() => {
Expand All @@ -42,7 +39,9 @@ const Gravatar = ({ user, fallback, ...props }) => {

return (
<Avatar sx={{ width: 20, height: 20 }} src={userAvatar} {...props}>
{!userAvatar && fallback ? fallback : (user.email || user.username)[0].toUpperCase()}
{!userAvatar && fallback
? fallback
: (user.email || user.username)[0].toUpperCase()}
</Avatar>
);
};
Expand Down
33 changes: 32 additions & 1 deletion src/contexts/ResourceContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ export const ResourceContextProvider = ({ children }) => {
}
};

const getTeamResourceIds = () => {
if (!teams) return;

let resourceIds = [];

teams.forEach((t) => {
if (t.resources) {
t.resources.forEach((r) => {
if (!resourceIds.includes(r.id)) {
resourceIds.push(r.id);
}
});
}
});

return resourceIds;
};

const queueJob = (job) => {
console.log("Queuing job", JSON.stringify(job));
if (!job) return;
Expand All @@ -106,7 +124,20 @@ export const ResourceContextProvider = ({ children }) => {

setRows(array);

setUserRows(array.filter((row) => row.ownerId === user.id));
let userOwned = array.filter((row) => row.ownerId === user.id);

let teamResourceIds = getTeamResourceIds();
teamResourceIds.forEach((resourceId) => {
let sharedRow = array.find((row) => row.id === resourceId);

sharedRow.shared = true;

if (sharedRow && !userOwned.includes(sharedRow)) {
userOwned.push(sharedRow);
}
});

setUserRows(userOwned);
};

const loadZones = async () => {
Expand Down
21 changes: 19 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@
"menu-manage-account": "Manage account",
"teams": "Teams",
"current-teams": "Current teams",
"teams-subheader": "Teams are a way to organize your resources and collaborate with others. You can create a team and invite others to join.",
"teams-subheader-1": "Teams are a way to organize your resources and collaborate with others. You can create a team and invite others to join.",
"teams-subheader-2": "Share resources by going to the resource's page and clicking share with team.",
"create-team": "Create team",
"description": "Description",
"invite": "Invite",
Expand All @@ -402,6 +403,22 @@
"replicas-saving": "Saving replicas...",
"could-not-save-replicas": "Could not save replicas: ",
"replicas-shutdown-warning": "This will shut down your deployment. Are you sure?",
"members": "Members"
"members": "Members",
"share-with-team-description": "Share with team",
"share-with-team-action": "share with team",
"search-for-teams": "Search for teams",
"share": "share",
"with": "with",
"transferred-successfully": "Successfully transferred",
"successfully-added-to-team": "Successfully added to team",
"resources": "Resources",
"resource": "Resource",
"remove": "Remove",
"from-team": "from team",
"resource-not-found": "Resource not found",
"shared": "Shared",
"shared-in-group": "Resource is available through a group you are a member of",
"auto-scroll": "Auto scroll",
"logs-truncated": "Over 1000 logs: Logs truncated. Please download the full log file to view earlier logs."
}
}
21 changes: 19 additions & 2 deletions src/locales/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@
"menu-manage-account": "Hantera konto",
"teams": "Grupper",
"current-teams": "Dina grupper",
"teams-subheader": "Grupper är ett sätt att organisera dina resurser och samarbeta med andra. Du kan skapa en grupp och bjuda in andra.",
"teams-subheader-1": "Grupper är ett sätt att organisera dina resurser och samarbeta med andra. Du kan skapa en grupp och bjuda in andra.",
"teams-subheader-2": "Dela resurser med gruppen genom att besöka resursens sida och klicka på dela med grupp",
"create-team": "Skapa grupp",
"description": "Beskrivning",
"invite": "Bjud in",
Expand All @@ -402,6 +403,22 @@
"replicas-saving": "Sparar antal kopior...",
"could-not-save-replicas": "Kunde inte uppdatera antal kopior: ",
"replicas-shutdown-warning": "Varning: Om du väljer 0 kopior kommer appen att stängas av.",
"members": "Medlemmar"
"members": "Medlemmar",
"share-with-team-description": "Dela med grupp",
"share-with-team-action": "dela med grupp",
"search-for-teams": "Sök grupper",
"share": "dela",
"with": "med",
"transferred-successfully": "Överföringen lyckades",
"successfully-added-to-team": "Delad med grupp",
"resources": "Resurser",
"resource": "Resurs",
"remove": "Ta bort",
"from-team": "från grupp",
"resource-not-found": "Resursen hittades inte",
"shared": "Delad",
"shared-in-group": "Resursen är tillgänglig genom en av grupperna du är medlem i",
"auto-scroll": "Auto scroll",
"logs-truncated": "Över 1000 loggar: Loggar avkortade. Ladda ner hela loggen för att se tidigare loggar."
}
}
17 changes: 17 additions & 0 deletions src/pages/deploy/Deploy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,22 @@ export function Deploy() {
);
};

const renderShared = (row) => {
if (!row.shared) return <></>;

return (
<Label
variant="ghost"
style={{ fontFamily: "monospace" }}
startIcon={<Iconify icon="mdi:account-group" sx={{ opacity: 0.65 }} />}
>
<Tooltip title={t("shared-in-group")}>
<span>{t("shared")}</span>
</Tooltip>
</Label>
);
};

useEffect(() => {
if (user && !user.onboarded) {
navigate("/onboarding");
Expand Down Expand Up @@ -455,6 +471,7 @@ export function Deploy() {
{renderResourceStatus(row)}
{renderStatusCode(row)}
{renderZone(row)}
{renderShared(row)}
</Stack>
</TableCell>

Expand Down
Loading

0 comments on commit 055554a

Please sign in to comment.