Skip to content

Commit

Permalink
fix: scorecard form
Browse files Browse the repository at this point in the history
Implemented new sharing setup

Implemented new sharing UI
  • Loading branch information
nnkogift committed Sep 24, 2024
1 parent cc705ff commit 2fb113d
Show file tree
Hide file tree
Showing 30 changed files with 1,215 additions and 338 deletions.
57 changes: 40 additions & 17 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-09-24T08:03:46.605Z\n"
"PO-Revision-Date: 2024-09-24T08:03:46.605Z\n"
"POT-Creation-Date: 2024-09-24T10:31:52.171Z\n"
"PO-Revision-Date: 2024-09-24T10:31:52.171Z\n"

msgid "Could not determine scorecard's access"
msgstr "Could not determine scorecard's access"
Expand Down Expand Up @@ -74,6 +74,42 @@ msgstr "Add New Scorecard"
msgid "Organisation Unit"
msgstr "Organisation Unit"

msgid "Give Access to a user , group or role"
msgstr "Give Access to a user , group or role"

msgid "Access level"
msgstr "Access level"

msgid "Select a level"
msgstr "Select a level"

msgid "Give access"
msgstr "Give access"

msgid "Users and groups that currently have access"
msgstr "Users and groups that currently have access"

msgid "User / Group / Role"
msgstr "User / Group / Role"

msgid "All users"
msgstr "All users"

msgid "Not available offline"
msgstr "Not available offline"

msgid "User, group or role"
msgstr "User, group or role"

msgid "Search"
msgstr "Search"

msgid "Confirm action"
msgstr "Confirm action"

msgid "Are you sure you want to delete this access?"
msgstr "Are you sure you want to delete this access?"

msgid "Select Access"
msgstr "Select Access"

Expand All @@ -83,12 +119,6 @@ msgstr "Add"
msgid "Sharing"
msgstr "Sharing"

msgid "Shared With"
msgstr "Shared With"

msgid "Add Access"
msgstr "Add Access"

msgid "No Access"
msgstr "No Access"

Expand Down Expand Up @@ -422,12 +452,8 @@ msgstr "Title is required"
msgid "Title must have at least 4 characters"
msgstr "Title must have at least 4 characters"

msgid ""
"A scorecard with the title '{{value}}' already exists. Please select "
"another title"
msgstr ""
"A scorecard with the title '{{value}}' already exists. Please select "
"another title"
msgid "A scorecard with this title already exists. Please select another title"
msgstr "A scorecard with this title already exists. Please select another title"

msgid "A data group must have at least one data item"
msgstr "A data group must have at least one data item"
Expand Down Expand Up @@ -552,9 +578,6 @@ msgstr "Confirm scorecard selection"
msgid "Are you sure you want to select this scorecard for this dashboard?"
msgstr "Are you sure you want to select this scorecard for this dashboard?"

msgid "Search"
msgstr "Search"

msgid "Preparing widgets migration..."
msgstr "Preparing widgets migration..."

Expand Down
17 changes: 13 additions & 4 deletions packages/app/src/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,21 @@
"grid": "grid",
"Add New Scorecard": "Add New Scorecard",
"Organisation Unit": "Organisation Unit",
"Give Access to a user , group or role": "Give Access to a user , group or role",
"Access level": "Access level",
"Select a level": "Select a level",
"Give access": "Give access",
"Users and groups that currently have access": "Users and groups that currently have access",
"User / Group / Role": "User / Group / Role",
"All users": "All users",
"Not available offline": "Not available offline",
"User, group or role": "User, group or role",
"Search": "Search",
"Confirm action": "Confirm action",
"Are you sure you want to delete this access?": "Are you sure you want to delete this access?",
"Select Access": "Select Access",
"Add": "Add",
"Sharing": "Sharing",
"Shared With": "Shared With",
"Add Access": "Add Access",
"No Access": "No Access",
"Can Read": "Can Read",
"Can Read and Write": "Can Read and Write",
Expand Down Expand Up @@ -131,7 +141,7 @@
"Error saving scorecard": "Error saving scorecard",
"Title is required": "Title is required",
"Title must have at least 4 characters": "Title must have at least 4 characters",
"A scorecard with the title '{{value}}' already exists. Please select another title": "A scorecard with the title '{{value}}' already exists. Please select another title",
"A scorecard with this title already exists. Please select another title": "A scorecard with this title already exists. Please select another title",
"A data group must have at least one data item": "A data group must have at least one data item",
"A scorecard needs at least one data group": "A scorecard needs at least one data group",
"You must select at least one organisation unit": "You must select at least one organisation unit",
Expand Down Expand Up @@ -173,7 +183,6 @@
"Create a new scorecard in the scorecard app to see it here.": "Create a new scorecard in the scorecard app to see it here.",
"Confirm scorecard selection": "Confirm scorecard selection",
"Are you sure you want to select this scorecard for this dashboard?": "Are you sure you want to select this scorecard for this dashboard?",
"Search": "Search",
"Preparing widgets migration...": "Preparing widgets migration...",
"Migrating scorecards widgets": "Migrating scorecards widgets"
}
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;
}
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>
);
}
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>
);
}
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>
</>
);
}
Loading

0 comments on commit 2fb113d

Please sign in to comment.