Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK-1059] Handle submission groups in Access Log UI #5116

Merged
merged 25 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0af76c1
refactor: make access logs a proxy class
rgraber Sep 3, 2024
ee2e727
fixup!: new tests
rgraber Sep 3, 2024
6587c70
fixup!: cleanup
rgraber Sep 3, 2024
f24b102
fixup!: authorized app
rgraber Sep 3, 2024
e19279a
fixup!: fix rebase artifact
rgraber Sep 3, 2024
b2b222b
fixup!: use lowercase user
rgraber Sep 16, 2024
4ba78ca
fixup!: migration
rgraber Sep 17, 2024
fa6bfdf
fixup!: format
rgraber Sep 17, 2024
e039199
feat: group submission logs when fetching access logs
rgraber Sep 17, 2024
d6b6ae6
fixup!: rm old stuff
rgraber Sep 17, 2024
36b4388
fixup!: endpoint documentation
rgraber Sep 17, 2024
6f4a476
fixup!: i will refactor you and everything you love
rgraber Sep 18, 2024
6f2bacc
Merge branch 'task857-access-log-ui' into task1059-access-log-ui-subm…
magicznyleszek Sep 18, 2024
85d9dd1
Merge branch 'task857-access-log-ui' into task1059-access-log-ui-subm…
magicznyleszek Sep 18, 2024
ef7b976
add flexibility to cellFormatter fn for UniversalTable and display pr…
magicznyleszek Sep 18, 2024
31c8c57
fix Project Views switcher text being cut
magicznyleszek Sep 19, 2024
666c70d
docs: update PR template to include test plan (#5154)
rgraber Oct 7, 2024
37b17aa
Merge pull request #5109 from kobotoolbox/task857-access-log-ui
jamesrkiger Oct 7, 2024
b859571
Merge branch 'beta-refactored' into task1059-access-log-ui-submission…
magicznyleszek Oct 7, 2024
ccba1d2
cleanup after merge conflicts
magicznyleszek Oct 7, 2024
a61cb94
Cleanup after merge conflicts
magicznyleszek Oct 7, 2024
4e40666
fix comment typo
magicznyleszek Oct 7, 2024
81e6371
eslint cleanups
magicznyleszek Oct 7, 2024
c8fceea
Merge branch 'task1059-access-log-ui-submission-group' of github.com:…
magicznyleszek Oct 7, 2024
8a2ba47
Merge branch 'main' into task1059-access-log-ui-submission-group
magicznyleszek Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
import React from 'react';

// Partial components
import Button from 'js/components/common/button';
// import Button from 'js/components/common/button';
import PaginatedQueryUniversalTable from 'js/universalTable/paginatedQueryUniversalTable.component';

// Utilities
import useAccessLogsQuery, {type AccessLog} from 'js/query/queries/accessLogs.query';
import {formatTime} from 'js/utils';
import sessionStore from 'js/stores/session';
// import sessionStore from 'js/stores/session';

// Styles
import securityStyles from 'js/account/security/securityRoute.module.scss';

export default function AccessLogsSection() {
function logOutAllSessions() {
sessionStore.logOutAll();
}
// function logOutAllSessions() {
// sessionStore.logOutAll();
// }

return (
<>
Expand All @@ -43,11 +43,21 @@ export default function AccessLogsSection() {
columns={[
// The `key`s of these columns are matching the `AccessLog` interface
// properties (from `accessLogs.query.ts` file) using dot notation.
{key: 'metadata.source', label: t('Source')},
{
key: 'metadata.source',
label: t('Source'),
cellFormatter: (log: AccessLog) => {
if (log.metadata.auth_type === 'submission-group') {
return t('Data Submissions (##count##)').replace('##count##', String(log.count));
} else {
return log.metadata.source;
}
},
},
{
key: 'date_created',
label: t('Last activity'),
cellFormatter: (date: string) => formatTime(date),
cellFormatter: (log: AccessLog) => formatTime(log.date_created),
},
{key: 'metadata.ip_address', label: t('IP Address')},
]}
Expand Down
4 changes: 3 additions & 1 deletion jsapp/js/projects/projectViews/viewSwitcher.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
font-size: sizes.$x20;
font-weight: 800;
color: colors.$kobo-gray-800;
padding: sizes.$x6 sizes.$x16;
padding: 2px sizes.$x16;
// we want it to be 32px height
line-height: 28px;
max-width: sizes.$x400;

:global {
Expand Down
18 changes: 8 additions & 10 deletions jsapp/js/query/queries/accessLogs.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ import type {PaginatedResponse} from 'js/dataInterface';
import {fetchGet} from 'js/api';

export interface AccessLog {
app_label: 'kobo_auth' | string;
model_name: 'User' | string;
object_id: number;
/** User URL */
user: string;
user_uid: string;
/** Date string */
date_created: string;
username: string;
action: 'auth' | string;
metadata: {
auth_type: 'digest' | 'submission-group' | string;
// Both `source` and `ip_address` appear only for `digest` type
/** E.g. "Firefox (Ubuntu)" */
source: string;
auth_type: 'Digest' | string;
ip_address: string;
source?: string;
ip_address?: string;
};
/** Date string */
date_created: string;
log_type: 'access' | string;
/** For `submission-group` type, here is the number of submisssions. */
count: number;
}

async function getAccessLogs(limit: number, offset: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface PaginatedQueryUniversalTableProps<DataItem> {
// Below are props from `UniversalTable` that should come from the parent
// component (these are kind of "configuration" props). The other
// `UniversalTable` props are being handled here internally.
columns: UniversalTableColumn[];
columns: UniversalTableColumn<DataItem>[];
}

const PAGE_SIZES = [10, 30, 50, 100];
Expand Down
11 changes: 6 additions & 5 deletions jsapp/js/universalTable/universalTable.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {generateUuid} from 'js/utils';
// Styles
import styles from './universalTable.module.scss';

export interface UniversalTableColumn {
export interface UniversalTableColumn<DataItem> {
/**
* Pairs to data object properties. It is using dot notation, so it's possible
* to match data from a nested object :ok:.
Expand All @@ -40,14 +40,15 @@ export interface UniversalTableColumn {
size?: number;
/**
* This is an optional formatter function that will be used when rendering
* the cell value. Without it a literal text value will be rendered.
* the cell value. Without it a literal text value will be rendered. For more
* flexibility, function receives whole original data object.
*/
cellFormatter?: (value: string) => React.ReactNode;
cellFormatter?: (value: DataItem) => React.ReactNode;
}

interface UniversalTableProps<DataItem> {
/** A list of column definitions */
columns: UniversalTableColumn[];
columns: UniversalTableColumn<DataItem>[];
data: DataItem[];
// PAGINATION
// To see footer with pagination you need to pass all these below:
Expand Down Expand Up @@ -133,7 +134,7 @@ export default function UniversalTable<DataItem>(
header: () => columnDef.label,
cell: (cellProps: CellContext<DataItem, string>) => {
if (columnDef.cellFormatter) {
return columnDef.cellFormatter(cellProps.getValue());
return columnDef.cellFormatter(cellProps.row.original);
} else {
return cellProps.renderValue();
}
Expand Down
Loading