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 pblish project,fixed mie errors,strong validation in guest workspace #130

Merged
merged 3 commits into from
Jun 28, 2024
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
31 changes: 30 additions & 1 deletion src/app/new-project/newproject.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Select,
FormControl,
MenuItem,
Switch,
} from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import CancelIcon from "@mui/icons-material/Cancel";
Expand All @@ -36,6 +37,7 @@ import { fetchDatasetSearchPopup } from "@/Lib/Features/datasets/DatasetSearchPo
import {fetchLanguages} from "@/Lib/Features/fetchLanguages";
import DatasetSearchPopup from "@/components/datasets/DatasetSearchPopup";
import { fetchDataitemsById } from "@/Lib/Features/datasets/GetDataitemsById";
import { fetchWorkspaceDetails } from "@/Lib/Features/getWorkspaceDetails";

const isNum = (str) => {
var reg = new RegExp("^[0-9]*$");
Expand Down Expand Up @@ -73,6 +75,7 @@ const CreateProject = () => {
const NewProject = useSelector(state => state.projects.newProject?.res);
const UserData = useSelector(state => state.getLoggedInData.data);
const navigate = useNavigate();


const [domains, setDomains] = useState([]);
const [projectTypes, setProjectTypes] = useState(null);
Expand Down Expand Up @@ -100,6 +103,7 @@ const CreateProject = () => {
const [selectedVariableParameters, setSelectedVariableParameters] = useState(
[]
);
const workspaceDtails = useSelector(state => state.getWorkspaceDetails.data);
const [taskReviews, setTaskReviews] = useState(1);
const [variable_Parameters_lang, setVariable_Parameters_lang] = useState("");
//Table related state variables
Expand All @@ -110,6 +114,7 @@ const CreateProject = () => {
const [totalDataitems, setTotalDataitems] = useState(10);
const [tableData, setTableData] = useState([]);
const [searchAnchor, setSearchAnchor] = useState(null);
const [is_published, setIsPublished] = useState(false);
const [selectedFilters, setsSelectedFilters] = useState({});
const [createannotationsAutomatically, setsCreateannotationsAutomatically] = useState("none");
/* eslint-disable react-hooks/exhaustive-deps */
Expand All @@ -129,6 +134,15 @@ const CreateProject = () => {
"rating",
];

const getWorkspaceDetails = ()=>{
dispatch(fetchWorkspaceDetails(id));
}


useEffect(()=>{
getWorkspaceDetails();
},[]);

//Fetch and display Project Domains
useEffect(() => {
// if(ProjectDomains.status !== "succeeded")
Expand All @@ -138,6 +152,10 @@ const CreateProject = () => {
setSelectedDomain(value);
};

const handleChangeIsPublished = (event) => {
setIsPublished(event.target.checked);
};

useEffect(() => {
setTotalDataitems(DataItems.count);
let fetchedItems = DataItems.results;
Expand Down Expand Up @@ -301,6 +319,7 @@ const CreateProject = () => {
project_stage: taskReviews,
required_annotators_per_task: selectedAnnotatorsNum,
automatic_annotation_creation_mode: createannotationsAutomatically,
is_published:is_published,
};
if (sourceLanguage) newProject["src_language"] = sourceLanguage;
if (targetLanguage) newProject["tgt_language"] = targetLanguage;
Expand Down Expand Up @@ -1040,10 +1059,20 @@ const CreateProject = () => {
</Select>
</FormControl>
</Grid>
{workspaceDtails?.guest_workspace_display === "Yes"?<Grid container direction="row" alignItems="center">
<Typography gutterBottom components="div">
Publish Project :
</Typography>
<Switch
checked={is_published}
onChange={handleChangeIsPublished}
inputProps={{ "aria-label": "controlled" }}
sx={{ mt: 2, ml: 2 ,mb:2}}
/>
</Grid>:null}

</>
)}

<Grid
item
className="projectsettingGrid"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ModelInteractionEvaluation = ({ currentInteraction, setCurrentInteraction
const classes = ModelResponseEvaluationStyle();
const [interactions, setInteractions] = useState([]);
const [forms, setForms] = useState([]);
const [leftPanelVisible, setLeftPanelVisible] = useState(false);
const [leftPanelVisible, setLeftPanelVisible] = useState(true);
const [selectedQuestions, setSelectedQuestions] = useState([]);


Expand Down Expand Up @@ -109,7 +109,7 @@ const ModelInteractionEvaluation = ({ currentInteraction, setCurrentInteraction
setCurrentInteraction((prev) => {
return {
prompt: interactions[0]?.prompt,
output: interactions[0]?.output,
output: typeof(interactions[0]?.output)==="string"?interactions[0]?.output:interactions[0]?.value,
prompt_output_pair_id: interactions[0]?.prompt_output_pair_id,
rating: currentForm[0]?.form_output_json?.rating,
additional_note: currentForm[0]?.form_output_json?.additional_note,
Expand Down Expand Up @@ -361,14 +361,15 @@ const ModelInteractionEvaluation = ({ currentInteraction, setCurrentInteraction
}}
className={classes.answerTile}
>
{pair.output}
{typeof(pair.output)==="string"?pair?.output:pair?.output?.value}
</Box>
<Box sx={{ display: 'flex', alignItems: 'center', marginTop: '1rem' }}>
<Button
label={translate("model_evaluation_btn")}
buttonVariant={"outlined"}
style={{
marginTop: "1rem",
padding:"0.5rem"
}}
onClick={handleFormBtnClick}
id={pair.prompt_output_pair_id}
Expand Down
47 changes: 34 additions & 13 deletions src/app/ui/pages/workspace/AddWorkspaceDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,38 @@ const AddWorkspaceDialog = ({ isOpen, dialogCloseHandler,orgId}) => {
});
const validatePassword = () => {
const errors = [];
if(password1.length>0){
if (password1.length < 8) {
errors.push("This password is too short. It must contain at least 8 characters.");
}
const commonPasswords = ["password", "12345678", "qwerty"];
if (commonPasswords.includes(password1)) {
errors.push("This password is too common.");

if (password1.length > 0) {
if (password1.length < 8) {
errors.push("This password is too short. It must contain at least 8 characters.");
}

if (!/[a-z]/.test(password1)) {
errors.push("This password must contain at least one lowercase letter.");
}

if (!/[A-Z]/.test(password1)) {
errors.push("This password must contain at least one uppercase letter.");
}

if (!/[0-9]/.test(password1)) {
errors.push("This password must contain at least one number.");
}

if (!/[!@#$%^&*(),.?":{}|<>]/.test(password1)) {
errors.push("This password must contain at least one special character.");
}

const commonPasswords = ["password", "12345678", "qwerty", "123456789", "abc123", "password1"];
if (commonPasswords.includes(password1)) {
errors.push("This password is too common.");
}
} else {
errors.push("Password cannot be empty.");
}

setPasswordErrors(errors);
return errors.length === 0;
}
};
useEffect(() => {
validatePassword()
Expand Down Expand Up @@ -97,7 +118,7 @@ const AddWorkspaceDialog = ({ isOpen, dialogCloseHandler,orgId}) => {
const createWorkspaceRespData = await createWorkspaceRes.json();

if (createWorkspaceRes.ok) {
const getWorkspaceApiObj = new GetWorkspaceAPI(); // Correctly instantiate the class
const getWorkspaceApiObj = new GetWorkspaceAPI();
const workspaceDataRes = await fetch(getWorkspaceApiObj.apiEndPoint(), {
method: "GET",
headers: {
Expand All @@ -122,7 +143,7 @@ const AddWorkspaceDialog = ({ isOpen, dialogCloseHandler,orgId}) => {
// dispatch(fetchWorkspaceDetails(orgId));
setSnackbarInfo({
open: true,
message: resp?.message,
message: "Successfully created Guest Workspace",
variant: "success",
})
} else {
Expand All @@ -132,8 +153,8 @@ const AddWorkspaceDialog = ({ isOpen, dialogCloseHandler,orgId}) => {
variant: "error",
})
}
}

setLoading(false);
}
}
dialogCloseHandler();
setLoading(false);
Expand Down Expand Up @@ -233,7 +254,7 @@ const AddWorkspaceDialog = ({ isOpen, dialogCloseHandler,orgId}) => {
label="Enter Password"
/>
{passwordErrors.map((error, index) => (
<span key={index} style={{ color: "#d93025" }}>{error}</span>
<span key={index} style={{ color: "#d93025" ,fontSize:"13px"}}>*{error}</span>
))}
</FormControl>
<FormControl sx={{ width: "100%", marginTop: "3%", marginLeft: "0" }} variant="outlined">
Expand Down
45 changes: 33 additions & 12 deletions src/app/ui/pages/workspace/WorkspaceSetting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,38 @@ function WorkspaceSetting(props) {

const validatePassword = () => {
const errors = [];
if(newpassword.length>0){
if (newpassword.length < 8) {
errors.push("This password is too short. It must contain at least 8 characters.");
}
const commonPasswords = ["password", "12345678", "qwerty"]; // Simplified common password list
if (commonPasswords.includes(newpassword)) {
errors.push("This password is too common.");

if (newpassword.length > 0) {
if (newpassword.length < 8) {
errors.push("This password is too short. It must contain at least 8 characters.");
}

if (!/[a-z]/.test(newpassword)) {
errors.push("This password must contain at least one lowercase letter.");
}

if (!/[A-Z]/.test(newpassword)) {
errors.push("This password must contain at least one uppercase letter.");
}

if (!/[0-9]/.test(newpassword)) {
errors.push("This password must contain at least one number.");
}

if (!/[!@#$%^&*(),.?":{}|<>]/.test(newpassword)) {
errors.push("This password must contain at least one special character.");
}

const commonPasswords = ["password", "12345678", "qwerty", "123456789", "abc123", "newpassword"];
if (commonPasswords.includes(newpassword)) {
errors.push("This password is too common.");
}
} else {
errors.push("Password cannot be empty.");
}

setPasswordErrors(errors);
return errors.length === 0;
}
};
useEffect(()=>{
validatePassword()
Expand Down Expand Up @@ -367,7 +388,7 @@ function WorkspaceSetting(props) {
label="Enter Password"
/>
{passwordErrors.map((error, index) => (
<span key={index} style={{ color: "#d93025" }}>{error}</span>
<span key={index} style={{ color: "#d93025",fontSize:"13px" }}>*{error}</span>
))}
</FormControl>
</Grid>
Expand All @@ -392,7 +413,7 @@ function WorkspaceSetting(props) {
}
label="Confirm Password"
/>
{passwordEqual==true ? "" : <span style={{ color: "#d93025" }}>The passwords don't match</span>}
{passwordEqual==true ? "" : <span style={{ color: "#d93025",fontSize:"13px" }}>*The passwords don't match</span>}
</FormControl>
</Grid>
</Grid>
Expand Down Expand Up @@ -436,7 +457,7 @@ function WorkspaceSetting(props) {
label="Enter Password"
/>
{passwordErrors.map((error, index) => (
<span key={index} style={{ color: "#d93025" }}>{error}</span>
<span key={index} style={{ color: "#d93025",fontSize:"13px" }}>*{error}</span>
))}
</FormControl>
</Grid>
Expand All @@ -461,7 +482,7 @@ function WorkspaceSetting(props) {
}
label="Confirm Password"
/>
{passwordEqual==true ? "" : <span style={{ color: "#d93025" }}>The passwords don't match</span>}
{passwordEqual==true ? "" : <span style={{ color: "#d93025",fontSize:"13px" }}>*The passwords don't match</span>}

</FormControl>
</Grid>
Expand Down
1 change: 1 addition & 0 deletions src/components/Project/DeleteProjectTasks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useParams } from 'react-router-dom';
import CustomizedSnackbars from "@/components/common/Snackbar";
import userRole from "@/utils/UserMappedByRole/Roles";
import DeleteProjectTasksAPI from "@/app/actions/api/Projects/DeleteProjectTasksAPI";
import LoginAPI from "@/app/actions/api/user/Login";

export default function DeleteProjectTasks() {
const classes = DatasetStyle();
Expand Down
Loading