209 lines
7.1 KiB
TypeScript
209 lines
7.1 KiB
TypeScript
import { mdiChartTimelineVariant } from '@mdi/js'
|
|
import Head from 'next/head'
|
|
import { uniqueId } from 'lodash';
|
|
import React, { ReactElement, useState } from 'react'
|
|
import CardBox from '../../components/CardBox'
|
|
import LayoutAuthenticated from '../../layouts/Authenticated'
|
|
import SectionMain from '../../components/SectionMain'
|
|
import SectionTitleLineWithButton from '../../components/SectionTitleLineWithButton'
|
|
import LegalOpsPageIntro from '../../components/LegalOpsPageIntro'
|
|
import { getPageTitle } from '../../config'
|
|
import TableAi_use_cases from '../../components/Ai_use_cases/TableAi_use_cases'
|
|
import BaseButton from '../../components/BaseButton'
|
|
import axios from "axios";
|
|
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
|
|
import CardBoxModal from "../../components/CardBoxModal";
|
|
import DragDropFilePicker from "../../components/DragDropFilePicker";
|
|
import {setRefetch, uploadCsv} from '../../stores/ai_use_cases/ai_use_casesSlice';
|
|
|
|
|
|
import {hasPermission} from "../../helpers/userPermissions";
|
|
|
|
|
|
|
|
const Ai_use_casesTablesPage = () => {
|
|
const [filterItems, setFilterItems] = useState([]);
|
|
const [csvFile, setCsvFile] = useState<File | null>(null);
|
|
const [isModalActive, setIsModalActive] = useState(false);
|
|
const [showTableView, setShowTableView] = useState(false);
|
|
const actionButtonClass = 'min-h-[44px] w-full justify-center px-4 text-sm font-semibold';
|
|
|
|
|
|
const { currentUser } = useAppSelector((state) => state.auth);
|
|
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
const [filters] = useState([{label: 'Use case title', title: 'title'},{label: 'Description', title: 'description'},{label: 'Business goal', title: 'business_goal'},{label: 'Review notes', title: 'review_notes'},
|
|
|
|
{label: 'Expected hours saved', title: 'expected_hours_saved', number: 'true'},
|
|
{label: 'Submitted at', title: 'submitted_at', date: 'true'},{label: 'Approved at', title: 'approved_at', date: 'true'},
|
|
|
|
|
|
{label: 'Owner', title: 'owner'},
|
|
|
|
|
|
|
|
{label: 'Practice group', title: 'practice_group'},
|
|
|
|
|
|
|
|
{label: 'Matter type', title: 'matter_type'},
|
|
|
|
|
|
|
|
{label: 'Data classification', title: 'data_classification'},
|
|
|
|
|
|
|
|
{label: 'Intended AI tool', title: 'intended_tool'},
|
|
|
|
|
|
|
|
{label: 'Status', title: 'status', type: 'enum', options: ['draft','submitted','risk_review','security_review','ethics_review','approved','rejected','needs_changes','retired']},{label: 'Risk level', title: 'risk_level', type: 'enum', options: ['low','medium','high','critical']},
|
|
]);
|
|
|
|
const hasCreatePermission = currentUser && hasPermission(currentUser, 'CREATE_AI_USE_CASES');
|
|
|
|
|
|
const addFilter = () => {
|
|
const newItem = {
|
|
id: uniqueId(),
|
|
fields: {
|
|
filterValue: '',
|
|
filterValueFrom: '',
|
|
filterValueTo: '',
|
|
selectedField: '',
|
|
},
|
|
};
|
|
newItem.fields.selectedField = filters[0].title;
|
|
setFilterItems([...filterItems, newItem]);
|
|
};
|
|
|
|
const getAi_use_casesCSV = async () => {
|
|
const response = await axios({url: '/ai_use_cases?filetype=csv', method: 'GET',responseType: 'blob'});
|
|
const type = response.headers['content-type']
|
|
const blob = new Blob([response.data], { type: type })
|
|
const link = document.createElement('a')
|
|
link.href = window.URL.createObjectURL(blob)
|
|
link.download = 'ai_use_casesCSV.csv'
|
|
link.click()
|
|
};
|
|
|
|
const onModalConfirm = async () => {
|
|
if (!csvFile) return;
|
|
await dispatch(uploadCsv(csvFile));
|
|
dispatch(setRefetch(true));
|
|
setCsvFile(null);
|
|
setIsModalActive(false);
|
|
};
|
|
|
|
const onModalCancel = () => {
|
|
setCsvFile(null);
|
|
setIsModalActive(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>{getPageTitle('AI request register table')}</title>
|
|
</Head>
|
|
<SectionMain>
|
|
<SectionTitleLineWithButton icon={mdiChartTimelineVariant} title="AI request register table" main>
|
|
{''}
|
|
</SectionTitleLineWithButton>
|
|
<LegalOpsPageIntro
|
|
eyebrow='AI governance intake'
|
|
title='Review proposed AI workflows in table view'
|
|
description='Use the table when you need dense scanning, filtering, CSV review, or quick edits across the AI request register.'
|
|
metrics={[
|
|
{ label: 'View mode', value: 'Table', helper: 'Best for bulk review and governance cleanup.' },
|
|
{ label: 'Review model', value: 'Human approval', helper: 'Partner, GC, security, and ethics review stay visible.' },
|
|
{ label: 'Evidence', value: 'ROI tracked', helper: 'Hours saved, notes, and approvals become an audit trail.' },
|
|
]}
|
|
>
|
|
<div className='grid w-full grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3'>
|
|
{hasCreatePermission && (
|
|
<BaseButton
|
|
href={'/ai_use_cases/ai_use_cases-new'}
|
|
color='info'
|
|
label='New AI intake'
|
|
className={actionButtonClass}
|
|
/>
|
|
)}
|
|
<BaseButton
|
|
color='info'
|
|
outline
|
|
label='Add filter'
|
|
onClick={addFilter}
|
|
className={actionButtonClass}
|
|
/>
|
|
<BaseButton
|
|
color='info'
|
|
outline
|
|
label='Export CSV'
|
|
onClick={getAi_use_casesCSV}
|
|
className={actionButtonClass}
|
|
/>
|
|
{hasCreatePermission && (
|
|
<BaseButton
|
|
color='info'
|
|
outline
|
|
label='Upload CSV'
|
|
onClick={() => setIsModalActive(true)}
|
|
className={actionButtonClass}
|
|
/>
|
|
)}
|
|
<div id='delete-rows-button' className='contents'></div>
|
|
<BaseButton
|
|
href={'/ai_use_cases/ai_use_cases-list'}
|
|
color='info'
|
|
outline
|
|
label='Card view'
|
|
className={actionButtonClass}
|
|
/>
|
|
</div>
|
|
</LegalOpsPageIntro>
|
|
<CardBox className="mb-6" hasTable>
|
|
<TableAi_use_cases
|
|
filterItems={filterItems}
|
|
setFilterItems={setFilterItems}
|
|
filters={filters}
|
|
showGrid={true}
|
|
/>
|
|
</CardBox>
|
|
</SectionMain>
|
|
<CardBoxModal
|
|
title='Upload CSV'
|
|
buttonColor='info'
|
|
buttonLabel={'Confirm'}
|
|
// buttonLabel={false ? 'Deleting...' : 'Confirm'}
|
|
isActive={isModalActive}
|
|
onConfirm={onModalConfirm}
|
|
onCancel={onModalCancel}
|
|
>
|
|
<DragDropFilePicker
|
|
file={csvFile}
|
|
setFile={setCsvFile}
|
|
formats={'.csv'}
|
|
/>
|
|
</CardBoxModal>
|
|
</>
|
|
)
|
|
}
|
|
|
|
Ai_use_casesTablesPage.getLayout = function getLayout(page: ReactElement) {
|
|
return (
|
|
<LayoutAuthenticated
|
|
|
|
permission={'READ_AI_USE_CASES'}
|
|
|
|
>
|
|
{page}
|
|
</LayoutAuthenticated>
|
|
)
|
|
}
|
|
|
|
export default Ai_use_casesTablesPage
|