Commit e4326cf9 authored by Marek Veselý's avatar Marek Veselý
Browse files

Merge branch '769-fix-file-drive' into 'main'

Fix file drive

Closes #769

See merge request inject/frontend!675
parents d99ff583 a3a6d520
Loading
Loading
Loading
Loading
+23 −55
Original line number Diff line number Diff line
import { Button } from '@blueprintjs/core'
import { css } from '@emotion/css'
import type { FileInfo } from '@inject/graphql'
import type { Column } from '@inject/shared'
import {
  dateSortingFunction,
  stringSortingFunction,
  Table,
  timedFormatter,
} from '@inject/shared'
import type { Column, Row } from '@inject/shared'
import { stringSortingFunction, Table } from '@inject/shared'
import type { NavigateOptions } from '@tanstack/react-router'
import { useNavigate } from '@tanstack/react-router'
import type { FC } from 'react'
@@ -29,12 +23,7 @@ const DriveTable: FC<DriveProps> = ({
}) => {
  const nav = useNavigate()

  const handleClick = (
    e: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
    link: NavigateOptions
  ) => {
    e.preventDefault()

  const handleClick = (link: NavigateOptions) => {
    nav({
      ...link,
      state: {
@@ -51,38 +40,19 @@ const DriveTable: FC<DriveProps> = ({
      id: 'name',
      name: 'Name',
      style: { textAlign: 'left' },
      renderValue: file => file.fileName,
      renderValue: file => (
        <p
          className={css`
            margin: 0;
            padding-block: 0.5rem;
          `}
        >
          {file.fileName}
        </p>
      ),
      sortingFunction: (a, b) => stringSortingFunction(a.fileName, b.fileName),
      className: verticallyCentered,
    },
    {
      id: 'uploaded',
      name: 'Uploaded',
      style: { textAlign: 'left', width: '20ch' },
      renderValue: file =>
        timedFormatter({ datetime: new Date(file.uploadedAt) }),
      sortingFunction: (a, b) =>
        dateSortingFunction(new Date(a.uploadedAt), new Date(b.uploadedAt)),
      className: verticallyCentered,
    },
    {
      id: 'actions',
      name: 'Actions',
      style: {
        textAlign: 'right',
        width: '14ch',
      },
      renderValue: file => {
        const link = getFileLink(file.id)

        return (
          <a href={link.href} onClick={e => handleClick(e, link)}>
            <Button icon='eye-open' title='Preview' />
          </a>
        )
      },
      className: verticallyCentered,
    },
  ]

  const filteredFiles = useMemo(
@@ -93,18 +63,16 @@ const DriveTable: FC<DriveProps> = ({
    [fileInfos, searchString]
  )

  const rows = useMemo(
    () =>
      filteredFiles
  const rows: Row<FileInfo>[] = filteredFiles
    .map(fileInfo => ({
      id: fileInfo.id,
      value: fileInfo,
      onClick: () => {
        const link = getFileLink(fileInfo.id)
        handleClick(link)
      },
    }))
        .sort((a, b) =>
          stringSortingFunction(a.value.fileName, b.value.fileName)
        ),
    [filteredFiles]
  )
    .sort((a, b) => stringSortingFunction(a.value.fileName, b.value.fileName))

  return (
    <Table<FileInfo>
+12 −7
Original line number Diff line number Diff line
@@ -105,13 +105,6 @@ export const InstructorView: FC<InstructorViewProps> = ({
          {exerciseId && (
            <OverviewButton exerciseId={exerciseId} hideLabel={hideLeftBar} />
          )}
          <DriveButton
            link={{
              to: InstructorDriveRoute.to,
              params: { exerciseId },
            }}
            hideLabel={hideLeftBar}
          />
          <MoveTimeButton
            hideLabel={hideLeftBar}
            exerciseId={exerciseId}
@@ -151,6 +144,18 @@ export const InstructorView: FC<InstructorViewProps> = ({
        </>
      ),
    },
    {
      id: 'Documents',
      node: (
        <DriveButton
          link={{
            to: InstructorDriveRoute.to,
            params: { exerciseId },
          }}
          hideLabel={hideLeftBar}
        />
      ),
    },
    ...(exerciseId && teamId
      ? [
          {
+13 −9
Original line number Diff line number Diff line
@@ -66,15 +66,6 @@ export const TraineeView: FC<TraineeViewProps> = ({
      node: (
        <>
          <HideSidebarButton />
          {teamId && (
            <DriveButton
              link={{
                to: TraineeDriveRoute.to,
                params: { exerciseId },
              }}
              hideLabel={hideLeftBar}
            />
          )}
          <ExitButton
            exitRoute={{ to: RootRoute.to }}
            hideLabel={hideLeftBar}
@@ -82,8 +73,21 @@ export const TraineeView: FC<TraineeViewProps> = ({
        </>
      ),
    },

    ...(teamId
      ? [
          {
            id: 'Documents',
            node: (
              <DriveButton
                link={{
                  to: TraineeDriveRoute.to,
                  params: { exerciseId },
                }}
                hideLabel={hideLeftBar}
              />
            ),
          },
          {
            id: 'channels',
            name: 'Channels',
+2 −2
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@ export const DriveButton: FC<DriveButtonProps> = ({ link, hideLabel }) => (
      alignText: 'left',
      fill: true,
      minimal: true,
      title: 'File drive',
      text: !hideLabel && 'File drive',
      title: 'Documents',
      text: !hideLabel && 'Documents',
    }}
    end
  />