Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deposit-ui: align license with funding modal #1946

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import {
EmptyResults,
Error,
InvenioSearchApi,
Pagination,
ReactSearchKit,
ResultsLoader,
Toggle,
} from "react-searchkit";
import { Button, Form, Grid, Menu, Modal } from "semantic-ui-react";
import { Button, Container, Form, Grid, Menu, Modal } from "semantic-ui-react";
import * as Yup from "yup";
import { LicenseFilter } from "./LicenseFilter";
import { LicenseResults } from "./LicenseResults";
import { LicenseSearchBar } from "./LicenseSearchBar";
import { NoLicenseResults } from "./NoLicenseResults";

const overriddenComponents = {
"SearchFilters.Toggle": LicenseFilter,
Expand All @@ -50,6 +52,7 @@ const LicenseSchema = Yup.object().shape({
export class LicenseModal extends Component {
state = {
open: false,
mode: ModalTypes.STANDARD,
};

openModal = () => {
Expand All @@ -60,12 +63,17 @@ export class LicenseModal extends Component {
this.setState({ open: false });
};

setMode = (mode) => {
this.setState({ mode: mode });
};

onSubmit = (values, formikBag) => {
// We have to close the modal first because onLicenseChange and passing
// license as an object makes React get rid of this component. Otherwise
// we get a memory leak warning.
const { onLicenseChange } = this.props;
this.closeModal();
this.setMode(this.mode);
onLicenseChange(values.selectedLicense);
formikBag.resetForm();
};
Expand Down Expand Up @@ -101,27 +109,36 @@ export class LicenseModal extends Component {
>
{({ handleSubmit, resetForm }) => (
<Modal
onOpen={() => this.openModal()}
role="dialog"
centered={false}
onOpen={() => {
this.openModal();
this.setMode(mode);
}}
open={open}
trigger={trigger}
trigger={React.cloneElement(trigger, {
"aria-expanded": open,
"aria-haspopup": "dialog",
})}
onClose={() => {
this.closeModal();
resetForm();
this.setMode(ModalTypes.STANDARD);
this.closeModal();
}}
closeIcon
closeOnDimmerClick={false}
>
<Modal.Header as="h2" className="pt-10 pb-10">
{action === ModalActions.ADD
? i18next.t(`Add {{mode}} license`, {
mode: mode,
mode: this.state.mode,
})
: i18next.t(`Change {{mode}} license`, {
mode: mode,
mode: this.state.mode,
})}
</Modal.Header>
<Modal.Content scrolling>
{mode === ModalTypes.STANDARD && (
<Modal.Content>
{this.state.mode === ModalTypes.STANDARD && (
<OverridableContext.Provider value={overriddenComponents}>
<ReactSearchKit
searchApi={searchApi}
Expand All @@ -133,7 +150,7 @@ export class LicenseModal extends Component {
<Grid.Row>
<Grid.Column width={8} floated="left" verticalAlign="middle">
<LicenseSearchBar
placeholder={i18next.t("Search")}
placeholder={i18next.t("Search for licenses")}
autofocus
actionProps={{
icon: "search",
Expand Down Expand Up @@ -168,7 +185,7 @@ export class LicenseModal extends Component {
</Grid.Column>
</Grid.Row>
<Grid.Row verticalAlign="middle">
<Grid.Column>
<Grid.Column width={16} className="pb-0">
<ResultsLoader>
<EmptyResults />
<Error />
Expand All @@ -178,13 +195,28 @@ export class LicenseModal extends Component {
})}
/>
</ResultsLoader>
<Container textAlign="center" className="rel-mb-1">
<Pagination />
</Container>
</Grid.Column>
<Grid.Column
width={16}
textAlign="center"
className="pt-0 pb-0"
>
<NoLicenseResults
switchToCustom={() => {
resetForm();
this.setMode(ModalTypes.CUSTOM);
}}
/>
</Grid.Column>
</Grid.Row>
</Grid>
</ReactSearchKit>
</OverridableContext.Provider>
)}
{mode === ModalTypes.CUSTOM && (
{this.state.mode === ModalTypes.CUSTOM && (
<Form>
<TextField
label={i18next.t("Title")}
Expand All @@ -211,10 +243,10 @@ export class LicenseModal extends Component {
name="cancel"
onClick={() => {
resetForm();
this.setMode(mode);
this.closeModal();
}}
icon="remove"
labelPosition="left"
content={i18next.t("Cancel")}
floated="left"
/>
Expand All @@ -223,7 +255,6 @@ export class LicenseModal extends Component {
onClick={(event) => handleSubmit(event)}
primary
icon="checkmark"
labelPosition="left"
content={
action === ModalActions.ADD
? i18next.t("Add license")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is part of Invenio-RDM-Records
// Copyright (C) 2021-2024 CERN.
// Copyright (C) 2021 Northwestern University.
// Copyright (C) 2025 ZBW – Leibniz-Informationszentrum Wirtschaft.
//
// Invenio is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import PropTypes from "prop-types";
import React from "react";
import { Segment } from "semantic-ui-react";
import { i18next } from "@translations/invenio_rdm_records/i18next";

export function NoLicenseResults({ switchToCustom }) {
return (
<Segment
basic
content={
<p>
{i18next.t("Did not find your license? ")}
<a
href="/"
onClick={(e) => {
e.preventDefault();
switchToCustom();
}}
>
{i18next.t("Add a custom license.")}
</a>
</p>
}
/>
);
}

NoLicenseResults.propTypes = {
switchToCustom: PropTypes.func.isRequired,
};