Skip to content

Commit

Permalink
fmt / lint
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed May 6, 2023
1 parent bcf4da0 commit 7ba2048
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 89 deletions.
10 changes: 7 additions & 3 deletions dashboard/src/components/AppNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const AppNavContainer = styled('div', {
display: 'flex',
flexDirection: 'row',
gap: '20px',
}
},
})

export interface AppNavProps {
Expand All @@ -56,10 +56,14 @@ export const AppNav = (props: AppNavProps): JSXElement => {
</AppTitleContainer>
<AppNavContainer>
<A href={`/apps/${props.appID}`}>
<Button color='black1' size='large'>General</Button>
<Button color='black1' size='large'>
General
</Button>
</A>
<A href={`/apps/${props.appID}/builds`}>
<Button color='black1' size='large'>Builds</Button>
<Button color='black1' size='large'>
Builds
</Button>
</A>
</AppNavContainer>
</>
Expand Down
4 changes: 1 addition & 3 deletions dashboard/src/components/BuildStatusIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ interface Props {
}

export const BuildStatusIcon = (props: Props): JSXElement => {
return (
<Dynamic component={components[props.state]} size={props.size ?? 20} />
)
return <Dynamic component={components[props.state]} size={props.size ?? 20} />
}
6 changes: 3 additions & 3 deletions dashboard/src/components/Log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export const LogContainer = styled('div', {
scroll: {
whiteSpace: 'nowrap',
overflowX: 'scroll',
}
}
},
},
},
defaultVariants: {
overflowX: 'wrap',
}
},
})
37 changes: 20 additions & 17 deletions dashboard/src/components/RepositoryRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,26 @@ export const RepositoryRow = ({ repo, apps }: Props): JSXElement => {
<div>Add&nbsp;branch</div>
</AddBranchButton>
</Header>
<For each={apps} children={(app, i) => (
<A href={`/apps/${app.id}`}>
<ApplicationContainer upperBorder={i() === apps.length - 1 ? 'none' : 'line'}>
<StatusIcon state={applicationState(app)} />
<AppDetail>
<AppName>{app.name}</AppName>
<AppFooter>
<div>{shortSha(app.currentCommit)}</div>
<AppFooterRight>
<div>{app.websites[0]?.fqdn || ''}</div>
<DiffHuman target={app.updatedAt.toDate()} />
</AppFooterRight>
</AppFooter>
</AppDetail>
</ApplicationContainer>
</A>
)} />
<For
each={apps}
children={(app, i) => (
<A href={`/apps/${app.id}`}>
<ApplicationContainer upperBorder={i() === apps.length - 1 ? 'none' : 'line'}>
<StatusIcon state={applicationState(app)} />
<AppDetail>
<AppName>{app.name}</AppName>
<AppFooter>
<div>{shortSha(app.currentCommit)}</div>
<AppFooterRight>
<div>{app.websites[0]?.fqdn || ''}</div>
<DiffHuman target={app.updatedAt.toDate()} />
</AppFooterRight>
</AppFooter>
</AppDetail>
</ApplicationContainer>
</A>
)}
/>
</Container>
)
}
4 changes: 1 addition & 3 deletions dashboard/src/components/StatusIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ interface Props {
}

export const StatusIcon = (props: Props): JSXElement => {
return (
<Dynamic component={components[props.state]} size={props.size ?? 20} />
)
return <Dynamic component={components[props.state]} size={props.size ?? 20} />
}
21 changes: 11 additions & 10 deletions dashboard/src/libs/buffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ export const concatBuffers = (a: Uint8Array, b: Uint8Array): Uint8Array => {
const utf8Decoder = new TextDecoder('utf-8')
const ansiDecoder = new Convert()

const escapeHTML = (s: string): string => s.replace(/[&'`"<>]/g, function (match) {
return {
'&': '&amp;',
'\'': '&#x27;',
'`': '&#x60;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;',
}[match]
})
const escapeHTML = (s: string): string =>
s.replace(/[&'`"<>]/g, function (match) {
return {
'&': '&amp;',
"'": '&#x27;',
'`': '&#x60;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;',
}[match]
})

export const toUTF8WithAnsi = (arr: Uint8Array): string => {
const rawStr = utf8Decoder.decode(arr.buffer)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/libs/sleep.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
7 changes: 4 additions & 3 deletions dashboard/src/pages/apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ export default () => {
</Button>
</SearchBarContainer>
<RepositoriesContainer>
<For each={repos().repositories} children={(r) => (
<RepositoryRow repo={r} apps={appsByRepo()[r.id] || []} />
)} />
<For
each={repos().repositories}
children={(r) => <RepositoryRow repo={r} apps={appsByRepo()[r.id] || []} />}
/>
</RepositoriesContainer>
</MainContainer>
</ContentContainer>
Expand Down
30 changes: 16 additions & 14 deletions dashboard/src/pages/apps/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default () => {
() => app()?.deployType === DeployType.RUNTIME && app()?.id,
(id) => client.getOutput({ applicationId: id, before: Timestamp.fromDate(now) }),
)
const reversedLog = createMemo(() => log() && [...log().outputs].reverse() as ApplicationOutput[])
const reversedLog = createMemo(() => log() && ([...log().outputs].reverse() as ApplicationOutput[]))
const [logStream] = createResource(
() => app()?.container === Application_ContainerState.RUNNING && app()?.id,
(id) => client.getOutputStream({ applicationId: id, after: Timestamp.fromDate(now) }),
Expand All @@ -139,7 +139,7 @@ export default () => {

const iterate = async () => {
for await (const log of stream) {
setStreamedLog(prev => prev.concat(log.log))
setStreamedLog((prev) => prev.concat(log.log))
}
await sleep(1000)
await refetchApp()
Expand Down Expand Up @@ -217,11 +217,14 @@ export default () => {
</CardItem>
<CardItem>
<CardItemTitle>
<For each={app().websites} children={(website) => (
<URLText href={getWebsiteURL(website)} target='_blank' rel="noreferrer">
{getWebsiteURL(website)}
</URLText>
)} />
<For
each={app().websites}
children={(website) => (
<URLText href={getWebsiteURL(website)} target='_blank' rel="noreferrer">
{getWebsiteURL(website)}
</URLText>
)}
/>
</CardItemTitle>
</CardItem>
</Show>
Expand Down Expand Up @@ -284,7 +287,8 @@ export default () => {
<CardItem>
<CardItemTitle>Build Type</CardItemTitle>
<CardItemContent>{buildTypeStr[app().config.buildConfig.buildConfig.case]}</CardItemContent>
</CardItem>A
</CardItem>
A
<BuildConfigInfo config={app().config.buildConfig} />
<Show when={app().config.entrypoint}>
<CardItem>
Expand All @@ -304,12 +308,10 @@ export default () => {
<Card>
<CardTitle>Container Log</CardTitle>
<LogContainer ref={logRef} overflowX='scroll'>
<For each={reversedLog()} children={(l) => (
<span>{l.log}</span>
)} />
<For each={streamedLog()} children={(line) => (
<span>{line}</span>
)} />
{/* rome-ignore lint: Avoid passing children using a prop */}
<For each={reversedLog()} children={(l) => <span>{l.log}</span>} />
{/* rome-ignore lint: Avoid passing children using a prop */}
<For each={streamedLog()} children={(line) => <span>{line}</span>} />
</LogContainer>
</Card>
</Show>
Expand Down
57 changes: 32 additions & 25 deletions dashboard/src/pages/apps/[id]/builds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const BuildsContainer = styled('div', {
marginTop: '24px',
borderRadius: '4px',
border: `1px solid ${vars.bg.white4}`,
}
},
})

const BuildContainer = styled('div', {
Expand Down Expand Up @@ -92,37 +92,44 @@ export default () => {
)
const loaded = () => !!(app() && repo() && builds())

const sortedBuilds = createMemo(() => builds() && [...builds().builds].sort((b1, b2) => {
if (!b1.startedAt.valid) return -1
if (!b2.startedAt.valid) return 1
return b2.startedAt.timestamp.toDate().getTime() - b1.startedAt.timestamp.toDate().getTime()
}))
const sortedBuilds = createMemo(
() =>
builds() &&
[...builds().builds].sort((b1, b2) => {
if (!b1.startedAt.valid) return -1
if (!b2.startedAt.valid) return 1
return b2.startedAt.timestamp.toDate().getTime() - b1.startedAt.timestamp.toDate().getTime()
}),
)

return (
<Container>
<Header />
<Show when={loaded()}>
<AppNav repoName={repo().name} appName={app().name} appID={app().id} />
<BuildsContainer>
<For each={sortedBuilds()} children={(b, i) => (
<A href={`/apps/${app().id}/builds/${b.id}`}>
<BuildContainer upperBorder={i() > 0 && i() < sortedBuilds().length-1 ? 'line' : 'none'}>
<BuildStatusIcon state={b.status} />
<BuildDetail>
<BuildName>Build {b.id}</BuildName>
<BuildFooter>
<div>{shortSha(b.commit)}</div>
<BuildFooterRight>
{/* TODO: use queued_at */}
<Show when={b.startedAt.valid}>
<DiffHuman target={b.startedAt.timestamp.toDate()} />
</Show>
</BuildFooterRight>
</BuildFooter>
</BuildDetail>
</BuildContainer>
</A>
)} />
<For
each={sortedBuilds()}
children={(b, i) => (
<A href={`/apps/${app().id}/builds/${b.id}`}>
<BuildContainer upperBorder={i() > 0 && i() < sortedBuilds().length - 1 ? 'line' : 'none'}>
<BuildStatusIcon state={b.status} />
<BuildDetail>
<BuildName>Build {b.id}</BuildName>
<BuildFooter>
<div>{shortSha(b.commit)}</div>
<BuildFooterRight>
{/* TODO: use queued_at */}
<Show when={b.startedAt.valid}>
<DiffHuman target={b.startedAt.timestamp.toDate()} />
</Show>
</BuildFooterRight>
</BuildFooter>
</BuildDetail>
</BuildContainer>
</A>
)}
/>
</BuildsContainer>
</Show>
</Container>
Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/pages/apps/[id]/builds/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default () => {

const iterate = async () => {
for await (const log of stream) {
setStreamedLog(prev => concatBuffers(prev, log.log))
setStreamedLog((prev) => concatBuffers(prev, log.log))
}
await sleep(1000)
await refetchBuild() // refetch build on stream end
Expand Down Expand Up @@ -122,31 +122,31 @@ export default () => {
<CardItemTitle>Started at</CardItemTitle>
<CardItemContent>
<Show when={build().startedAt.valid} fallback={'-'}>
<DiffHuman target={build().startedAt.timestamp.toDate()}></DiffHuman>
<DiffHuman target={build().startedAt.timestamp.toDate()} />
</Show>
</CardItemContent>
</CardItem>
<CardItem>
<CardItemTitle>Finished at</CardItemTitle>
<CardItemContent>
<Show when={build().finishedAt.valid} fallback={'-'}>
<DiffHuman target={build().finishedAt.timestamp.toDate()}></DiffHuman>
<DiffHuman target={build().finishedAt.timestamp.toDate()} />
</Show>
</CardItemContent>
</CardItem>
<CardItem>
<CardItemTitle>Duration</CardItemTitle>
<CardItemContent>
<Show when={build().startedAt.valid && build().finishedAt.valid} fallback={'-'}>
{durationHuman(build().finishedAt.timestamp.toDate().getTime() - build().startedAt.timestamp.toDate().getTime())}
{durationHuman(
build().finishedAt.timestamp.toDate().getTime() - build().startedAt.timestamp.toDate().getTime(),
)}
</Show>
</CardItemContent>
</CardItem>
<CardItem>
<CardItemTitle>Retried</CardItemTitle>
<CardItemContent>
{build().retriable ? 'Yes' : 'No'}
</CardItemContent>
<CardItemContent>{build().retriable ? 'Yes' : 'No'}</CardItemContent>
</CardItem>
</CardItems>
</Card>
Expand Down
2 changes: 2 additions & 0 deletions pkg/usecase/api_app_config_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/friendsofgo/errors"
log "github.com/sirupsen/logrus"

"github.com/traPtitech/neoshowcase/pkg/domain"
"github.com/traPtitech/neoshowcase/pkg/util/optional"
Expand Down Expand Up @@ -63,6 +64,7 @@ func (s *APIServerService) GetOutputStream(ctx context.Context, id string, after
return errors.Wrap(err, "failed to send log")
}
case <-ctx.Done():
log.Infof("closing output stream")
return nil
}
}
Expand Down

0 comments on commit 7ba2048

Please sign in to comment.