-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented new sharing setup Implemented new sharing UI
- Loading branch information
Showing
30 changed files
with
1,215 additions
and
338 deletions.
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
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
10 changes: 10 additions & 0 deletions
10
...ponents/Access/components/Sharing/components/CustomSharingDialog/SharingDialog.module.css
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,10 @@ | ||
.root { | ||
position: fixed; | ||
} | ||
|
||
.search-menu { | ||
width: 400px; | ||
padding: 2px; | ||
max-height: 400px; | ||
overflow-y: auto; | ||
} |
13 changes: 13 additions & 0 deletions
13
...ent/components/Access/components/Sharing/components/CustomSharingDialog/SharingDialog.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,13 @@ | ||
import React from "react"; | ||
import { AccessAdd } from "./components/AccessAdd"; | ||
import { AccessList } from "./components/AccessList"; | ||
|
||
export function SharingDialog() { | ||
|
||
return ( | ||
<div id="sharing-form-area" className="column gap-8"> | ||
<AccessAdd /> | ||
<AccessList /> | ||
</div> | ||
); | ||
} |
116 changes: 116 additions & 0 deletions
116
...ponents/Access/components/Sharing/components/CustomSharingDialog/components/AccessAdd.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,116 @@ | ||
import { useController } from "react-hook-form"; | ||
import React, { useRef, useState } from "react"; | ||
import Title from "./Title"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
import { SharingAutoComplete } from "./SharingAutocomplete"; | ||
import { Button, colors, SingleSelectField, SingleSelectOption } from "@dhis2/ui"; | ||
import { ACCESS_TYPES_LABELLED } from "@scorecard/shared"; | ||
|
||
export function AccessAdd(): React.ReactElement { | ||
const { field: userAccessField } = useController({ name: "sharing.users" }); | ||
const { field: userGroupAccessField } = useController({ | ||
name: "sharing.userGroups" | ||
}); | ||
const ref = useRef<HTMLFormElement>(null); | ||
const [entity, setEntity] = useState< | ||
| { id: string; type?: string; name?: string; displayName?: string } | ||
| undefined | ||
>(); | ||
const [access, setAccess] = useState(""); | ||
const onSubmit = (e: { preventDefault: () => void }) => { | ||
e.preventDefault(); | ||
if (entity?.type === "user") { | ||
userAccessField.onChange( | ||
{ | ||
...userAccessField.value, | ||
[entity.id]: { | ||
id: entity.id, | ||
name: entity.name, | ||
displayName: entity.displayName, | ||
access | ||
} | ||
} | ||
); | ||
} | ||
if (entity?.type === "userGroup") { | ||
userGroupAccessField.onChange( | ||
{ | ||
...userGroupAccessField.value, | ||
[entity.id]: { | ||
id: entity.id, | ||
name: entity.name, | ||
displayName: entity.displayName, | ||
access | ||
} | ||
} | ||
); | ||
} | ||
setEntity(undefined); | ||
setAccess(""); | ||
}; | ||
|
||
return ( | ||
<div className="access-config-add-user"> | ||
<Title title={i18n.t("Give Access to a user , group or role")} /> | ||
<form | ||
ref={ref} | ||
style={{ | ||
display: "flex", | ||
gap: 16 | ||
}} | ||
onSubmit={onSubmit} | ||
> | ||
<div className="flex-1 access-config-add-user-search"> | ||
<SharingAutoComplete | ||
selected={entity} | ||
onSelection={setEntity} | ||
/> | ||
</div> | ||
<div | ||
id="select-access-sharing-settings" | ||
className="select-wrapper access-config-add-user-select-wrapper" | ||
> | ||
<SingleSelectField | ||
label={i18n.t("Access level")} | ||
placeholder={i18n.t("Select a level")} | ||
dataTest={"access-level-list-test"} | ||
selected={access} | ||
onChange={({ selected }: any) => setAccess(selected)} | ||
> | ||
{ACCESS_TYPES_LABELLED.map(({ value, label }) => ( | ||
<SingleSelectOption | ||
dataTest={"access-level-option-list-test"} | ||
key={value} | ||
label={label} | ||
value={value} | ||
active={value === access} | ||
/> | ||
))} | ||
</SingleSelectField> | ||
</div> | ||
<Button | ||
className={"access-config-add-user-access-action"} | ||
type="submit" | ||
disabled={!entity || !access} | ||
> | ||
{i18n.t("Give access")} | ||
</Button> | ||
</form> | ||
<style>{` | ||
form { | ||
background-color: ${colors.grey100}; | ||
color: ${colors.grey900}; | ||
margin-bottom: 21px; | ||
padding: 8px 12px; | ||
border-radius: 5px; | ||
display: flex; | ||
align-items: flex-end; | ||
} | ||
.select-wrapper { | ||
flex: 1; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
...onents/Access/components/Sharing/components/CustomSharingDialog/components/AccessList.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,62 @@ | ||
import i18n from "@dhis2/d2-i18n"; | ||
import React from "react"; | ||
import Title from "./Title"; | ||
import { ListItem } from "./ListAccessItem"; | ||
import useManageAccess from "../hooks"; | ||
import { AccessTypes } from "@scorecard/shared"; | ||
|
||
export function AccessList(): React.ReactElement { | ||
const { | ||
userGroups, | ||
users, | ||
onChangeAccess, | ||
onRemove, | ||
publicAccess | ||
} = useManageAccess(); | ||
|
||
return ( | ||
<> | ||
<Title | ||
title={i18n.t("Users and groups that currently have access")} | ||
/> | ||
<div className="header"> | ||
<div className="header-left-column"> | ||
{i18n.t("User / Group / Role")} | ||
</div> | ||
<div className="header-right-column"> | ||
{i18n.t("Access level")} | ||
</div> | ||
</div> | ||
<div className="access-list"> | ||
<ListItem | ||
entity={{ | ||
name: i18n.t("All users"), | ||
displayName: i18n.t("All users"), | ||
id: "publicAccess", | ||
access: publicAccess | ||
}} | ||
target={AccessTypes.PUBLIC} | ||
onChange={onChangeAccess(AccessTypes.PUBLIC)} | ||
/> | ||
{Object.values(userGroups)?.map((uGroup) => ( | ||
<ListItem | ||
key={`${uGroup.id}`} | ||
entity={uGroup} | ||
target={AccessTypes.USER_GROUP} | ||
onChange={onChangeAccess(AccessTypes.USER_GROUP)} | ||
onRemove={onRemove(AccessTypes.USER_GROUP)} | ||
/> | ||
))} | ||
{Object.values(users)?.map((entity) => ( | ||
<ListItem | ||
entity={entity} | ||
key={entity.id} | ||
target={AccessTypes.USER} | ||
onChange={onChangeAccess(AccessTypes.USER)} | ||
onRemove={onRemove(AccessTypes.USER)} | ||
/> | ||
))} | ||
</div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.