<commit_before>import { Component, Input, ViewEncapsulation } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ColDef } from 'ag-grid-community';
import gql from 'graphql-tag';
import { DateTime } from 'luxon';
import {
  ContestProblemAssignmentUserTacklingSubmissionListFragment,
  ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment,
} from '../generated/graphql-types';
import { getFieldColumns } from './data/field-table';
import { textFragment } from './material/text.pipe';
import { submissionModalFragment } from './submission-modal.component';

@Component({
  selector: 'app-contest-problem-assignment-user-tackling-submission-list',
  templateUrl: './contest-problem-assignment-user-tackling-submission-list.component.html',
  styleUrls: ['./contest-problem-assignment-user-tackling-submission-list.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class ContestProblemAssignmentUserTacklingSubmissionListComponent {
  constructor(readonly modalService: NgbModal) {}

  @Input()
  data!: ContestProblemAssignmentUserTacklingSubmissionListFragment;

  openSubmission!: ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment;

  getSummaryRows(submissions: ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment[]) {
    return submissions.map(s => s.summaryRow);
  }

  getColumns(data: ContestProblemAssignmentUserTacklingSubmissionListFragment): ColDef[] {
    return [
      {
        colId: 'time',
        headerName: 'Submitted at',
        valueGetter: ({ data: submission }) =>
          (submission as ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment).createdAt.local,
        valueFormatter: ({ value: dateString }) =>
          DateTime.fromISO(dateString as string).toRelative() ?? `${dateString}`,
        tooltipValueGetter: ({ value: dateString }) => `${dateString}`.replace('T', ' '),
      },
      ...getFieldColumns(
        data.assignmentView.assignment.problem.submissionListColumns,
        (submission: ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment) => submission.summaryRow,
      ),
    ];
  }
}

export const contestProblemAssignmentUserTacklingSubmissionListFragment = gql`
  fragment ContestProblemAssignmentUserTacklingSubmissionList on ContestProblemAssignmentUserTackling {
    submissions {
      ...ContestProblemAssignmentUserTacklingSubmissionListSubmission
    }

    assignmentView {
      assignment {
        problem {<commit_msg>Show most recent submissions first in the list<commit_after>import { Component, Input, ViewEncapsulation } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ColDef } from 'ag-grid-community';
import gql from 'graphql-tag';
import { DateTime } from 'luxon';
import {
  ContestProblemAssignmentUserTacklingSubmissionListFragment,
  ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment,
} from '../generated/graphql-types';
import { getFieldColumns } from './data/field-table';
import { textFragment } from './material/text.pipe';
import { submissionModalFragment } from './submission-modal.component';

@Component({
  selector: 'app-contest-problem-assignment-user-tackling-submission-list',
  templateUrl: './contest-problem-assignment-user-tackling-submission-list.component.html',
  styleUrls: ['./contest-problem-assignment-user-tackling-submission-list.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class ContestProblemAssignmentUserTacklingSubmissionListComponent {
  constructor(readonly modalService: NgbModal) {}

  @Input()
  data!: ContestProblemAssignmentUserTacklingSubmissionListFragment;

  openSubmission!: ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment;

  getSummaryRows(submissions: ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment[]) {
    return submissions.map(s => s.summaryRow);
  }

  getColumns(data: ContestProblemAssignmentUserTacklingSubmissionListFragment): ColDef[] {
    return [
      {
        colId: 'time',
        headerName: 'Submitted at',
        sortable: true,
        sort: 'desc',
        sortingOrder: ['desc', 'asc', null] as string[],
        valueGetter: ({ data: submission }) =>
          (submission as ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment).createdAt.local,
        valueFormatter: ({ value: dateString }) =>
          DateTime.fromISO(dateString as string).toRelative() ?? `${dateString}`,
        tooltipValueGetter: ({ value: dateString }) => `${dateString}`.replace('T', ' '),
      },
      ...getFieldColumns(
        data.assignmentView.assignment.problem.submissionListColumns,
        (submission: ContestProblemAssignmentUserTacklingSubmissionListSubmissionFragment) => submission.summaryRow,
      ),
    ];
  }
}

export const contestProblemAssignmentUserTacklingSubmissionListFragment = gql`
  fragment ContestProblemAssignmentUserTacklingSubmissionList on ContestProblemAssignmentUserTackling {
    submissions {
      ...ContestProblemAssignmentUserTacklingSubmissionListSubmission
    }

    assignmentView {
      assignment {
        problem {
{'fraction_non_alphanumeric': 0.10497877267464299, 'fraction_numerical': 0.0, 'mean_word_length': 5.040792540792541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024429', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1421, 'n_words': 233}