Skip to content

Commit

Permalink
Fix default markdown, add set-version script, add basic linting rules (
Browse files Browse the repository at this point in the history
…#61)

Signed-off-by: Eamonn Mansour <[email protected]>
  • Loading branch information
eamansour authored Oct 2, 2024
1 parent ee5cf52 commit 3fedd8c
Show file tree
Hide file tree
Showing 33 changed files with 834 additions and 709 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

// Right now, the REST interface spec is always the same version as the galasa framework bundles.
def galasaFrameworkVersion = '0.37.0'
def galasaFrameworkVersion = "0.38.0"
def galasaOpenApiYamlVersion = galasaFrameworkVersion

repositories {
Expand Down
1 change: 1 addition & 0 deletions dockerfiles/dockerfile.webui
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN chown -R node:node /galasa
# Take advantage of Next.js' automatic file tracing to reduce image size
# See https://nextjs.org/docs/app/api-reference/next-config-js/output for information.
COPY --chown=node:node ./galasa-ui/.next/standalone ./
COPY --chown=node:node ./galasa-ui/public ./public
COPY --chown=node:node ./galasa-ui/.next/static ./.next/static

# Never run anything in a docker container as the root user if you can help it.
Expand Down
8 changes: 7 additions & 1 deletion galasa-ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"ignorePatterns": ["**/generated/*"],
"rules": {
"indent": ["error", 2],
"semi": "error",
"no-irregular-whitespace": "error"
}
}
20 changes: 10 additions & 10 deletions galasa-ui/src/app/auth/tokens/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AuthCookies from '@/utils/authCookies';
import { cookies } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server';
import { AuthenticationAPIApi, UsersAPIApi } from '@/generated/galasaapi';
import * as Constants from "@/utils/constants"
import * as Constants from "@/utils/constants";

// Stop this route from being pre-rendered
export const dynamic = 'force-dynamic';
Expand All @@ -23,7 +23,7 @@ interface TokenDetails {
export async function POST(request: NextRequest) {
// Call out to the API server's /auth/clients endpoint to create a new Dex client

const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration())
const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration());
const dexClient = await authApiClientWithAuthHeader.postClients();

const clientId = dexClient.clientId;
Expand All @@ -40,7 +40,7 @@ export async function POST(request: NextRequest) {
const response = NextResponse.json({ url: authResponse.headers.get('Location') ?? authResponse.url });
response.headers.set('Set-Cookie', authResponse.headers.get('Set-Cookie') ?? '');

cookies().set(AuthCookies.SHOULD_REDIRECT_TO_SETTINGS, 'true', {httpOnly: false})
cookies().set(AuthCookies.SHOULD_REDIRECT_TO_SETTINGS, 'true', {httpOnly: false});

return response;
} else {
Expand All @@ -51,19 +51,19 @@ export async function POST(request: NextRequest) {
export async function GET(request: NextRequest) {
// Call out to the API server's /auth/tokens endpoint to retrieve all tokens for a user

const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration())
const userApiClientWithAuthHeader = new UsersAPIApi(createAuthenticatedApiConfiguration())
const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration());
const userApiClientWithAuthHeader = new UsersAPIApi(createAuthenticatedApiConfiguration());

const response = await userApiClientWithAuthHeader.getUserByLoginId("me");

const loginId = response.length > 0 && response[0].loginId;

if (loginId) {

const tokens = await authApiClientWithAuthHeader.getTokens(Constants.CLIENT_API_VERSION, loginId)
const tokens = await authApiClientWithAuthHeader.getTokens(Constants.CLIENT_API_VERSION, loginId);

const serializedTokens = JSON.stringify(tokens.tokens);
return (new NextResponse(serializedTokens, {status: 200}))
return (new NextResponse(serializedTokens, {status: 200}));

} else {
return (new NextResponse("No login ID provided", {status : 400}));
Expand All @@ -79,10 +79,10 @@ export async function DELETE(request: NextRequest){
return new NextResponse('Token ID is required', { status: 400 });
}

const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration())
const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration());

await authApiClientWithAuthHeader.deleteToken(tokenId)
await authApiClientWithAuthHeader.deleteToken(tokenId);

return (new NextResponse(null, {status: 204}))
return (new NextResponse(null, {status: 204}));

}
22 changes: 11 additions & 11 deletions galasa-ui/src/app/home/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { ConfigurationPropertyStoreAPIApi } from "@/generated/galasaapi"
import { createAuthenticatedApiConfiguration } from "@/utils/api"
import { ConfigurationPropertyStoreAPIApi } from "@/generated/galasaapi";
import { createAuthenticatedApiConfiguration } from "@/utils/api";
import { NextResponse } from "next/server";

const NAMESPACE = "service"
const PROPERTY_NAME = "welcome.markdown"
const NAMESPACE = "service";
const PROPERTY_NAME = "welcome.markdown";

export async function GET() {

let data;
const cpsApiClientWithAuthHeader = new ConfigurationPropertyStoreAPIApi(createAuthenticatedApiConfiguration());
const response = await cpsApiClientWithAuthHeader.getCpsProperty(NAMESPACE, PROPERTY_NAME);
let data;
const cpsApiClientWithAuthHeader = new ConfigurationPropertyStoreAPIApi(createAuthenticatedApiConfiguration());
const response = await cpsApiClientWithAuthHeader.getCpsProperty(NAMESPACE, PROPERTY_NAME);

if (response.length > 0 && response[0]) {
data = response[0].data?.value;
}
if (response.length > 0 && response[0]) {
data = response[0].data?.value;
}

return (new NextResponse(data, { status: 200 }))
return new NextResponse(data, { status: 200 });

}
94 changes: 47 additions & 47 deletions galasa-ui/src/app/myprofile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,73 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
'use client'
'use client';

import { useEffect, useState } from "react";
import { Loading, ToastNotification } from "@carbon/react"
import styles from "../../styles/MyProfile.module.css"
import { Loading, ToastNotification } from "@carbon/react";
import styles from "../../styles/MyProfile.module.css";
import PageTile from "@/components/PageTile";

export default function MyProfilePage() {

const [isLoading, setIsLoading] = useState(false)
const [isError, setIsError] = useState(false)
const [loginId, setLoginId] = useState("")
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const [loginId, setLoginId] = useState("");

const handleFetchUserData = async () => {
const handleFetchUserData = async () => {

setIsLoading(true)
setIsLoading(true);

try {
const response = await fetch('/users', { method: 'GET' })
try {
const response = await fetch('/users', { method: 'GET' });

if (response.ok) {
if (response.ok) {

const data = await response.text();
setLoginId(data)
const data = await response.text();
setLoginId(data);

}

} catch (err) {
setIsError(true)
console.log(err);
}
finally {
setIsLoading(false)
}
}

} catch (err) {
setIsError(true);
console.log(err);
}
finally {
setIsLoading(false);
}

useEffect(() => {
};

handleFetchUserData()
useEffect(() => {

}, [])
handleFetchUserData();

return (
<div id="content" className={styles.content}>
<PageTile title={"My Profile"} />
}, []);

{isLoading ?
<Loading data-testid="loader" small={false} active={isLoading} />
:
<div className={styles.userNameContainer}>
<h4>Currently logged in as:</h4>
<h4> &nbsp; {loginId}</h4>
</div>
}
return (
<div id="content" className={styles.content}>
<PageTile title={"My Profile"} />

{isError &&
{isLoading ?
<Loading data-testid="loader" small={false} active={isLoading} />
:
<div className={styles.userNameContainer}>
<h4>Currently logged in as:</h4>
<h4> &nbsp; {loginId}</h4>
</div>
}

{isError &&
<ToastNotification
aria-label="closes notification"
kind="error"
onClose={function noRefCheck() { }}
onCloseButtonClick={function noRefCheck() { setIsError(false)}}
statusIconDescription="notification"
caption="Failed to fetch user profile data."
title="Internal Server Error"
aria-label="closes notification"
kind="error"
onClose={function noRefCheck() { }}
onCloseButtonClick={function noRefCheck() { setIsError(false);}}
statusIconDescription="notification"
caption="Failed to fetch user profile data."
title="Internal Server Error"
/>
}
</div>
);
}
</div>
);
};
26 changes: 13 additions & 13 deletions galasa-ui/src/app/users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ export const dynamic = 'force-dynamic';

export async function GET() {

try {
try {

const userApiClientWithAuthHeader = new UsersAPIApi(createAuthenticatedApiConfiguration())
const userApiClientWithAuthHeader = new UsersAPIApi(createAuthenticatedApiConfiguration());

const response = await userApiClientWithAuthHeader.getUserByLoginId("me")
const response = await userApiClientWithAuthHeader.getUserByLoginId("me");

return (new NextResponse(response[0].loginId, { status: 200 }))
} catch (err) {
throw new Error("Failed to get login id of user")
}
return (new NextResponse(response[0].loginId, { status: 200 }));
} catch (err) {
throw new Error("Failed to get login id of user");
}

}

export async function DELETE() {

// an api route is made because, cookies are server side props and cannot be access directly on components
// that use 'use client' keyword.
// an api route is made because, cookies are server side props and cannot be access directly on components
// that use 'use client' keyword.

cookies().delete(AuthCookies.ID_TOKEN)
cookies().delete(AuthCookies.SHOULD_REDIRECT_TO_SETTINGS)
cookies().delete(AuthCookies.ID_TOKEN);
cookies().delete(AuthCookies.SHOULD_REDIRECT_TO_SETTINGS);

return (new NextResponse(null, { status: 204 }))
return (new NextResponse(null, { status: 204 }));

}
}
Loading

0 comments on commit 3fedd8c

Please sign in to comment.