diff --git a/src/app/domain/github/githubUserAuth/oauthCallback.ts b/src/app/domain/github/githubUserAuth/oauthCallback.ts index 3b3f6f6..21061bf 100644 --- a/src/app/domain/github/githubUserAuth/oauthCallback.ts +++ b/src/app/domain/github/githubUserAuth/oauthCallback.ts @@ -5,7 +5,8 @@ import { redirectResponseWithCookies } from '../../../inboundInterfaces/httpResp import { APIGatewayProxyResult } from 'aws-lambda/trigger/api-gateway-proxy' import { getUserByAuthToken } from '../githubUser' import { cookies } from './cicadaAuthCookies' -import { generatePageViewResultWithoutHtmx } from '../../../web/views/viewResultWrappers' +import { pageViewResultWithoutHtmx } from '../../../web/views/viewResultWrappers' +import { p } from '../../../web/hiccough/hiccoughElements' export async function oauthCallback( appState: AppState, @@ -64,7 +65,7 @@ async function tryOauthCallback( function failedToLoginResult(message: string): APIGatewayProxyResult { return { - ...generatePageViewResultWithoutHtmx(`
${message}
`), + ...pageViewResultWithoutHtmx([p(message)]), statusCode: 400 } } diff --git a/src/app/domain/github/setup/processGithubSetupRedirect.ts b/src/app/domain/github/setup/processGithubSetupRedirect.ts index a194248..84f6398 100644 --- a/src/app/domain/github/setup/processGithubSetupRedirect.ts +++ b/src/app/domain/github/setup/processGithubSetupRedirect.ts @@ -1,7 +1,7 @@ import { Route } from '../../../internalHttpRouter/internalHttpRoute' import { APIGatewayProxyEvent } from 'aws-lambda' import { GithubSetupAppState } from './githubSetupAppState' -import { generatePageViewResultWithoutHtmx } from '../../../web/views/viewResultWrappers' +import { pageViewResultWithoutHtmx } from '../../../web/views/viewResultWrappers' import { Octokit } from '@octokit/rest' import { ParameterType, PutParameterCommand, SSMClient } from '@aws-sdk/client-ssm' import { @@ -11,6 +11,7 @@ import { } from '../../../../multipleContexts/ssmParams' import { logger } from '../../../util/logging' import { fromRawAccountType, ORGANIZATION_ACCOUNT_TYPE } from '../../types/githubCommonTypes' +import { a, p } from '../../../web/hiccough/hiccoughElements' export const setupRedirectRoute: Route-Github app ${appDetails.appName} has been successsfully created. -You now need to install it in GitHub here. -Once you've installed the GitHub app Cicada will start loading your GitHub data - this can take a minute or more. -
`, + return pageViewResultWithoutHtmx( + [ + p( + `Github app ${appDetails.appName} has been successsfully created. You now need to install it in GitHub `, + a(installationsPath, 'here'), + `Once you've installed the GitHub app Cicada will start loading your GitHub data - this can take a minute or more` + ) + ], false ) } @@ -125,17 +128,17 @@ async function writeSSMParameter( ) } -const noCodeResponse = generatePageViewResultWithoutHtmx( - `Unexpected redirect from GitHub - no code on URL
`, +const noCodeResponse = pageViewResultWithoutHtmx( + [p('Unexpected redirect from GitHub - no code on URL')], false ) -const noStateResponse = generatePageViewResultWithoutHtmx( - `Unexpected redirect from GitHub - no state on URL
`, +const noStateResponse = pageViewResultWithoutHtmx( + [p('Unexpected redirect from GitHub - no state on URL')], false ) -const invalidStateResponse = generatePageViewResultWithoutHtmx( - `Unexpected redirect from GitHub - invalid state on URL
`, +const invalidStateResponse = pageViewResultWithoutHtmx( + [p('Unexpected redirect from GitHub - invalid state on URL')], false ) diff --git a/src/app/domain/github/setup/startGithubSetup.ts b/src/app/domain/github/setup/startGithubSetup.ts index 50a819b..98ecd8c 100644 --- a/src/app/domain/github/setup/startGithubSetup.ts +++ b/src/app/domain/github/setup/startGithubSetup.ts @@ -1,5 +1,5 @@ import { GithubSetupAppState } from './githubSetupAppState' -import { generatePageViewResultWithoutHtmx } from '../../../web/views/viewResultWrappers' +import { pageViewResultWithoutHtmx } from '../../../web/views/viewResultWrappers' import { APIGatewayProxyEvent } from 'aws-lambda' import { Route } from '../../../internalHttpRouter/internalHttpRoute' @@ -49,8 +49,8 @@ GitHub Account. If you're not sure then the official GitHub docs ` - return generatePageViewResultWithoutHtmx(bodyContents, false) + return pageViewResultWithoutHtmx([bodyContents], false) } diff --git a/src/app/lambdaFunctions/authenticatedWeb/lambda.ts b/src/app/lambdaFunctions/authenticatedWeb/lambda.ts index 5937b30..b11f2d0 100644 --- a/src/app/lambdaFunctions/authenticatedWeb/lambda.ts +++ b/src/app/lambdaFunctions/authenticatedWeb/lambda.ts @@ -13,9 +13,10 @@ import { logoutResponse } from '../../domain/github/githubUserAuth/githubWebAuth import { authorizeUserRequest } from '../../domain/webAuth/userAuthorizer' import { notAuthorizedHTMLResponse } from '../../inboundInterfaces/standardHttpResponses' import { logger } from '../../util/logging' -import { generateFragmentViewResult } from '../../web/views/viewResultWrappers' +import { fragmentViewResult } from '../../web/views/viewResultWrappers' import { startSetupRoute } from '../../domain/github/setup/startGithubSetup' import { isFailure } from '../../util/structuredResult' +import { a, p } from '../../web/hiccough/hiccoughElements' const router = createRouter([showHelloRoute, showLatestActivityRoute, showRepoRoute, showWorkflowRoute]) @@ -35,9 +36,9 @@ export const baseHandler: CicadaAPIAuthorizedAPIHandler = async (event: APIGatew return await handleWebRequest(appState, event) } -export const setupRequiredResponse = generateFragmentViewResult(`-Cicada GitHub app not ready yet. Go here to start the setup process. -
`) +export const setupRequiredResponse = fragmentViewResult( + p('Cicada GitHub app not ready yet.', a(startSetupRoute.path, 'Go here to start the setup process')) +) // TOEventually - top level error handler export async function handleWebRequest(appState: AppState, event: APIGatewayProxyEvent) { diff --git a/src/app/lambdaFunctions/githubAuth/lambda.ts b/src/app/lambdaFunctions/githubAuth/lambda.ts index 928c1ca..59267b1 100644 --- a/src/app/lambdaFunctions/githubAuth/lambda.ts +++ b/src/app/lambdaFunctions/githubAuth/lambda.ts @@ -6,7 +6,7 @@ import { powertoolsMiddlewares } from '../../middleware/standardMiddleware' import { handleGitHubWebAuthRequest } from '../../domain/github/githubUserAuth/githubWebAuthHandler' import { logger } from '../../util/logging' import { isFailure } from '../../util/structuredResult' -import { generatePageViewResultWithoutHtmx } from '../../web/views/viewResultWrappers' +import { pageViewResultWithoutHtmx } from '../../web/views/viewResultWrappers' import { startSetupRoute } from '../../domain/github/setup/startGithubSetup' let appState: AppState @@ -24,10 +24,13 @@ export const baseHandler: APIGatewayProxyHandler = async (event) => { return await handleGitHubWebAuthRequest(appState, event) } -export const setupRequiredResponse = generatePageViewResultWithoutHtmx( - `+export const setupRequiredResponse = pageViewResultWithoutHtmx( + // TODO - use hiccough elements + [ + `
Cicada GitHub app not ready yet. Go here to start the setup process. -
`, +` + ], false ) diff --git a/src/app/lambdaFunctions/githubSetup/lambda.ts b/src/app/lambdaFunctions/githubSetup/lambda.ts index 6cb91dc..cf85c71 100644 --- a/src/app/lambdaFunctions/githubSetup/lambda.ts +++ b/src/app/lambdaFunctions/githubSetup/lambda.ts @@ -4,7 +4,8 @@ import { powertoolsMiddlewares } from '../../middleware/standardMiddleware' import { handleGithubSetupRequest } from '../../domain/github/setup/appSetupHandler' import { GithubSetupAppState, githubSetupStartup } from '../../domain/github/setup/githubSetupAppState' import { githubAppIsReady } from '../../domain/github/setup/githubAppReadyCheck' -import { generatePageViewResultWithoutHtmx } from '../../web/views/viewResultWrappers' +import { pageViewResultWithoutHtmx } from '../../web/views/viewResultWrappers' +import { p } from '../../web/hiccough/hiccoughElements' let appState: GithubSetupAppState @@ -18,9 +19,7 @@ export const baseHandler: APIGatewayProxyHandler = async (event) => { return await handleGithubSetupRequest(appState, event) } -const setupAlreadyCompleteResponse = generatePageViewResultWithoutHtmx(`-Cicada is already configured. -
`) +const setupAlreadyCompleteResponse = pageViewResultWithoutHtmx([p('Cicada is already configured.')], false) // Entry point - usage is defined by CDK // noinspection JSUnusedGlobalSymbols diff --git a/src/app/util/types.ts b/src/app/util/types.ts new file mode 100644 index 0000000..3561729 --- /dev/null +++ b/src/app/util/types.ts @@ -0,0 +1,2 @@ +export type OptionalHello ${event.username} / ${event.userId}
`) + return pageViewResultWithoutHtmx([p('Hello ', event.username, ' / ', `${event.userId}`)]) } diff --git a/src/app/web/views/pageElements.ts b/src/app/web/views/pageElements.ts index a38afe7..fb17f10 100644 --- a/src/app/web/views/pageElements.ts +++ b/src/app/web/views/pageElements.ts @@ -3,6 +3,8 @@ import { GithubPush } from '../../domain/types/GithubPush' import { Clock, displayDateTime } from '../../util/dateAndTime' import { GithubRepositoryElement } from '../../domain/types/GithubRepositoryElement' import { latestCommitInPush } from '../../domain/github/githubPush' +import { a, td, tr } from '../hiccough/hiccoughElements' +import { inlineChildren, withOptions } from '../hiccough/hiccoughElement' export function workflowRow( clock: Clock, @@ -15,20 +17,20 @@ export function workflowRow( showWorkflowCell: boolean } = { showRepoCell: true, showWorkflowCell: true } ) { - return `Repo | Workflow | Status | When | By | Commit |
---|
Repo | Branch | When | By | Commit |
---|
Workflow | Status | When | By | Commit |
---|
Type | Activity | When | By | Commit |
---|
No activity found. If this is a new workflow make sure it runs first before trying to view here -`) - } + const structure = + runs.length === 0 + ? [p('No activity found. If this is a new workflow make sure it runs first before trying to view here')] + : [ + h3(`Runs for workflow ${runs[0].workflowName} in ${runs[0].ownerName}/${runs[0].repoName}`), + // TOEventually - when we have in-progress runs only show them if no corresponding completed event + table( + { class: 'table' }, + thead(tr(...['Result', 'When', 'By', 'Commit'].map((x) => th(x)))), + tbody( + ...runs.map((run) => workflowRow(clock, run, { showRepoCell: false, showWorkflowCell: false })) + ) + ) + ] - // TOEventually - when we have in-progress runs only show them if no corresponding completed event - return generatePageViewResultWithoutHtmx(` -
Result | When | By | Commit |
---|
Unable to login because there was no code on request
-Unable to login because there was no code on request
++ Manage Web Push Notifications +
++ Back to home +
++ Logout +
+Repo | Workflow | Status | When | By | Commit |
---|---|---|---|---|---|
org-test-repo-one | -Test Repo One Workflow | -Success | -2024-03-06T19:25:42Z | -mikebroberts | -Test Repo One Workflow | -
Repo | Branch | When | By | Commit |
---|---|---|---|---|
org-test-repo-one | -main | -2024-03-06T17:00:40Z | -mikebroberts | -test workflow | -
Repo | +Workflow | +Status | +When | +By | +Commit | +
---|---|---|---|---|---|
org-test-repo-one | +Test Repo One Workflow | +Success | +2024-03-06T19:25:42Z | +mikebroberts | +Test Repo One Workflow | +
Repo | +Branch | +When | +By | +Commit | +
---|---|---|---|---|
org-test-repo-one | +main | +2024-03-06T17:00:40Z | +mikebroberts | +test workflow | +
Workflow | Status | When | By | Commit |
---|
Type | Activity | When | By | Commit |
---|---|---|---|---|
Successful Run | -Test Repo One Workflow | -2024-03-06T19:25:42Z | -mikebroberts | -Test Repo One Workflow | -
Workflow | +Status | +When | +By | +Commit | +
---|
Type | +Activity | +When | +By | +Commit | +
---|---|---|---|---|
Successful Run | +Test Repo One Workflow | +2024-03-06T19:25:42Z | +mikebroberts | +Test Repo One Workflow | +
+ Manage Web Push Notifications +
++ Back to home +
++ Logout +
+a | +b | +c | +
a | b |
a | b | c |
Hello
World
Hello
World
HelloWorld
`) + + expect(html([p('Hello'), p('World')])).toEqual(`Hello
World
`) +}) + +test('hiccough with options', () => { + const indentAndNewLine = { + eachIndent: ' ', + newLines: true + } + + expect(html(element('span', { class: 'foo' }, 'bar'), indentAndNewLine)).toEqual( + `bar` + ) + + expect(html(div({ class: 'foo' }, p('Hello'), p('World')), indentAndNewLine)).toEqual(`Hello
+World
++Hello +World +Again +
`) + + expect(html(table(tr(td('a'), td('b'))), indentAndNewLine)).toEqual(`a | +b | +
a | +b | +
a | b |
+Hello +testuser + / +1234 +
++ Manage Web Push Notifications +
++ Back to home +
++ Logout +
+