Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Disable intent feature & Fix previousId issue #208

Merged
merged 2 commits into from
Mar 15, 2019
Merged
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
12 changes: 8 additions & 4 deletions backend/src/middlewares/openNLX.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,14 @@ class OpenNLXMiddleware {
const bots = this.mainControllers.getBots();
let intents = await bots.getIntents(botId, versionId);
intents = intents.map((int) => {
const intentWithPrevious = int;
intentWithPrevious.previous = int.previousId;
delete intentWithPrevious.previousId;
return intentWithPrevious;
const toOpenNLXIntent = int;
if (int.previousId && int.previousId.length > 0) {
toOpenNLXIntent.previous = int.previousId;
delete toOpenNLXIntent.previousId;
}
toOpenNLXIntent.deactivated =
int.state && int.state === "deactivated";
return toOpenNLXIntent;
});
this.openNLX.deleteAllIntents(botId, version);
this.openNLX.setIntents(botId, version, intents);
Expand Down
20 changes: 19 additions & 1 deletion front/src/shared/components/intentDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Zrmc, {
ListItemMeta,
MenuItem,
Select,
Switch,
TextField,
} from "zrmc";
import { ExpansionPanel } from "zoapp-ui";
Expand All @@ -28,6 +29,7 @@ const IntentDetail = ({
displayCondition,
displayHelp,
getIntentNameById,
onDisable,
onSelect,
onAction,
onHelp,
Expand All @@ -40,6 +42,8 @@ const IntentDetail = ({
}) => {
const { name, input, output } = intent;
const topic = intent.topic && intent.topic.length > 0 ? intent.topic : "*";
const isDeactivated = intent.state && intent.state === "deactivated";

const { previousId } = intent;
let help = "";
if (displayHelp > -1) {
Expand Down Expand Up @@ -147,6 +151,19 @@ const IntentDetail = ({
</Button>
</ListItemMeta>
</ListItem>
<ListItem icon="link">
Deactivate
<ListItemMeta style={{ minWidth: "320px", display: "flex" }}>
<Switch
id="deactivate"
style={{ margin: "0 auto" }}
checked={isDeactivated}
onChange={(isDisabled) => {
onDisable(isDisabled);
}}
/>
</ListItemMeta>
</ListItem>
</List>
</ExpansionPanel>
</div>
Expand All @@ -164,6 +181,7 @@ IntentDetail.defaultProps = {
IntentDetail.propTypes = {
intent: PropTypes.shape({}).isRequired,
getIntentNameById: PropTypes.func.isRequired,
onDisable: PropTypes.func.isRequired,
onSelect: PropTypes.func.isRequired,
onAction: PropTypes.func.isRequired,
onHelp: PropTypes.func,
Expand Down Expand Up @@ -216,7 +234,7 @@ export const displayActionEditor = (
label="Select an intent"
style={{ width: "100%" }}
onSelected={(t) => {
setInput({ value: t !== "default" ? t : null });
setInput({ value: t !== "default" ? t : "" });
}}
>
{parameters.options.map((int) => (
Expand Down
12 changes: 12 additions & 0 deletions front/src/shared/containers/builder/intentContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,18 @@ class IntentContainer extends Component {
) || { name: null };
return intentName;
}}
onDisable={(isDisabled) => {
const { selectedIntent } = this.state;
if (isDisabled) {
selectedIntent.state = "deactivated";
} else {
selectedIntent.state = "";
}
this.props.appUpdateIntent(
this.props.selectedBotId,
selectedIntent,
);
}}
onSelect={this.handleActions}
onAction={this.handleDoActions}
onHelp={this.handleHelp}
Expand Down
8 changes: 6 additions & 2 deletions front/src/shared/containers/explorerContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ class ExplorerContainer extends Component {
n.push(
<div key="i_text">
{intent.notSaved ? <div className="item_notsaved" /> : ""}
<span style={{ margin: "0 14px 0 0px" }}>#</span>
{intent.name}
<span
style={intent.state === "deactivated" ? { opacity: "0.5" } : {}}
>
<span style={{ margin: "0 14px 0 0px" }}>#</span>
{intent.name}
</span>
</div>,
);
n.push(
Expand Down
112 changes: 112 additions & 0 deletions front/tests/shared/components/__snapshots__/intentDetail.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,62 @@ exports[`components/intentDetail can render intent with special characters corre
</button>
</span>
</li>
<li
className="mdc-list-item"
onKeyPress={[Function]}
role="menuitem"
>
<i
aria-hidden="true"
className="mdc-list-item__graphic material-icons"
>
link
</i>
Deactivate
<span
className="mdc-list-item__meta"
onClick={null}
onKeyUp={[Function]}
role="button"
style={
Object {
"display": "flex",
"minWidth": "320px",
}
}
tabIndex="0"
>
<div
className="mdc-switch"
onClick={[Function]}
style={
Object {
"margin": "0 auto",
}
}
>
<div
className="mdc-switch__track"
/>
<div
className="mdc-switch__thumb-underlay"
>
<div
className="mdc-switch__thumb"
>
<input
checked={false}
className="mdc-switch__native-control"
disabled={false}
id="deactivate"
role="switch"
type="checkbox"
/>
</div>
</div>
</div>
</span>
</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -1089,6 +1145,62 @@ exports[`components/intentDetail renders correctly 1`] = `
</button>
</span>
</li>
<li
className="mdc-list-item"
onKeyPress={[Function]}
role="menuitem"
>
<i
aria-hidden="true"
className="mdc-list-item__graphic material-icons"
>
link
</i>
Deactivate
<span
className="mdc-list-item__meta"
onClick={null}
onKeyUp={[Function]}
role="button"
style={
Object {
"display": "flex",
"minWidth": "320px",
}
}
tabIndex="0"
>
<div
className="mdc-switch"
onClick={[Function]}
style={
Object {
"margin": "0 auto",
}
}
>
<div
className="mdc-switch__track"
/>
<div
className="mdc-switch__thumb-underlay"
>
<div
className="mdc-switch__thumb"
>
<input
checked={false}
className="mdc-switch__native-control"
disabled={false}
id="deactivate"
role="switch"
type="checkbox"
/>
</div>
</div>
</div>
</span>
</li>
</ul>
</div>
</div>
Expand Down