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

added toggler to disable box #55

Open
wants to merge 8 commits 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
24 changes: 24 additions & 0 deletions src/components/box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { openConfirmModal } from '../../helpers/modal';
import { copyObject, isEqual } from '../../helpers/object';
import { DictionaryEntity } from '../../models/Dictionary';
import '../../styles/box.scss';
import '../../styles/toggler.scss';

interface Props {
box: BoxEntity;
Expand Down Expand Up @@ -61,6 +62,7 @@ const Box = (
'box',
isBoxActive ? 'active' : null,
isHidden ? 'hidden' : null,
box.spec.disabled ? 'disabled' : null,
);

React.useEffect(() => {
Expand Down Expand Up @@ -132,6 +134,22 @@ const Box = (
const splitedImageName = imageName.split('/');
const slicedImageName = splitedImageName.slice(-(splitedImageName.length - 1)).join('/');

const toggleDisabled = () => {
const copyBox = copyObject(box);
if (box.spec.disabled) {
copyBox.spec.disabled = undefined;
} else {
copyBox.spec.disabled = true;
}
const temp = schemasStore.boxes
.map((value, index) => {
return { value, index };
})
.find(b => b.value.name === copyBox.name);
if (temp) schemasStore.boxes[temp.index].spec.disabled = copyBox.spec.disabled;
schemasStore.saveEntityChanges(copyBox, 'update');
};

return (
<>
<div
Expand Down Expand Up @@ -159,6 +177,12 @@ const Box = (
)}
<span className='box__title'>{box.name}</span>
<div className='box__buttons-wrapper'>
<div className='toggler'>
<div
className={`toggler__bar ${box.spec.disabled ? 'off' : 'on'}`}
onClick={toggleDisabled}
/>
</div>
<button className='box__button filter' onClick={filterRelatedBoxes}>
<i className='box__button-icon' />
</button>
Expand Down
5 changes: 1 addition & 4 deletions src/components/box/BoxSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ const BoxSettings = ({ box, onClose, setEditablePin, setEditableDictionary }: Bo
savePins(pinsList);
}, [pinsList]);

useEffect(() => {
saveConfig(boxConfigInput.value);
}, [boxConfigInput.value]);

useOutsideClickListener(modalRef, (e: MouseEvent) => {
if (
!e
Expand Down Expand Up @@ -251,6 +247,7 @@ const BoxSettings = ({ box, onClose, setEditablePin, setEditableDictionary }: Bo
};

const submit = async () => {
saveConfig(boxConfigInput.value);
if (
[
imageNameInput,
Expand Down
1 change: 1 addition & 0 deletions src/models/Box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DictionaryRelation } from './Dictionary';

export interface BoxEntity extends FileBase {
spec: {
['disabled']?: true | undefined;
['custom-config']?: {
[prop: string]: string;
};
Expand Down
20 changes: 5 additions & 15 deletions src/store/SchemasStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,13 @@ export default class SchemasStore {
entity: BoxEntity | LinksDefinition | DictionaryLinksEntity | DictionaryEntity,
operation: 'add' | 'update' | 'remove',
) => {
if (
!this.preparedRequests.some(
request =>
request.payload.name === entity.name &&
request.operation === operation &&
!hasChanges(request.payload, entity),
)
) {
this.preparedRequests.push({
this.preparedRequests = [
...this.preparedRequests.filter(req => req.payload.name !== entity.name),
{
operation,
payload: entity,
});
}

function hasChanges<T extends object>(obj1: T, obj2: T) {
return Object.keys(diff(obj1, obj2)).length > 0;
}
},
];
};

@action
Expand Down
6 changes: 5 additions & 1 deletion src/styles/box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
filter: blur(0.5px);
}

&.disabled {
opacity: 0.5;
}

&__header {
min-height: 25px;
width: 100%;
display: flex;
flex-wrap: wrap;
Expand Down Expand Up @@ -125,6 +128,7 @@
}

&__buttons-wrapper {
min-height: 25px;
margin-left: auto;
display: flex;
gap: 7.5px;
Expand Down
3 changes: 2 additions & 1 deletion src/styles/group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@

display: flex;
flex-direction: column;
overflow-y: scroll;
overflow-y: auto;
overflow-x: hidden;
padding: 0 10px;
padding-bottom: 12px;
}
Expand Down
60 changes: 60 additions & 0 deletions src/styles/toggler.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/******************************************************************************
* Copyright 2020-2020 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

@import './common/vars';


.toggler {
display: flex;
align-items: center;

&__bar {
cursor: pointer;
position: relative;
box-sizing: border-box;
width: 20px;
height: 10px;
margin: 0 2px;
border: solid transparent 1px;
border-radius: 6px;
&:before {
position: absolute;
content: '';
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #7a99b8;
top: 50%;
transform: translateY(-50%);
transition: left ease-in-out 240ms;
}
}
.on {
background-color: white;
&:before {
left: calc(100% - 9px);
}
}
.off {
background-color: #617a93;
opacity: 0.9;
&:before {
background-color: white;
opacity: 0.5;
left: 1px;
}
}
}