Skip to content

Commit

Permalink
Merge pull request #116 from oarepo/stojanovic/fe-113-i18next-plugin-…
Browse files Browse the repository at this point in the history
…eslint

Stojanovic/fe 113 i18next plugin eslint
  • Loading branch information
mirekys authored Jan 12, 2024
2 parents 355f7f7 + 9f92ee6 commit 892122c
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 26 deletions.
2 changes: 1 addition & 1 deletion oarepo_ui/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def empty_record(self, resource_requestctx, **kwargs):
empty_data = dump_empty(self.api_config.schema)
files_field = getattr(self.api_config.record_cls, "files", None)
if files_field and isinstance(files_field, FilesField):
empty_data["files"] = {"enabled": False}
empty_data["files"] = {"enabled": True}
empty_data = deepmerge.always_merger.merge(
empty_data, copy.deepcopy(self.config.empty_record)
)
Expand Down
69 changes: 67 additions & 2 deletions oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/api/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export class OARepoDepositApiClient extends DepositApiClient {
*/
readDraft = async (draftLinks) => {
return this._createResponse(() => {
const response = this.axiosWithConfig.get(relativeUrl(draftLinks.self))
return this.recordSerializer.deserialize(response)
const response = this.axiosWithConfig.get(relativeUrl(draftLinks.self));
return this.recordSerializer.deserialize(response);
});
};

Expand Down Expand Up @@ -176,3 +176,68 @@ export class OARepoDepositApiClient extends DepositApiClient {
);
};
}

export class DepositFileApiClient {
constructor(additionalApiConfig) {
if (this.constructor === DepositFileApiClient) {
throw new Error("Abstract");
}
const additionalHeaders = _get(additionalApiConfig, "headers", {});
this.apiHeaders = Object.assign({}, BASE_HEADERS, additionalHeaders);

const apiConfig = {
withCredentials: true,
xsrfCookieName: "csrftoken",
xsrfHeaderName: "X-CSRFToken",
headers: this.apiHeaders.json,
};
this.axiosWithConfig = axios.create(apiConfig);
}

isCancelled(error) {
return axios.isCancel(error);
}

initializeFileUpload(initializeUploadUrl, filename) {
throw new Error("Not implemented.");
}

uploadFile(uploadUrl, file, onUploadProgress, cancel) {
throw new Error("Not implemented.");
}

finalizeFileUpload(finalizeUploadUrl) {
throw new Error("Not implemented.");
}

deleteFile(fileLinks) {
throw new Error("Not implemented.");
}
}

/**
* Default File API Client for deposits.
*/
export class OARepoDepositFileApiClient extends DepositFileApiClient {
_createResponse = async (axiosRequest) => {
let response;
try {
response = await axiosRequest();
const data = response.data || {};
return data;
} catch (error) {
return Promise.reject(error);
}
};

readDraftFiles = async (draft) => {
return this._createResponse(() => {
const response = this.axiosWithConfig.get(relativeUrl(draft.links.files));
return response;
});
};

deleteFile = (fileLinks) => {
return this.axiosWithConfig.delete(fileLinks.self);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const EDTFSingleDatePicker = ({
icon,
helpText,
required,
placeholderText,
placeholder,
calendarControlButtonClassName,
calendarControlIconName,
clearIconClassName,
Expand Down Expand Up @@ -249,6 +249,7 @@ export const EDTFSingleDatePicker = ({
fieldPath={fieldPath}
required={required}
autoComplete="off"
placeholder={placeholder}
label={<FieldLabel htmlFor={fieldPath} icon={icon} label={label} />}
icon={
field?.value ? (
Expand Down Expand Up @@ -281,7 +282,6 @@ export const EDTFSingleDatePicker = ({
{...props}
/>
)}
placeholderText={placeholderText}
{...datePickerProps}
/>
)}
Expand Down Expand Up @@ -310,7 +310,7 @@ EDTFSingleDatePicker.propTypes = {
helpText: PropTypes.string,
datePickerProps: PropTypes.object,
required: PropTypes.bool,
placeholderText: PropTypes.string,
placeholder: PropTypes.string,
calendarControlButtonClassName: PropTypes.string,
calendarControlIconName: PropTypes.string,
clearIconClassName: PropTypes.string,
Expand All @@ -320,7 +320,7 @@ EDTFSingleDatePicker.defaultProps = {
icon: "calendar",
helpText: i18next.t("Format: YYYY-MM-DD, YYYYY-MM or YYYY."),
required: false,
placeholderText: i18next.t(
placeholder: i18next.t(
"Write a date or click on the calendar icon to select it"
),
calendarControlButtonClassName: "calendar-control-button",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const MultilingualTextInput = ({
addButtonLabel,
lngFieldWidth,
showEmptyValue,
prefillLanguageWithDefaultLocale,
...uiProps
}) => {
const { defaultLocale } = useDefaultLocale();
Expand All @@ -43,7 +44,11 @@ export const MultilingualTextInput = ({
return (
<ArrayField
addButtonLabel={addButtonLabel}
defaultNewValue={getNewValue(defaultNewValue, usedLanguages)}
defaultNewValue={
prefillLanguageWithDefaultLocale
? getNewValue(defaultNewValue, usedLanguages)
: defaultNewValue
}
fieldPath={fieldPath}
label={
<FieldLabel htmlFor={fieldPath} icon={labelIcon ?? ""} label={label} />
Expand Down Expand Up @@ -106,6 +111,7 @@ MultilingualTextInput.propTypes = {
rich: PropTypes.bool,
defaultNewValue: PropTypes.object,
showEmptyValue: PropTypes.bool,
prefillLanguageWithDefaultLocale: PropTypes.bool,
};

MultilingualTextInput.defaultProps = {
Expand All @@ -117,4 +123,5 @@ MultilingualTextInput.defaultProps = {
label: undefined,
addButtonLabel: i18next.t("Add another language"),
showEmptyValue: false,
prefillLanguageWithDefaultLocale: false,
};
Loading

0 comments on commit 892122c

Please sign in to comment.