Skip to content

Commit

Permalink
set files to enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducica committed Dec 6, 2023
1 parent 59fd500 commit aaa6773
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion oarepo_ui/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def empty_record(self, resource_requestctx, **kwargs):
record = dump_empty(self.api_config.schema)
files_field = getattr(self.api_config.record_cls, "files", None)
if files_field and isinstance(files_field, FilesField):
record["files"] = {"enabled": False}
record["files"] = {"enabled": True}
record = deepmerge.always_merger.merge(
record, copy.deepcopy(self.config.empty_record)
)
Expand Down
14 changes: 10 additions & 4 deletions oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ export const useDepositApiClient = (
export const useDepositFileApiClient = (file, baseApiClient) => {
const formik = useFormikContext();

const { isSubmitting, values, setSubmitting, setFieldValue } = formik;
const { isSubmitting, values, setSubmitting, setFieldValue, setValues } =
formik;

const apiClient = baseApiClient
? new baseApiClient()
Expand All @@ -344,11 +345,16 @@ export const useDepositFileApiClient = (file, baseApiClient) => {
async function read(draft) {
return await apiClient.readDraftFiles(draft);
}

async function _delete() {
// TODO: The issue is that files state is in FileUploader component, but the delete function is here=> not sure if best to keep delete func in nrdocs in uploader
// or like this. Or maybe to keep file state in formik's state similar like we keep the record and then delete this key before submitting
async function _delete(file, handleDeletionInUi) {
setSubmitting(true);

try {
let response = await apiClient.deleteFile(file?.links?.self);
let response = await apiClient.deleteFile(file?.links);
if (response.status === 204 && handleDeletionInUi) {
handleDeletionInUi(file);
}
return response;
} catch (error) {
setFieldValue(
Expand Down

0 comments on commit aaa6773

Please sign in to comment.