Skip to content

Commit

Permalink
Merge pull request #19 from cophilot/adapt-new-changes
Browse files Browse the repository at this point in the history
Adapt new changes
  • Loading branch information
cophilot authored Feb 8, 2024
2 parents bbf7c91 + 2570fbd commit 883f137
Show file tree
Hide file tree
Showing 12 changed files with 640 additions and 73 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"prepare": "husky install",
"generate": "python scripts/generate.py",
"g": "python scripts/generate.py",
"todo": "python scripts/todo.py",
"comment:check": "python scripts/check_comment.py",
"backend:check": "python scripts/check_backend.py",
"backend:create": "npm run backend:create:tables",
Expand Down
19 changes: 18 additions & 1 deletion src/components/DocBaseOverview/DocBaseOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import './DocBaseOverview.scss';
import APIService from '../../utils/ApiService';
import MyDocument from '../../types/MyDocument';
import { Link } from 'react-router-dom';
import { useLoadDocbaseTask } from '../../providers/DocBaseTaskProvider';
import {
useLoadDocbaseTask,
useStartInteractiveTablePopulation,
} from '../../providers/DocBaseTaskProvider';
import {
useShowChoiceNotification,
useShowNotification,
Expand All @@ -29,6 +32,8 @@ function DocBaseOverview({ organizationProp }: Props) {
const showNotification = useShowNotification();
const getOrganizations = useGetOrganizations();
const loadDocbaseTask = useLoadDocbaseTask();
const startDocBaseInteractiveTablePopulation =
useStartInteractiveTablePopulation();

useEffect(() => {
APIService.getOrganizationNames().then((orgs) => {
Expand Down Expand Up @@ -66,6 +71,10 @@ function DocBaseOverview({ organizationProp }: Props) {
loadDocbaseTask(selectedOrgID, document.name);
};

const startInteractiveTablePopulation = (document: MyDocument) => {
startDocBaseInteractiveTablePopulation(selectedOrgID, document.name);
};

const removeDocument = (document: MyDocument) => {
showChoiceNotification(
'Delete DocBase',
Expand Down Expand Up @@ -168,6 +177,14 @@ function DocBaseOverview({ organizationProp }: Props) {
>
View DocBase
</Icon>
<Icon
cls="bi bi-check-square icon"
onClicked={() => {
startInteractiveTablePopulation(docBase);
}}
>
Start interactive table population
</Icon>
<Icon
cls="bi bi-x-circle"
onClicked={() => {
Expand Down
17 changes: 7 additions & 10 deletions src/components/DocbaseViewer/DocbaseViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,15 @@ function DocbaseViewer({ docBase, onClose }: Props) {
onClose();
}}
></AttributeAdder>
{/* <ul className="ver">
{docBase.attributes.map((attribute, index) => {
return (
<li key={index}>
<b>{attribute}</b>
</li>
);
})}
</ul> */}
<h2>Documents</h2>
{docBase.docs.map((doc, index) => {
return <NuggetDocumentViewer key={index} doc={doc} />;
return (
<NuggetDocumentViewer
key={index}
doc={doc}
docBase={docBase}
/>
);
})}
<button className="btn mb ml mt" onClick={onClose}>
Close
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.InteractiveDocBaseViewer {
width: 90%;
height: 80%;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: var(--bg-color);
overflow-y: scroll;
border-radius: 15px;
border: 2px solid var(--text-color);
z-index: 999;
padding: 40px;
.buffer {
height: 150px;
width: 10px;
}
}

.closeBtn {
position: fixed;
top: 9%;
right: 5%;
cursor: pointer;
z-index: 1000;
font-size: 30px;
cursor: pointer;
color: var(--text-color);
font-weight: bold;
&:hover {
scale: 1.15;
}
}

.infobar {
position: fixed;
left: 50%;
top: 85%;

transform: translateX(-50%);
background-color: var(--btn-color);
z-index: 1000;
width: 90%;
border-radius: 15px;
border: 2px solid var(--text-color);
padding-left: 20px;
padding-right: 20px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0px 0px 10px 10px #00000079;
font-size: 20px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import DocBase from '../../types/DocBase';
import NuggetDocumentViewer from '../NuggetViewer/NuggetDocumentViewer';
import './InteractiveDocBaseViewer.scss';

interface Props {
docBase: DocBase;
onClose: () => void;
}

/**
* A popup that displays a DocBases
* @param docBase The docbase to view
*/
function InteractiveDocBaseViewer({ docBase }: Props) {
return (
<>
<div
className="background"
style={{
zIndex: 100,
}}
></div>

<div className="InteractiveDocBaseViewer">
<h1>Interactive Table Population Editor</h1>
<h2>
DocBase: <i>{docBase.name}</i>
</h2>

<h2>Documents</h2>
{docBase.docs.map((doc, index) => {
return (
<NuggetDocumentViewer
key={index}
doc={doc}
interactive={true}
docBase={docBase}
/>
);
})}
<div className="buffer"></div>
</div>
<div className="infobar">
<p>
<i>Attribute</i>: <b>{docBase.attributes.join(', ')}</b>
</p>
</div>
</>
);
}
export default InteractiveDocBaseViewer;
19 changes: 16 additions & 3 deletions src/components/NuggetText/NuggetText.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

.highlighted-unselected {
background-color: rgba(255, 255, 0, 0.4);
background-color: rgba(255, 255, 0, 0.2);
color: black;
border-radius: 5px;
}
Expand All @@ -14,7 +14,7 @@
overflow-x: scroll;
}
.nugget {
background-color: rgba(255, 255, 0, 0.4);
background-color: rgba(255, 255, 0, 0.2);
color: black;
border-radius: 5px;
padding: 5px;
Expand All @@ -30,8 +30,21 @@
background-color: rgb(255, 255, 0);
}

.attribute-label {
order: 1;
font-size: 0.8rem;
font-weight: bold;
background-color: red;
}

.ghf {
order: 2;
align-self: baseline; // Add this line
}

pre {
font-size: 1rem;
font-size: 1.2rem;
line-height: 2;
padding-left: 20px;
padding-right: 20px;
padding-top: 10px;
Expand Down
63 changes: 51 additions & 12 deletions src/components/NuggetText/NuggetText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import React from 'react';
import NuggetDocument from '../../types/NuggetDocument';
import './NuggetText.scss';
import Nugget from '../../types/Nugget';
import Icon from '../Icon/Icon';
import Logger from '../../utils/Logger';

interface Props {
doc: NuggetDocument;
interactive?: boolean;
}

/**
* Displays a NuggetDocuments content and highlights the nuggets
* @param param0 The nuggget document to display
* @returns
*/
function NuggetText({ doc }: Props) {
function NuggetText({ doc, interactive = false }: Props) {
const [selectedNugget, setSelectedNugget] = React.useState<
Nugget | undefined
>(undefined);
Expand Down Expand Up @@ -44,17 +47,53 @@ function NuggetText({ doc }: Props) {
index > 0 ? normalizedIntervals[index - 1].end : 0,
start
)}
<span
className={
selectedNugget === undefined
? 'highlighted'
: selectedNugget.startChar == start &&
selectedNugget.endChar == end
? 'highlighted'
: 'highlighted-unselected'
}
>
{text.substring(start, end)}
<span className="box">
{/* <span className="attribute-label">att</span>
*/}
<span
className={
selectedNugget === undefined
? 'ghf highlighted'
: selectedNugget.startChar == start &&
selectedNugget.endChar == end
? 'ghf highlighted'
: 'ghf highlighted-unselected'
}
>
<span>{text.substring(start, end)}</span>
{interactive && (
<>
<Icon
style={{
color: 'black',
fontSize: '1.2rem',
marginRight: '5px',
paddingRight: '10px',
}}
cls="bi bi-hand-thumbs-up icon ml"
onClicked={() => {
Logger.log('Confirm Nugget');
alert('Not implemented');
}}
>
Confirm Nugget
</Icon>
{/* <Icon
style={{
color: 'black',
fontSize: '1.2rem',
paddingRight: '10px',
}}
cls="bi bi-hand-thumbs-down icon"
onClicked={() => {
Logger.log('Decline Nugget');
}}
>
Decline Nugget
</Icon> */}
</>
)}
</span>
</span>
</React.Fragment>
))
Expand Down
30 changes: 28 additions & 2 deletions src/components/NuggetViewer/NuggetDocumentViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
import NuggetDocument from '../../types/NuggetDocument';
import Icon from '../Icon/Icon';
import NuggetText from '../NuggetText/NuggetText';
import './NuggetDocumentViewer.scss';
import { useGetOrderedNuggets } from '../../providers/DocBaseTaskProvider';
import DocBase from '../../types/DocBase';

interface Props {
docBase: DocBase;
doc: NuggetDocument;
interactive?: boolean;
}

/**
* This displays a NuggetDocument
* @param doc The NuggetDocument to display
*/
function NuggetDocumentViewer({ doc }: Props) {
function NuggetDocumentViewer({ docBase, doc, interactive = false }: Props) {
const getOrderedNuggets = useGetOrderedNuggets();

return (
<div className="ver">
<p>
<b>
Document: <i>{doc.name}</i>
</b>
{!interactive && (
<Icon
cls="bi bi-info-circle ml"
style={{
//TODO
display: 'none',
}}
onClicked={() => {
getOrderedNuggets(
docBase.organizationId,
docBase.name,
doc.name,
doc.content
);
}}
>
Get more information about this document
</Icon>
)}
</p>
<NuggetText doc={doc} />
<NuggetText doc={doc} interactive={interactive} />
</div>
);
}
Expand Down
Loading

0 comments on commit 883f137

Please sign in to comment.