Skip to content

Commit

Permalink
origin data name change, tree view bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanaijaz committed Oct 26, 2024
1 parent 9ac9964 commit bc01a8f
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ const DataFilesProjectFileListingAddon = ({ system }) => {
)}
<span className={styles.separator}>|</span>
{selectedFiles.length == 1 && selectedFiles[0]?.metadata &&
selectedFiles[0].metadata['data_type'] === 'origin_data' ? (
selectedFiles[0].metadata['data_type'] === 'digital_dataset' ? (
<Button
type="link"
onClick={() =>
createOriginDataModal('EDIT_ORIGIN_DATASET', selectedFiles[0])
}
>
Edit Origin Dataset
Edit Digital Dataset
</Button>
) : (
<Button
type="link"
onClick={() => createOriginDataModal('ADD_ORIGIN_DATASET')}
>
Add Origin Dataset
Add Digital Dataset
</Button>
)}
<span className={styles.separator}>|</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useFileListing } from 'hooks/datafiles';
import DataDisplay from '../utils/DataDisplay/DataDisplay';
import { formatDate } from 'utils/timeFormat';

const excludeKeys = ['name', 'description', 'data_type', 'sample', 'base_origin_data', 'file_objs'];
const excludeKeys = ['name', 'description', 'data_type', 'sample', 'digital_dataset', 'file_objs'];

const DataFilesProjectFileListingMetadataAddon = ({ folderMetadata, metadata, path }) => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const DataFilesProjectFileListingMetadataTitleAddon = ({ folderMetadata, metadat
case 'sample':
createSampleModal('EDIT_SAMPLE_DATA', editFile);
break;
case 'origin_data':
case 'digital_dataset':
createOriginDataModal('EDIT_ORIGIN_DATASET', editFile);
break;
case 'analysis_data':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ReviewProjectStructure = ({ projectTree }) => {
if (projectTree && projectTree.length > 0) {
setExpandedNodes([projectTree[0].id]);
}
}, [projectTree]);
}, []);

const handleNodeToggle = (event, nodeIds) => {
// Update the list of expanded nodes
Expand Down Expand Up @@ -71,13 +71,13 @@ const ReviewProjectStructure = ({ projectTree }) => {
name: node.metadata.name,
system: params.system,
type: 'dir',

path: node.path,
};
switch (dataType) {
case 'sample':
createSampleModal('EDIT_SAMPLE_DATA', editFile);
break;
case 'origin_data':
case 'digital_dataset':
createOriginDataModal('EDIT_ORIGIN_DATASET', editFile);
break;
case 'analysis_data':
Expand Down Expand Up @@ -113,8 +113,7 @@ const ReviewProjectStructure = ({ projectTree }) => {
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');

const renderTree = (node) => {
return (
const renderTree = (node) => (
<>
<Section
className={styles['section-project-structure']}
Expand Down Expand Up @@ -158,7 +157,7 @@ const ReviewProjectStructure = ({ projectTree }) => {
'description',
'data_type',
'sample',
'base_origin_data',
'digital_dataset',
'file_objs',
]}
/>
Expand All @@ -173,8 +172,8 @@ const ReviewProjectStructure = ({ projectTree }) => {
</div>
</Section>
</>
)};

);
return (
<SectionTableWrapper
header={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useFileListing } from 'hooks/datafiles';
const processSampleAndOriginData = (data, path) => {
// use the path to get sample and origin data names
const sample = data.sample ? path.split('/')[0] : null;
const origin_data = data.base_origin_data ? path.split('/')[1] : null;
const origin_data = data.digital_dataset ? path.split('/')[1] : null;

// remove trailing / from pathname
const locationPathname = location.pathname.endsWith('/') ? location.pathname.slice(0, -1) : location.pathname;
Expand All @@ -19,7 +19,7 @@ const processSampleAndOriginData = (data, path) => {

// construct urls for sample and origin data and add to processed data
if (sample) {
const sampleUrl = locationPathnameParts.slice(0, data.base_origin_data ? -2 : -1).join('/')
const sampleUrl = locationPathnameParts.slice(0, data.digital_dataset ? -2 : -1).join('/')
sampleAndOriginMetadata.push({ label: 'Sample', value: <Link className={`${styles['dataset-link']}`} to={sampleUrl}>{sample}</Link> });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const customFilePermissions = (operation, files) => {

const protectedDataTypes = [
'sample',
'origin_data',
'digital_dataset',
'analysis_data'
]

Expand Down
7 changes: 3 additions & 4 deletions client/src/redux/sagas/_custom/drp.sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ function* executeOperation(isEdit, params, values, reloadCallback, file = null,

try {
if (file && isEdit) {

yield call(
patchEntityUtil,
filteredValues.data_type,
params.system,
'/' + file.path,
file.path ? '/' + file.path : '',
'/' + path,
filteredValues,
file.uuid
Expand Down Expand Up @@ -122,7 +121,7 @@ function* handleOriginData(action, isEdit) {

const metadata = {
...values,
data_type: 'origin_data',
data_type: 'digital_dataset',
sample: sample.uuid,
}

Expand Down Expand Up @@ -152,7 +151,7 @@ function* handleAnalysisData(action, isEdit) {
...values,
data_type: 'analysis_data',
sample: sample.uuid,
base_origin_data: originData ? originData.uuid : ''
// base_origin_data: originData ? originData.uuid : ''
}

yield call(
Expand Down
1 change: 1 addition & 0 deletions server/portal/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
constants.PROJECT: DrpProjectMetadata,
constants.SAMPLE: DrpSampleMetadata,
constants.ORIGIN_DATA: DrpOriginDatasetMetadata,
constants.DIGITAL_DATASET: DrpOriginDatasetMetadata,
constants.ANALYSIS_DATA: DrpAnalysisDatasetMetadata,
constants.FILE: DrpFileMetadata
}
4 changes: 3 additions & 1 deletion server/portal/apps/_custom/drp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class DrpDatasetMetadata(DrpMetadataModel):
data_type: Literal[
"sample",
"origin_data",
"digital_dataset",
"analysis_data",
"file"
]
Expand Down Expand Up @@ -211,4 +212,5 @@ class DrpAnalysisDatasetMetadata(DrpDatasetMetadata):
]
external_uri: Optional[str] = None
sample: str
base_origin_data: Optional[str] = None
# base_origin_data: Optional[str] = None
digital_dataset: Optional[str] = None
12 changes: 11 additions & 1 deletion server/portal/apps/_custom/drp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from portal.apps.projects.models.project_metadata import ProjectMetadata
from portal.apps._custom.drp import constants
import networkx as nx
from networkx import shortest_path
from portal.apps.projects.workspace_operations.project_meta_operations import get_ordered_value
class DigitalRocksSampleView(BaseApiView):

Expand All @@ -24,7 +25,7 @@ def get(self, request):
if get_origin_data == 'true':
# origin_data = DataFilesMetadata.objects.filter(project_id=full_project_id, metadata__data_type='origin_data').values('id', 'name', 'path', 'metadata')

origin_data = ProjectMetadata.objects.filter(base_project__value__projectId=full_project_id, name=constants.ORIGIN_DATA).values('uuid', 'name', 'value')
origin_data = ProjectMetadata.objects.filter(base_project__value__projectId=full_project_id, name=constants.DIGITAL_DATASET).values('uuid', 'name', 'value')

response_data = {
'samples': list(samples),
Expand Down Expand Up @@ -65,6 +66,8 @@ def get(self, request):

graph = nx.node_link_graph(graph_model.value)

trash_node_id = None

for node_id in graph.nodes:
trash_node = graph.nodes[node_id].get('name') == settings.TAPIS_DEFAULT_TRASH_NAME
if trash_node:
Expand All @@ -80,6 +83,13 @@ def get(self, request):

node = graph.nodes[node_id]

# Get the path from NODE_ROOT to the current node
if nx.has_path(graph, 'NODE_ROOT', node_id):
path_nodes = shortest_path(graph, 'NODE_ROOT', node_id)[1:]
node['path'] = '/'.join(graph.nodes[parent]['label'] for parent in path_nodes if 'label' in graph.nodes[parent])
else:
node['path'] = ""

if node.get('value'):
metadata = get_ordered_value(node['name'], node['value'])
file_objs = node['value'].get('fileObjs', [])
Expand Down
4 changes: 2 additions & 2 deletions server/portal/apps/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ def patch(self, request: HttpRequest, project_id: str):
raise ApiException("Error updating file metadata", status=500) from exc
else:
try:
new_name = move_entity(client, project_id, path, updated_path, value)
patch_entity_and_node(project_id, value, path, updated_path, new_name)
new_name = move_entity(client, project_id, path, updated_path, value, entity_uuid)
patch_entity_and_node(project_id, value, path, updated_path, new_name, entity_uuid)
except Exception as exc:
raise ApiException("Error updating entity metadata", status=500) from exc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def update_node_in_project(project_id: str, node_id: str, new_parent: str = None
if not project_graph.has_node(node_id):
raise nx.exception.NodeNotFound

if new_parent:
if new_parent and new_parent != node_id:
# Remove the node from the graph and re-add it under the new parent.
parent_node = new_parent
if not project_graph.has_node(parent_node):
Expand Down Expand Up @@ -156,4 +156,16 @@ def add_node_to_project(project_id: str, parent_node: str, meta_uuid: str, name:

graph_model.value = nx.node_link_data(updated_graph)
graph_model.save()
return new_node_id
return new_node_id

def get_node_from_uuid(project_id: str, uuid: str):
"""Get a node from the project graph using its UUID."""
graph_model = ProjectMetadata.objects.get(
name=constants.PROJECT_GRAPH, base_project__value__projectId=project_id
)
project_graph = nx.node_link_graph(graph_model.value)

for node_id in project_graph.nodes:
if project_graph.nodes[node_id]["uuid"] == uuid:
return {"id": node_id, **project_graph.nodes[node_id]}
return None
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from portal.apps._custom.drp import constants
from portal.apps.projects.models.project_metadata import ProjectMetadata
from portal.apps._custom.drp.models import PartialEntityWithFiles, FileObj
from portal.apps.projects.workspace_operations.graph_operations import get_node_from_path, get_root_node, update_node_in_project
from portal.apps.projects.workspace_operations.graph_operations import get_node_from_path, get_node_from_uuid, get_root_node, update_node_in_project

portal = settings.PORTAL_NAMESPACE.lower()

Expand Down Expand Up @@ -192,13 +192,19 @@ def patch_file_obj_entity(client, project_id, value, path):
return entity

@transaction.atomic
def patch_entity_and_node(project_id, value, path, new_path, new_name):
def patch_entity_and_node(project_id, value, path, new_path, new_name, uuid=None):
"""Perform an operation on an entity."""

new_path_full = os.path.join(new_path.strip('/'), new_name)

source_node = get_node_from_path(project_id, path)
entity = ProjectMetadata.objects.get(uuid=source_node['uuid'])
if (path):
source_node = get_node_from_path(project_id, path)
elif (not path and uuid):
source_node = get_node_from_uuid(project_id, uuid)
else:
raise ValueError("Invalid parameters: path or uuid must be provided.")

entity = ProjectMetadata.objects.get(uuid=uuid if uuid else source_node['uuid'])

new_parent_node = get_node_from_path(project_id, new_path)

Expand Down

0 comments on commit bc01a8f

Please sign in to comment.