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

refactor: Replace table and checkbox with StudioCheckboxTable in accessControl tab #14112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@
.header {
background-color: var(--fds-colors-grey-100);
}

.checkboxContent {
width: 3rem;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import React, { useRef } from 'react';
import { Table, Checkbox } from '@digdir/designsystemet-react';
import React, { type ReactElement, useRef } from 'react';
import type { ApplicationMetadata, PartyTypesAllowed } from 'app-shared/types/ApplicationMetadata';
import classes from './SelectAllowedPartyTypes.module.css';
import { useTranslation } from 'react-i18next';
import { getPartyTypesAllowedOptions } from '../../../../utils/tabUtils/accessControlTabUtils';
import { useAppMetadataMutation } from 'app-development/hooks/mutations';
import { AccessControlWarningModal } from '../AccessControWarningModal';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';
import { StudioCheckboxTable } from '@studio/components';

export interface SelectAllowedPartyTypesProps {
export type SelectAllowedPartyTypesProps = {
appMetadata: ApplicationMetadata;
}
};

export const SelectAllowedPartyTypes = ({ appMetadata }: SelectAllowedPartyTypesProps) => {
export const SelectAllowedPartyTypes = ({
appMetadata,
}: SelectAllowedPartyTypesProps): ReactElement => {
const { t } = useTranslation();
const { org, app } = useStudioEnvironmentParams();

Expand Down Expand Up @@ -59,45 +61,27 @@ export const SelectAllowedPartyTypes = ({ appMetadata }: SelectAllowedPartyTypes

return (
<>
<Table className={classes.tableContent}>
<Table.Head>
<Table.Row>
<Table.HeaderCell className={classes.header}>
<Checkbox
aria-label={t('settings_modal.access_control_tab_option_all_types')}
checked={areAllCheckboxesChecked || isNoCheckboxesChecked}
indeterminate={!areAllCheckboxesChecked && isSomeCheckboxesChecked}
onChange={handleTableHeaderCheckboxChange}
aria-checked
size='small'
value='all'
/>
</Table.HeaderCell>
<Table.HeaderCell className={classes.header} aria-hidden>
{t('settings_modal.access_control_tab_option_all_types')}
</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{getPartyTypesAllowedOptions().map((mappedOption, key) => (
<Table.Row key={mappedOption.value}>
<Table.Cell className={classes.checkboxContent}>
<Checkbox
aria-label={t(mappedOption.label)}
key={key}
onChange={() =>
handleAllowedPartyTypeChange(partyTypesAllowed, mappedOption.value)
}
size='small'
value={mappedOption.value}
checked={partyTypesAllowed[mappedOption.value] || isNoCheckboxesChecked}
/>
</Table.Cell>
<Table.Cell>{t(mappedOption.label)}</Table.Cell>
</Table.Row>
<StudioCheckboxTable className={classes.tableContent}>
<StudioCheckboxTable.Header
title={t('settings_modal.access_control_tab_option_all_types')}
checked={areAllCheckboxesChecked || isNoCheckboxesChecked}
indeterminate={!areAllCheckboxesChecked && isSomeCheckboxesChecked}
onChange={handleTableHeaderCheckboxChange}
/>
<StudioCheckboxTable.Body>
{getPartyTypesAllowedOptions().map((mappedOption) => (
<StudioCheckboxTable.Row
key={mappedOption.value}
rowElement={{
...mappedOption,
label: t(mappedOption.label),
checked: partyTypesAllowed[mappedOption.value] || isNoCheckboxesChecked,
}}
onChange={() => handleAllowedPartyTypeChange(partyTypesAllowed, mappedOption.value)}
/>
))}
</Table.Body>
</Table>
</StudioCheckboxTable.Body>
</StudioCheckboxTable>
<AccessControlWarningModal modalRef={modalRef} />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
.descriptionText {
color: var(--fds-semantic-text-neutral-subtle);
}

.chexboxTextContent {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const StudioCheckboxTableRow = ({
checked={checked}
/>
</StudioTable.Cell>
<StudioTable.Cell>
<StudioTable.Cell className={classes.chexboxTextContent}>
<StudioParagraph size='sm'>{label}</StudioParagraph>
{description && (
<StudioParagraph size='sm' className={classes.descriptionText}>
Expand Down