Skip to content

Conversation

@Vismayak
Copy link
Contributor

Aim

To create an option in the file component viewer to only see the files in the current dataset

Methodology

The difficulty behind the task is because the datasetID depends on which dataset the extractor is called from and therefore can not be hardcoded into the extractor_info json. In order to bypass, this we use the property uiSchema (that I have previously misunderstood) and "ui:options".

uiSchema is actually used to format a given input and is dependent on the parameter name. ui:options allows us to pass in the datasetID as a field. Since the uiSchema uses parameter names I use a for loop to iterate through the form's parameters and add to the uiSchema

	// The for loop is used to pass the datasetId to a widget if it is a clowderFile Widget
	if (
		selectedExtractor &&
		selectedExtractor["properties"] &&
		selectedExtractor["properties"]["parameters"] &&
		selectedExtractor["properties"]["parameters"]["schema"]
	) {
		const parameters = selectedExtractor["properties"]["parameters"]["schema"];
		for (const key in parameters) {
			// Check if field "format" present and equals "clowderFile"
			if (parameters[key].format && parameters[key].format === "clowderFile") {
				uiSchema[key] = {
					"ui:widget": "clowderFile",
					"ui:options": {
						datasetId: datasetId,
					},
				};
			}
		}
	}

The rest of the changes are pretty straightforward. It involves passing in the datasetID and a flag to only show the dataset files or the entire filesystem.

How to test

Run an extractor, I used wordcount , locally as in to do the necessary modifications:

  1. Add another parameter in extractor-info.json file, in the schema field of parameters, if using wordcount, you will have to add it here
"DATASET_FILE_ID": {
        "type": "string",
        "title": "Dataset file ID",
        "description": "The Clowder file id of the dataset file to be used for inference",
        "format": "clowderFile",
        "showOnlyDatasetFiles": true
      }
  1. When you open the extractor and open the fileselector, you should only see the current folders and files in the dataset
    image

  2. Re-run the extractor but tis time set the field "showOnlyDatasetFiles" to false or remove it

  3. You should then see the complete clowder filesystem
    image

@Vismayak Vismayak force-pushed the 1086-file-ui-component-flag-current-files-in-datasets branch from bdd7563 to 2b8ef0e Compare June 10, 2024 17:43
Copy link
Member

@ddey2 ddey2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good and works as per expectation.

I have a slight diff suggestion. We are choosing a file from the tree viewer, I was wondering why the param name says 'Dataset file ID'? We are not entering any dataset fiel id here. Can we rename this to 'Dataset file', may be?
Screenshot 2024-06-12 at 12 44 22 PM

Copy link
Member

@longshuicy longshuicy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except minor suggestion everything else works well.

@longshuicy longshuicy merged commit e6724e8 into main Jun 13, 2024
@longshuicy longshuicy deleted the 1086-file-ui-component-flag-current-files-in-datasets branch June 13, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File UI Component Flag - To show only current files and folders in datasets

4 participants