-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catalog: Replace S3 Select with GQL (#4218)
- Loading branch information
Showing
28 changed files
with
2,114 additions
and
1,385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as dateFns from 'date-fns' | ||
import * as Eff from 'effect' | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
|
||
import Sparkline from 'components/Sparkline' | ||
import * as GQL from 'utils/GraphQL' | ||
import log from 'utils/Logging' | ||
import * as SVG from 'utils/SVG' | ||
import { readableQuantity } from 'utils/string' | ||
|
||
import Section from '../Section' | ||
|
||
import ACCESS_COUNTS_QUERY from './gql/ObjectAccessCounts.generated' | ||
|
||
const currentYear = new Date().getFullYear() | ||
|
||
const formatDate = (date: Date) => | ||
dateFns.format(date, currentYear === date.getFullYear() ? 'd MMM' : 'd MMM yyyy') | ||
|
||
interface AnalyticsProps { | ||
bucket: string | ||
path: string | ||
} | ||
|
||
export default function Analytics({ bucket, path }: AnalyticsProps) { | ||
const [cursor, setCursor] = React.useState<number | null>(null) | ||
|
||
const result = GQL.useQuery(ACCESS_COUNTS_QUERY, { bucket, key: path }) | ||
|
||
const data = React.useMemo(() => { | ||
if (result.fetching) return Eff.Option.none() | ||
if (result.error) log.error('Error fetching object access counts:', result.error) | ||
return Eff.Option.some(Eff.Option.fromNullable(result.data?.objectAccessCounts)) | ||
}, [result.fetching, result.error, result.data]) | ||
|
||
const defaultExpanded = Eff.Option.match(data, { | ||
onNone: () => false, | ||
onSome: Eff.Option.match({ | ||
onNone: () => false, | ||
onSome: ({ total }) => !!total, | ||
}), | ||
}) | ||
|
||
return ( | ||
<Section icon="bar_charts" heading="Analytics" defaultExpanded={defaultExpanded}> | ||
{Eff.Option.match(data, { | ||
onNone: () => <M.CircularProgress />, | ||
onSome: Eff.Option.match({ | ||
onNone: () => <M.Typography>No analytics available</M.Typography>, | ||
onSome: ({ counts, total }) => | ||
total ? ( | ||
<M.Box | ||
display="flex" | ||
width="100%" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
> | ||
<M.Box> | ||
<M.Typography variant="h5">Downloads</M.Typography> | ||
<M.Typography variant="h4" component="div"> | ||
{readableQuantity(cursor === null ? total : counts[cursor].value)} | ||
</M.Typography> | ||
<M.Typography variant="overline" component="span"> | ||
{cursor === null | ||
? `${counts.length} days` | ||
: formatDate(counts[cursor].date)} | ||
</M.Typography> | ||
</M.Box> | ||
<M.Box width="calc(100% - 7rem)"> | ||
<Sparkline | ||
data={counts.map((c) => c.value)} | ||
onCursor={setCursor} | ||
width={1000} | ||
height={60} | ||
stroke={SVG.Paint.Server( | ||
<linearGradient x2="0" y2="100%" gradientUnits="userSpaceOnUse"> | ||
<stop offset="0" stopColor={M.colors.blueGrey[800]} /> | ||
<stop offset="100%" stopColor={M.colors.blueGrey[100]} /> | ||
</linearGradient>, | ||
)} | ||
/> | ||
</M.Box> | ||
</M.Box> | ||
) : ( | ||
<M.Typography>No analytics available</M.Typography> | ||
), | ||
}), | ||
})} | ||
</Section> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
catalog/app/containers/Bucket/File/gql/ObjectAccessCounts.generated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core' | ||
import * as Types from '../../../../model/graphql/types.generated' | ||
|
||
export type containers_Bucket_File_gql_ObjectAccessCountsQueryVariables = Types.Exact<{ | ||
bucket: Types.Scalars['String'] | ||
key: Types.Scalars['String'] | ||
}> | ||
|
||
export type containers_Bucket_File_gql_ObjectAccessCountsQuery = { | ||
readonly __typename: 'Query' | ||
} & { | ||
readonly objectAccessCounts: Types.Maybe< | ||
{ readonly __typename: 'AccessCounts' } & Pick<Types.AccessCounts, 'total'> & { | ||
readonly counts: ReadonlyArray< | ||
{ readonly __typename: 'AccessCountForDate' } & Pick< | ||
Types.AccessCountForDate, | ||
'date' | 'value' | ||
> | ||
> | ||
} | ||
> | ||
} | ||
|
||
export const containers_Bucket_File_gql_ObjectAccessCountsDocument = { | ||
kind: 'Document', | ||
definitions: [ | ||
{ | ||
kind: 'OperationDefinition', | ||
operation: 'query', | ||
name: { kind: 'Name', value: 'containers_Bucket_File_gql_ObjectAccessCounts' }, | ||
variableDefinitions: [ | ||
{ | ||
kind: 'VariableDefinition', | ||
variable: { kind: 'Variable', name: { kind: 'Name', value: 'bucket' } }, | ||
type: { | ||
kind: 'NonNullType', | ||
type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, | ||
}, | ||
}, | ||
{ | ||
kind: 'VariableDefinition', | ||
variable: { kind: 'Variable', name: { kind: 'Name', value: 'key' } }, | ||
type: { | ||
kind: 'NonNullType', | ||
type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, | ||
}, | ||
}, | ||
], | ||
selectionSet: { | ||
kind: 'SelectionSet', | ||
selections: [ | ||
{ | ||
kind: 'Field', | ||
name: { kind: 'Name', value: 'objectAccessCounts' }, | ||
arguments: [ | ||
{ | ||
kind: 'Argument', | ||
name: { kind: 'Name', value: 'bucket' }, | ||
value: { kind: 'Variable', name: { kind: 'Name', value: 'bucket' } }, | ||
}, | ||
{ | ||
kind: 'Argument', | ||
name: { kind: 'Name', value: 'key' }, | ||
value: { kind: 'Variable', name: { kind: 'Name', value: 'key' } }, | ||
}, | ||
{ | ||
kind: 'Argument', | ||
name: { kind: 'Name', value: 'window' }, | ||
value: { kind: 'IntValue', value: '365' }, | ||
}, | ||
], | ||
selectionSet: { | ||
kind: 'SelectionSet', | ||
selections: [ | ||
{ kind: 'Field', name: { kind: 'Name', value: 'total' } }, | ||
{ | ||
kind: 'Field', | ||
name: { kind: 'Name', value: 'counts' }, | ||
selectionSet: { | ||
kind: 'SelectionSet', | ||
selections: [ | ||
{ kind: 'Field', name: { kind: 'Name', value: 'date' } }, | ||
{ kind: 'Field', name: { kind: 'Name', value: 'value' } }, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
} as unknown as DocumentNode< | ||
containers_Bucket_File_gql_ObjectAccessCountsQuery, | ||
containers_Bucket_File_gql_ObjectAccessCountsQueryVariables | ||
> | ||
|
||
export { containers_Bucket_File_gql_ObjectAccessCountsDocument as default } |
9 changes: 9 additions & 0 deletions
9
catalog/app/containers/Bucket/File/gql/ObjectAccessCounts.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query ($bucket: String!, $key: String!) { | ||
objectAccessCounts(bucket: $bucket, key: $key, window: 365) { | ||
total | ||
counts { | ||
date | ||
value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './File' |
Oops, something went wrong.