Skip to content

Commit 8306b85

Browse files
Merge pull request #190 from zenml-io/QA-Fixes
Qa fixes
2 parents e853fd8 + a42de4d commit 8306b85

File tree

1 file changed

+86
-4
lines changed
  • src/ui/layouts/stacks/StackDetail/Configuration

1 file changed

+86
-4
lines changed

src/ui/layouts/stacks/StackDetail/Configuration/index.tsx

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ import { useService } from './useService';
2727
import { StackBox } from '../../../common/StackBox';
2828
import { SidePopup } from '../../CreateStack/ListForAll/SidePopup';
2929
import { NonEditableConfig } from '../../../NonEditableConfig';
30+
import { useDispatch, useSelector } from '../../../../hooks';
31+
import {
32+
sessionSelectors,
33+
userSelectors,
34+
workspaceSelectors,
35+
} from '../../../../../redux/selectors';
36+
import { showToasterAction, stacksActions } from '../../../../../redux/actions';
37+
import { toasterTypes } from '../../../../../constants';
38+
import axios from 'axios';
3039
// import { SidePopup } from '../../../common/SidePopup';
3140

3241
export const Configuration: React.FC<{
@@ -36,6 +45,12 @@ export const Configuration: React.FC<{
3645
}> = ({ stackId, tiles, fetching = false }) => {
3746
// const dispatch = useDispatch();
3847
const { stack } = useService({ stackId });
48+
const user = useSelector(userSelectors.myUser);
49+
const authToken = useSelector(sessionSelectors.authenticationToken);
50+
const selectedWorkspace = useSelector(workspaceSelectors.selectedWorkspace);
51+
const workspaces = useSelector(workspaceSelectors.myWorkspaces);
52+
const [loading, setLoading] = useState(false);
53+
const dispatch = useDispatch();
3954
// const [hover, setHover] = useState(false);
4055
const [showPopup, setShowPopup] = useState<boolean>(false);
4156
const [selectedStackBox, setSelectedStackBox] = useState<any>();
@@ -51,6 +66,66 @@ export const Configuration: React.FC<{
5166
if (fetching) {
5267
return <FullWidthSpinner color="black" size="md" />;
5368
}
69+
if (loading) {
70+
return <FullWidthSpinner color="black" size="md" />;
71+
}
72+
const onCallApi = (name?: string, toggle?: boolean) => {
73+
// ;
74+
const { id }: any = workspaces.find(
75+
(item) => item.name === selectedWorkspace,
76+
);
77+
78+
const body = {
79+
user: user?.id,
80+
workspace: id,
81+
is_shared: toggle,
82+
name: name,
83+
};
84+
setLoading(true);
85+
axios
86+
.put(
87+
`${process.env.REACT_APP_BASE_API_URL}/stacks/${stackId}`,
88+
// @ts-ignore
89+
body,
90+
{ headers: { Authorization: `Bearer ${authToken}` } },
91+
)
92+
.then((response: any) => {
93+
// const id = response.data.id;
94+
95+
// setLoading(false);
96+
dispatch(
97+
showToasterAction({
98+
description: 'Stack has been updated successfully.',
99+
type: toasterTypes.success,
100+
}),
101+
);
102+
103+
dispatch(
104+
stacksActions.stackForId({
105+
stackId: stackId,
106+
onSuccess: () => setLoading(false),
107+
onFailure: () => setLoading(false),
108+
}),
109+
);
110+
})
111+
.catch((err) => {
112+
setLoading(false);
113+
// ;
114+
115+
dispatch(
116+
showToasterAction({
117+
description: err?.response?.data?.detail[0],
118+
type: toasterTypes.failure,
119+
}),
120+
);
121+
});
122+
};
123+
124+
const onPressEnter = (event?: any, defaultValue?: any) => {
125+
if (event.key === 'Enter') {
126+
onCallApi(event.target.value);
127+
}
128+
};
54129

55130
return (
56131
<FlexBox.Column fullWidth>
@@ -87,11 +162,13 @@ export const Configuration: React.FC<{
87162
{/* <Container> */}
88163
<Box style={{ width: '30%' }}>
89164
<EditField
90-
disabled
91-
onChangeText={() => console.log('')}
165+
// disabled
166+
onKeyDown={(e: any) => onPressEnter(e, stack.is_shared)}
167+
onChangeText={(e: any) => onPressEnter(e, stack.is_shared)}
92168
label={'Stack Name'}
93169
optional={false}
94-
value={stack.name}
170+
defaultValue={stack.name}
171+
// value={stack.name}
95172
placeholder=""
96173
hasError={false}
97174
className={styles.field}
@@ -105,7 +182,12 @@ export const Configuration: React.FC<{
105182
<Paragraph>Share Component with public</Paragraph>
106183

107184
<label className={styles.switch}>
108-
<input type="checkbox" checked={stack.isShared} />
185+
<input
186+
type="checkbox"
187+
defaultChecked={stack.isShared}
188+
// checked={stack.isShared}
189+
onChange={() => onCallApi(stack.name, !stack.isShared)}
190+
/>
109191
<span className={`${styles.slider} ${styles.round}`}></span>
110192
</label>
111193
</FlexBox>

0 commit comments

Comments
 (0)