Skip to content

Commit

Permalink
feat: make workspace permission first row deletable for workspace cre…
Browse files Browse the repository at this point in the history
…ate (opensearch-project#151)

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam authored Sep 13, 2023
1 parent 98b77d0 commit bb2d886
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const WorkspaceCreator = () => {
application={application}
onSubmit={handleWorkspaceFormSubmit}
opType={WORKSPACE_OP_TYPE_CREATE}
permissionFirstRowDeletable
/>
)}
</EuiPageContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ interface WorkspaceFormProps {
onSubmit?: (formData: WorkspaceFormSubmitData) => void;
defaultValues?: WorkspaceFormData;
opType?: string;
permissionFirstRowDeletable?: boolean;
}

export const WorkspaceForm = ({
application,
onSubmit,
defaultValues,
opType,
permissionFirstRowDeletable,
}: WorkspaceFormProps) => {
const workspaceId = defaultValues?.id;
const workspaceNameReadOnly =
Expand All @@ -140,7 +142,7 @@ export const WorkspaceForm = ({
>(
defaultValues?.permissions && defaultValues.permissions.length > 0
? defaultValues.permissions
: [{}]
: []
);

const [formErrors, setFormErrors] = useState<WorkspaceFormErrors>({});
Expand Down Expand Up @@ -477,6 +479,7 @@ export const WorkspaceForm = ({
errors={formErrors.permissions}
value={permissionSettings}
onChange={setPermissionSettings}
firstRowDeletable={permissionFirstRowDeletable}
/>
</EuiPanel>
<EuiSpacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,14 @@ interface WorkspacePermissionSettingPanelProps {
errors?: string[];
value?: Array<Partial<WorkspacePermissionSetting>>;
onChange?: (value: Array<Partial<WorkspacePermissionSetting>>) => void;
firstRowDeletable?: boolean;
}

export const WorkspacePermissionSettingPanel = ({
errors,
value,
onChange,
firstRowDeletable,
}: WorkspacePermissionSettingPanelProps) => {
const valueRef = useRef(value);
valueRef.current = value;
Expand Down Expand Up @@ -286,7 +288,7 @@ export const WorkspacePermissionSettingPanel = ({
<WorkspacePermissionSettingInput
{...item}
index={index}
deletable={index !== 0}
deletable={firstRowDeletable || index !== 0}
onDelete={handleDelete}
onTypeChange={handleTypeChange}
onGroupOrUserIdChange={handleGroupOrUserIdChange}
Expand Down

0 comments on commit bb2d886

Please sign in to comment.