-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
180 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { useLocation, useParams } from 'react-router'; | ||
import { useMetadataFilters } from '../hooks/api'; | ||
|
||
export const MetadataFilterContext = React.createContext(); | ||
|
||
/*eslint-disable react-hooks/exhaustive-deps*/ | ||
export function MetadataFilterSelector({ children }) { | ||
|
||
let { id, filterId } = useParams(); | ||
const location = useLocation(); | ||
|
||
React.useEffect(() => { | ||
if (location.state?.refresh) { | ||
loadFilter(id); | ||
} | ||
}, [location, id]) | ||
|
||
const { get, response } = useMetadataFilters(id, { | ||
cachePolicy: 'no-cache' | ||
}); | ||
|
||
const [filter, setFilter] = React.useState([]); | ||
|
||
async function loadFilter(filterId) { | ||
const f = await get(`/${filterId}`); | ||
if (response.ok) { | ||
setFilter(f); | ||
} | ||
} | ||
React.useEffect(() => { loadFilter(filterId) }, [id]); | ||
|
||
return ( | ||
<MetadataFilterContext.Provider value={filter}> | ||
{filter && filter.version && | ||
<React.Fragment>{children(filter)}</React.Fragment> | ||
} | ||
</MetadataFilterContext.Provider> | ||
); | ||
} | ||
|
||
export default MetadataFilterSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { faSave, faSpinner } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import React from 'react'; | ||
import { Prompt, useHistory, useParams } from 'react-router'; | ||
import Translate from '../../i18n/components/translate'; | ||
import { MetadataFilterEditor } from '../editor/MetadataFilterEditor'; | ||
import { MetadataForm } from '../hoc/MetadataFormContext'; | ||
import { MetadataSchema } from '../hoc/MetadataSchema'; | ||
import { useMetadataFilters } from '../hooks/api'; | ||
import { MetadataFilterSelector } from '../hoc/MetadataFilterSelector'; | ||
|
||
export function EditFilter() { | ||
|
||
const { id, filterId } = useParams(); | ||
const history = useHistory(); | ||
|
||
const { put, response, loading } = useMetadataFilters(id, {}); | ||
|
||
const [blocking, setBlocking] = React.useState(false); | ||
|
||
async function save(metadata) { | ||
await put(`${filterId}`, metadata); | ||
if (response.ok) { | ||
gotoDetail({ refresh: true }); | ||
} | ||
}; | ||
|
||
const cancel = () => { | ||
gotoDetail(); | ||
}; | ||
|
||
const gotoDetail = (state = null) => { | ||
setBlocking(false); | ||
history.push(`/metadata/provider/${id}`, state); | ||
}; | ||
|
||
return ( | ||
<div className="container-fluid p-3"> | ||
<Prompt | ||
when={blocking} | ||
message={location => | ||
`message.unsaved-editor` | ||
} | ||
/> | ||
<section className="section" tabIndex="0"> | ||
<div className="section-header bg-info px-4 py-2 text-white"> | ||
<span className="display-6"><Translate value="label.edit-filter">Edit filter</Translate></span> | ||
</div> | ||
<div className="section-body p-4 border border-top-0 border-info"> | ||
<MetadataFilterSelector> | ||
{(filter) => { | ||
return ( | ||
<MetadataSchema type={filter['@type']}> | ||
<MetadataForm initial={filter}> | ||
<React.Fragment> | ||
<div className="container-fluid"> | ||
<div className="form-inline"> | ||
<label htmlFor="staticType" className="mr-3">Filter Type</label> | ||
<input type="text" readOnly disabled className="form-control" id="staticType" value={filter['@type']} /> | ||
</div> | ||
</div> | ||
<hr /> | ||
<MetadataFilterEditor> | ||
{(filter, isInvalid) => | ||
<div className="d-flex justify-content-end"> | ||
<button className="btn btn-info mr-2" | ||
type="button" | ||
onClick={() => save(filter)} | ||
disabled={isInvalid || loading} | ||
aria-label="Save changes to the metadata source. You will return to the dashboard"> | ||
<FontAwesomeIcon icon={loading ? faSpinner : faSave} pulse={loading} /> | ||
<Translate value="action.save">Save</Translate> | ||
</button> | ||
<button className="btn btn-secondary" | ||
type="button" | ||
onClick={() => cancel()} aria-label="Cancel changes, go back to dashboard"> | ||
<Translate value="action.cancel">Cancel</Translate> | ||
</button> | ||
</div> | ||
} | ||
</MetadataFilterEditor> | ||
</React.Fragment> | ||
</MetadataForm> | ||
</MetadataSchema> | ||
); | ||
}} | ||
</MetadataFilterSelector> | ||
</div> | ||
</section> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters