Skip to content

Commit

Permalink
Implemented bundles for sources
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 7, 2021
1 parent c35bfd7 commit 9319c71
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/core/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Dropdown from 'react-bootstrap/Dropdown';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { faTh, faSignOutAlt, faPlusCircle, faCube, faCubes, faUsersCog, faSpinner, faUserCircle, faCog, faFileArchive, faUserTag, faBoxOpen, faTags, faIdBadge } from '@fortawesome/free-solid-svg-icons';
import { faTh, faSignOutAlt, faPlusCircle, faCube, faCubes, faUsersCog, faSpinner, faUserCircle, faCog, faBoxOpen, faTags, faIdBadge } from '@fortawesome/free-solid-svg-icons';

import Translate from '../../i18n/components/translate';
import { useTranslator } from '../../i18n/hooks';
Expand Down
55 changes: 40 additions & 15 deletions ui/src/app/form/component/widgets/AttributeReleaseWidget.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import Form from "react-bootstrap/Form";
import intersection from 'lodash/intersection';
import Translate from "../../../i18n/components/translate";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCheck, faTimes } from "@fortawesome/free-solid-svg-icons";
import Button from 'react-bootstrap/Button';
import { useTranslator } from "../../../i18n/hooks";

const selectValue = (value, selected, all) => {
const at = all.indexOf(value);
Expand Down Expand Up @@ -71,13 +71,49 @@ const AttributeReleaseWidget = ({
onChange(update);
}

const onUncheckBundle = (option) => {
const all = (enumOptions).map(({ value }) => value);
let update = [
...value
];
(option.value).forEach(v => update = deselectValue(v, update, all));

onChange(update);
}

const onClearAll = () => {
onChange([]);
}

const attrs = React.useMemo(() => enumOptions.filter(e => !(typeof e.value === 'string' ? false : true)), [enumOptions]);
const bundles = React.useMemo(() => enumOptions.filter(e => (typeof e.value === 'string' ? false : true)), [enumOptions]);

const bundlelist = React.useMemo(() => bundles.map((b) => (
{
...b,
selected: intersection(b.value, value).length === b.value.length
}
)), [bundles, value]);

return (
<fieldset>
<legend><Translate value={label || schema.title} /></legend>
{bundles && bundles.length > 0 &&
<ul class="list-group list-group-flush">
{(bundlelist).map((option) => (
<li class="list-group-item d-flex justify-content-between px-1">
<strong>{option.label}</strong>
<Button variant={option.selected ? 'outline-primary' : 'primary'} size="sm"
onClick={() => option.selected ? onUncheckBundle(option) : onCheckBundle(option) }
>
<span className="sr-only"><Translate value="action.select">Select</Translate></span>
<FontAwesomeIcon icon={faCheck} className="" />
</Button>
</li>
))}
</ul>
}

<table className="table table-striped table-sm">
<thead>
<tr className="table-secondary">
Expand All @@ -86,25 +122,15 @@ const AttributeReleaseWidget = ({
</tr>
</thead>
<tbody>
{(enumOptions).map((option, index) => {
{(attrs).map((option, index) => {
const checked = value.indexOf(option.value) !== -1;
const itemDisabled =
enumDisabled && (enumDisabled).indexOf(option.value) !== -1;
const bundled = typeof option.value === 'string' ? false : true;
return (
<tr key={index} className={bundled ? 'bg-secondary border-bottom py-4 text-white' : ''}>
<td className="align-middle">{bundled ?
<strong>{option.label}</strong>
:
<Translate value={`label.attribute-${option.label}`}>{option.label}</Translate>
}</td>
<tr key={index}>
<td className="align-middle"><Translate value={`label.attribute-${option.label}`}>{option.label}</Translate></td>
<td className="">
<fieldset className="d-flex justify-content-end">
{bundled ?
<Button variant="outline-primary bg-light" size="sm"
onClick={() => onCheckBundle(option)}
>Select</Button>
:
<div className="custom-control custom-checkbox">
<Form.Check
custom
Expand All @@ -120,7 +146,6 @@ const AttributeReleaseWidget = ({
disabled={disabled || itemDisabled || readonly}
/>
</div>
}
</fieldset>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/hoc/attribute/AttributeBundleApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import API_BASE_PATH from '../../../App.constant';
import { DeleteConfirmation } from '../../../core/components/DeleteConfirmation';
import { createNotificationAction, NotificationContext } from '../../../notifications/hoc/Notifications';

const api = '/custom/entity/bundles'
const api = '/custom/entity/bundles';

export function AttributeBundleApi({ id, children }) {

Expand Down
1 change: 1 addition & 0 deletions ui/src/app/metadata/hoc/attribute/AttributeBundleList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function AttributeBundleList({ load, children }) {

const [bundles, setBundles] = React.useState([]);

/*eslint-disable react-hooks/exhaustive-deps*/
React.useEffect(() => {
load((list) => setBundles(list));
}, []);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { useParams } from 'react-router-dom';

export function AttributeBundleSelector({ id, find, children }) {
const [bundle, setBundle] = React.useState([]);

/*eslint-disable react-hooks/exhaustive-deps*/
React.useEffect(() => {
find(id, (item) => setBundle(item));
}, []);
Expand Down
3 changes: 0 additions & 3 deletions ui/src/app/metadata/view/MetadataAttributeBundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import Button from 'react-bootstrap/Button';
import { Link } from 'react-router-dom';

import { Translate } from '../../i18n/components/translate';
import { useTranslator } from '../../i18n/hooks';

import { AttributeBundleApi } from '../hoc/attribute/AttributeBundleApi';

import { AttributeBundleList } from '../hoc/attribute/AttributeBundleList';

export function MetadataAttributeBundles({ entities, onDelete }) {

const translator = useTranslator();

return (
<AttributeBundleApi>
{(load, find, create, update, remove, loading) =>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/wizard/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const WizardContext = React.createContext();
const { Provider, Consumer } = WizardContext;

const initialState = {
current: 'attribute',
current: 'common',
disabled: false,
loading: false
};
Expand Down

0 comments on commit 9319c71

Please sign in to comment.