Skip to content

Commit

Permalink
Merge pull request #3 from edenia/perf/ui
Browse files Browse the repository at this point in the history
Perf/UI
  • Loading branch information
kuronosec committed Sep 29, 2023
2 parents 1b1d864 + bef4ac3 commit 7172ee5
Show file tree
Hide file tree
Showing 16 changed files with 1,055 additions and 914 deletions.
5 changes: 4 additions & 1 deletion hasura/metadata/databases/default/tables/public_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ select_permissions:
- role: guest
permission:
columns:
- status
- auth
- created_at
- session_id
- status
- updated_at
filter: {}
allow_aggregations: true
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."request" add column "created_at" timestamptz
-- null default now();
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."request" add column "created_at" timestamptz
null default now();
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."request" add column "updated_at" timestamptz
-- null default now();
--
-- CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
-- RETURNS TRIGGER AS $$
-- DECLARE
-- _new record;
-- BEGIN
-- _new := NEW;
-- _new."updated_at" = NOW();
-- RETURN _new;
-- END;
-- $$ LANGUAGE plpgsql;
-- CREATE TRIGGER "set_public_request_updated_at"
-- BEFORE UPDATE ON "public"."request"
-- FOR EACH ROW
-- EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
-- COMMENT ON TRIGGER "set_public_request_updated_at" ON "public"."request"
-- IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
alter table "public"."request" add column "updated_at" timestamptz
null default now();

CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_request_updated_at"
BEFORE UPDATE ON "public"."request"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_request_updated_at" ON "public"."request"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
42 changes: 26 additions & 16 deletions webapp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
FROM node:current-alpine as build-stage
# ---------- Base ----------
FROM node:18.18.0-alpine3.18 as base
WORKDIR /usr/src/app

# ---------- Builder ----------
FROM base AS builder

RUN apk add --no-cache git

COPY package.json .
COPY yarn*.lock .

RUN yarn --frozen-lockfile --production

COPY . .

ENV GENERATE_SOURCEMAP false

RUN yarn build

# ---------- Release ----------
FROM base as release
COPY --from=builder /usr/src/app/package.json ./package.json
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/.next ./.next

ARG next_public_tag
ARG next_public_name
Expand All @@ -24,21 +48,7 @@ ENV NEXT_PUBLIC_UAL_API_PORT $next_public_ual_api_port
ENV NEXT_PUBLIC_UAL_CHAIN_ID $next_public_ual_chain_id
ENV NEXT_PUBLIC_HASURA_URL $next_public_hasura_url

WORKDIR /usr/src/app

RUN apk add --no-cache git

COPY package.json .

COPY yarn*.lock .

RUN yarn --frozen-lockfile

COPY . .

ENV GENERATE_SOURCEMAP false

RUN yarn build
ENV NODE_ENV production

EXPOSE 3000

Expand Down
40 changes: 19 additions & 21 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,26 @@
},
"dependencies": {
"@0xpolygonid/js-sdk": "^1.1.0",
"@apollo/client": "^3.8.0-rc.1",
"@apollo/client": "^3.8.4",
"@apollo/experimental-nextjs-app-support": "^0.0.0-commit-7dad495",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@google-cloud/recaptcha-enterprise": "^2.4.0",
"@iden3/js-iden3-auth": "^1.0.0",
"@mui/icons-material": "^5.11.11",
"@iden3/js-iden3-auth": "^1.0.2",
"@mui/icons-material": "^5.14.11",
"@mui/lab": "^5.0.0-alpha.124",
"@mui/material": "^5.11.15",
"@mui/styles": "^5.11.13",
"@mui/x-date-pickers": "^6.0.4",
"@types/react-swipeable-views-utils": "^0.13.3",
"@mui/material": "^5.14.11",
"@mui/styles": "^5.14.11",
"@types/react-swipeable-views-utils": "^0.13.5",
"@types/yup": "^0.29.13",
"accept-language": "^3.0.18",
"bufferutil": "^4.0.7",
"clsx": "^1.1.1",
"date-fns": "^2.25.0",
"formik": "^2.2.9",
"graphql": "^16.7.1",
"formik": "^2.4.5",
"graphql": "^16.8.1",
"jwt-decode": "^3.1.2",
"next": "^13.4.7",
"next-intl": "^2.19.1",
"next": "^13.5.3",
"next-intl": "^2.20.2",
"next-seo": "^4.28.1",
"node-fetch": "^3.0.0",
"qrcode.react": "^3.1.0",
Expand All @@ -59,22 +57,22 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@types/gtag.js": "^0.0.8",
"@types/react": "18.0.31",
"@types/react-dom": "18.0.11",
"@types/react-swipeable-views": "^0.13.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"@types/react": "^18.2.23",
"@types/react-dom": "^18.2.8",
"@types/react-swipeable-views": "^0.13.3",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"eslint": "7.32.0",
"eslint-config-next": "13.2.4",
"eslint-config-prettier": "^8.3.0",
"eslint-config-next": "^13.5.3",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react-hooks": "^4.2.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "^11.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"typescript": "4.5.2"
"typescript": "^5.2.2"
}
}
172 changes: 172 additions & 0 deletions webapp/src/app/[locale]/components/TableCredential/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import * as React from 'react'
import { useEffect } from 'react'
import { useLocale, useTranslations } from 'next-intl'
import Box from '@mui/material/Box'
import Table from '@mui/material/Table'
import TableBody from '@mui/material/TableBody'
import TableCell from '@mui/material/TableCell'
import TableContainer from '@mui/material/TableContainer'
import TableHead from '@mui/material/TableHead'
import TablePagination from '@mui/material/TablePagination'
import TableRow from '@mui/material/TableRow'
import Typography from '@mui/material/Typography'
import Paper from '@mui/material/Paper'
import { AuthorizationRequestMessage } from '@0xpolygonid/js-sdk/dist/types/iden3comm/types/protocol/auth'
import { gql, useLazyQuery } from '@apollo/client'

const getRequestQuery = gql`
query get_request_data($limit: Int!, $offset: Int!) {
request(limit: $limit, offset: $offset, order_by: { created_at: desc }) {
auth
session_id
status
}
request_aggregate {
aggregate {
count
}
}
}
`

export const Status = {
pending: 'pending',
success: 'success'
} as const

export type StatusType = (typeof Status)[keyof typeof Status]

export interface Request {
session_id: string
auth: AuthorizationRequestMessage
status?: StatusType
}

export interface RequestResponse {
request: Request[]
request_aggregate: {
aggregate: {
count: number
}
}
}

interface HeadCell {
disablePadding: boolean
id: keyof Request
label: string
numeric: boolean
}

const headCells: readonly HeadCell[] = [
{
id: 'session_id',
numeric: false,
disablePadding: false,
label: 'Proof Id'
},
{
id: 'status',
numeric: true,
disablePadding: false,
label: 'Status'
}
]

const EnhancedTableHead = () => {
return (
<TableHead>
<TableRow>
{headCells.map(headCell => (
<TableCell
key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'normal'}
>
{headCell.label}
</TableCell>
))}
</TableRow>
</TableHead>
)
}

export default function EnhancedTable(): JSX.Element {
const locale = useLocale()
const t = useTranslations('CredentialPage')
const [page, setPage] = React.useState(0)
const [rowsPerPage] = React.useState(5)
const [loadQuery, { data }] = useLazyQuery<RequestResponse>(getRequestQuery, {
variables: { limit: rowsPerPage, offset: page * rowsPerPage },
fetchPolicy: 'network-only'
})

const handleChangePage = (event: unknown, newPage: number) => {
setPage(newPage)

loadQuery({
variables: { limit: rowsPerPage, offset: newPage * rowsPerPage }
})
}

useEffect(() => {
loadQuery()
}, [loadQuery])

return (
<Box sx={{ width: '70%' }}>
<Paper sx={{ width: '100%', mb: 2 }}>
<TableContainer>
<Table aria-labelledby='tableTitle' size={'medium'}>
<EnhancedTableHead />
{data?.request_aggregate.aggregate.count || 0 > 0 ? (
<TableBody>
{data?.request.map((row, index) => {
const labelId = `enhanced-table-checkbox-${index}`

return (
<TableRow
hover
role='checkbox'
tabIndex={-1}
key={row.session_id}
sx={{ cursor: 'pointer' }}
>
<TableCell
component='th'
id={labelId}
scope='row'
padding='normal'
>
{row.session_id.toString().substring(0, 8)}
</TableCell>
<TableCell align='right'>{row.status}</TableCell>
</TableRow>
)
})}
</TableBody>
) : (
<Typography
variant='caption'
style={{
fontSize: '16px',
marginLeft: '8px'
}}
>
{t('no-data', { locale })}
</Typography>
)}
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[5]}
component='div'
count={data?.request_aggregate.aggregate.count || 0}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
/>
</Paper>
</Box>
)
}
Loading

0 comments on commit 7172ee5

Please sign in to comment.