-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HPCC-31202 File permission dialog fails to open
When checking file permissions for file scopes, dialog was not opening. Dialog now opening for users to check permissions. Signed-off-by: Kunal Aswani <[email protected]>
- Loading branch information
1 parent
6cea89d
commit ce6f1e0
Showing
2 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
esp/src/src-react/components/forms/CheckPermissions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import * as React from "react"; | ||
import { DefaultButton, Dropdown, IDropdownOption, MessageBar, MessageBarType, PrimaryButton, TextField } from "@fluentui/react"; | ||
import { scopedLogger } from "@hpcc-js/util"; | ||
import { useForm, Controller } from "react-hook-form"; | ||
import nlsHPCC from "src/nlsHPCC"; | ||
import { MessageBox } from "../../layouts/MessageBox"; | ||
//import { Users } from "../Users"; | ||
//import { Groups } from "../Groups"; | ||
import { FilePermission } from "src/ws_access"; | ||
|
||
const logger = scopedLogger("src-react/components/forms/CheckPermissions.tsx"); | ||
|
||
interface CheckPermissionsFormValues { | ||
FileName: string; | ||
SelectedValue: string; | ||
} | ||
|
||
const defaultValues: CheckPermissionsFormValues = { | ||
FileName: "", | ||
SelectedValue: "", | ||
}; | ||
|
||
interface CheckPermissionsFormProps { | ||
refreshGrid?: () => void; | ||
showForm: boolean; | ||
setShowForm: (_: boolean) => void; | ||
} | ||
|
||
export const CheckPermissionsForm: React.FunctionComponent<CheckPermissionsFormProps> = ({ | ||
refreshGrid, | ||
showForm, | ||
setShowForm | ||
}) => { | ||
|
||
const { handleSubmit, control, reset, setValue, watch } = useForm<CheckPermissionsFormValues>({ defaultValues }); | ||
|
||
const [showError, setShowError] = React.useState(false); | ||
const [errorMessage] = React.useState(""); | ||
const [userOptions, setUserOptions] = React.useState<IDropdownOption[]>([]); | ||
const [groupOptions, setGroupOptions] = React.useState<IDropdownOption[]>([]); | ||
|
||
React.useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
const { FilePermissionResponse } = await FilePermission({}); | ||
const { Users, Groups } = FilePermissionResponse; | ||
|
||
setUserOptions(Users?.map(user => { | ||
return { key: user.username, text: user.username }; | ||
}) ?? []); | ||
|
||
setGroupOptions(Groups?.map(group => { | ||
return { key: group.name, text: group.name }; | ||
}) ?? []); | ||
} catch (error) { | ||
logger.error("Error fetching users and groups:" + error); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
const closeForm = React.useCallback(() => { | ||
setShowForm(false); | ||
}, [setShowForm]); | ||
|
||
const onSubmit = React.useCallback((data) => { | ||
const { FileName, SelectedValue } = data; | ||
logger.info(`Checking permissions for file ${FileName} for selected value: ${SelectedValue}`); | ||
}, []); | ||
|
||
return ( | ||
<MessageBox show={showForm} setShow={closeForm} title={nlsHPCC.CheckFilePermissions} minWidth={400} | ||
footer={<> | ||
<PrimaryButton text={nlsHPCC.Submit} onClick={handleSubmit(onSubmit)} /> | ||
<DefaultButton text={nlsHPCC.Cancel} onClick={() => { reset(defaultValues); closeForm(); }} /> | ||
</>}> | ||
<Controller | ||
control={control} name="FileName" | ||
render={({ | ||
field: { onChange, name: fieldName, value }, | ||
fieldState: { error } | ||
}) => <TextField | ||
name={fieldName} | ||
onChange={onChange} | ||
label={nlsHPCC.Name} | ||
value={value} | ||
errorMessage={error && error?.message} | ||
/>} | ||
rules={{ | ||
required: nlsHPCC.ValidationErrorRequired | ||
}} | ||
/> | ||
<Dropdown | ||
label={nlsHPCC.Users} | ||
options={userOptions} | ||
selectedKey={watch("SelectedValue")} | ||
onChange={(ev, option) => { | ||
setValue("SelectedValue", option?.key.toString() || ""); | ||
}} | ||
/> | ||
<Dropdown | ||
label={nlsHPCC.Groups} | ||
options={groupOptions} | ||
selectedKey={watch("SelectedValue")} | ||
onChange={(ev, option) => { | ||
setValue("SelectedValue", option?.key.toString() || ""); | ||
}} | ||
/> | ||
{showError && | ||
<div style={{ marginTop: 16 }}> | ||
<MessageBar | ||
messageBarType={MessageBarType.error} isMultiline={true} | ||
onDismiss={() => setShowError(false)} dismissButtonAriaLabel="Close"> | ||
{errorMessage} | ||
</MessageBar> | ||
</div> | ||
} | ||
</MessageBox> | ||
); | ||
}; |