-
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
11 changed files
with
195 additions
and
65 deletions.
There are no files selected for viewing
Empty file.
78 changes: 78 additions & 0 deletions
78
ui/src/app/metadata/domain/filter/component/MetadataFilterVersionContext.js
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,78 @@ | ||
| import React from 'react'; | ||
| import { MetadataFilterTypes } from '../index'; | ||
|
|
||
| export const isAdditionalFilter = (type) => MetadataFilterTypes.indexOf(type) > -1; | ||
|
|
||
| export const getVersionModelFilterPluginsFn = (model, kind) => { | ||
| const filters = kind === 'provider' ? | ||
| model.metadataFilters ? model.metadataFilters.filter(filter => MetadataFilterTypes.indexOf(filter['@type']) === -1) : | ||
| [] : null; | ||
| return filters; | ||
| }; | ||
|
|
||
| export const getComparisonModelsFilteredFn = (models) => models.map((model) => { | ||
| return ({ | ||
| ...model, | ||
| metadataFilters: getVersionModelFilterPluginsFn( | ||
| model, | ||
| model.hasOwnProperty('@type') ? model.hasOwnProperty('metadataFilters') ? 'provider' : 'filter' : 'resolver' | ||
| ) | ||
| }); | ||
| }); | ||
|
|
||
| export const getVersionModelFiltersFn = | ||
| (model, kind) => kind === 'provider' ? | ||
| model.metadataFilters ? model.metadataFilters.filter(filter => isAdditionalFilter(filter['@type'])) : | ||
| [] : null; | ||
|
|
||
| export const getComparisonFilterOrderedFn = (list) => | ||
| list.map(models => | ||
| models.map(filter => | ||
| ({ | ||
| ...filter, | ||
| comparable: list | ||
| .reduce((acc, v) => acc.concat(v), []) | ||
| .map(v => v.resourceId) | ||
| .some((id, index, coll) => { | ||
| return coll.indexOf(filter.resourceId) !== coll.lastIndexOf(filter.resourceId); | ||
| }) | ||
| }) | ||
| )); | ||
|
|
||
| export const getComparisonFilterListFn = (models) => models.map(m => getVersionModelFiltersFn(m, 'provider')); | ||
|
|
||
| export const getComparisonFilterConfiguration = (filters, dates) => { | ||
| const rows = filters.reduce((num, version) => version.length > num ? version.length : num, 0); | ||
| const range = [...Array(rows).keys()]; | ||
| return { | ||
| dates, | ||
| filters: range.reduce((collection, index) => { | ||
| const val = filters.map(version => version[index]); | ||
| collection[index] = val; | ||
| return collection; | ||
| }, []) | ||
| }; | ||
| } | ||
|
|
||
| export function useComparisonFilterList(models) { | ||
| return React.useMemo(() => getComparisonFilterListFn(models), [models]); | ||
| } | ||
|
|
||
| export function useOrderedComparisonFilterList (models) { | ||
| const data = useComparisonFilterList(models); | ||
|
|
||
| return React.useMemo(() => getComparisonFilterOrderedFn(data), [data]); | ||
| } | ||
|
|
||
| export function useComparisonFilterConfiguration (models, dates) { | ||
| const filters = useOrderedComparisonFilterList(models); | ||
|
|
||
| return React.useMemo(() => getComparisonFilterConfiguration(filters, dates), [filters, dates]); | ||
| } | ||
|
|
||
|
|
||
| export function MetadataFilterVersionContext ({ models, dates, children }) { | ||
| const config = useComparisonFilterConfiguration(models, dates); | ||
|
|
||
| return (<>{children(config)}</>); | ||
| } |
82 changes: 82 additions & 0 deletions
82
ui/src/app/metadata/domain/filter/component/MetadataFilterVersionList.js
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,82 @@ | ||
| import { faCheckSquare, faSquare } from '@fortawesome/free-solid-svg-icons'; | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
| import React from 'react'; | ||
| import FormattedDate from '../../../../core/components/FormattedDate'; | ||
| import Translate from '../../../../i18n/components/translate'; | ||
| import { usePropertyWidth } from '../../../component/properties/hooks'; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| export function MetadataFilterVersionList ({ configuration, columns }) { | ||
|
|
||
| const width = usePropertyWidth(columns); | ||
|
|
||
| const [comparing, setComparing] = React.useState(false); | ||
| const [selected, setSelected] = React.useState(null); | ||
|
|
||
| return ( | ||
| <React.Fragment> | ||
| { configuration && configuration.dates.length > 0 && | ||
| <React.Fragment> | ||
| <div className="d-flex border-bottom border-light border-2 py-2"> | ||
| <strong style={{width}}> | ||
| <Translate value={ comparing ? `label.order` : `label.option` } /> | ||
| </strong> | ||
| {configuration.dates.map(d => | ||
| <strong style={{width}} > | ||
| <FormattedDate date={d} time={true} /> | ||
| </strong> | ||
| ) } | ||
| </div> | ||
| {configuration.filters.map((version, i) => | ||
| <div className="d-flex border-bottom border-light"> | ||
| <div style={{width}} className="py-2"> | ||
| { i + 1 } | ||
| </div> | ||
| {version.map((filter, n) => | ||
| <div style={{width}} className="border-primary"> | ||
| {filter ? | ||
| <div className={`p-2 d-flex align-items-center ${((n % 2 === 0) && selected !== filter.resourceId) ? 'bg-lighter' : 'bg-primary-light'}`}> | ||
| <div className="w-50"> | ||
| <p className="mb-0">{ filter.name }</p> | ||
| <p className="mb-0 text-muted">{ filter['@type'] }</p> | ||
| </div> | ||
| { filter.comparable && | ||
| <button className="btn btn-link mx-auto" onClick={() => setSelected(filter.resourceId)}> | ||
| <FontAwesomeIcon icon={ selected === filter.resourceId ? faCheckSquare : faSquare } size="lg" /> | ||
| <span className="sr-only">Compare</span> | ||
| </button> | ||
| } | ||
| </div> | ||
| : | ||
| <div className="p-2 w-100">-</div> | ||
| } | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) } | ||
| { configuration && | ||
| <React.Fragment> | ||
| {configuration.filters.length < 1 ? | ||
| <div className="alert alert-info m-4"> | ||
| <h3><Translate value="message.no-filters">No Filters</Translate></h3> | ||
| <p><Translate value="message.no-filters-added">No filters have been added to this Metadata Provider</Translate></p> | ||
| </div> | ||
| : | ||
| <div className="d-flex justify-content-end my-2"> | ||
| <button className="btn btn-primary" disabled={!selected} onClick={() => setComparing()}> | ||
| <Translate value="label.compare-selected">Compare Selected</Translate> | ||
| </button> | ||
| </div> | ||
| } | ||
| </React.Fragment> | ||
| } | ||
| </React.Fragment> | ||
| } | ||
| </React.Fragment> | ||
|
|
||
|
|
||
|
|
||
| ); | ||
| } |
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,8 @@ | ||
| import React from 'react'; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| export function ComparisonContext () { | ||
| return (<></>); | ||
| } |
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