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

Feat/disable action based on role #349

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 7 additions & 3 deletions src/components/AddCaseButtons/AddCaseButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ export const AddCaseButtons = ({
title,
localList,
addCase,
isOwner,
}: {
title: string;
localList?: ComputeCaseDto[];
addCase?: (methodType: string) => void;
isOwner: () => boolean;
}) => {
const filerLocalList = (methodType: string) => {
if (!localList) return [];
Expand All @@ -24,7 +26,7 @@ export const AddCaseButtons = ({
<Button
variant="ghost"
onClick={() => addCase('Indicator')}
disabled={filerLocalList('Indicator').length > 0}
disabled={filerLocalList('Indicator').length > 0 || !isOwner()}
>
<Icon data={ADD} size={18}></Icon>
Add case
Expand All @@ -34,7 +36,7 @@ export const AddCaseButtons = ({
<Button
variant="ghost"
onClick={() => addCase('Net-To-Gross')}
disabled={filerLocalList('Net-To-Gross').length > 0}
disabled={filerLocalList('Net-To-Gross').length > 0 || !isOwner()}
>
<Icon data={ADD} size={18}></Icon>
Add case
Expand All @@ -44,7 +46,9 @@ export const AddCaseButtons = ({
<Button
variant="ghost"
onClick={() => addCase('ContiniousParameter')}
disabled={filerLocalList('ContiniousParameter').length > 0}
disabled={
filerLocalList('ContiniousParameter').length > 0 || !isOwner()
}
>
<Icon data={ADD} size={18}></Icon>
Add case
Expand Down
3 changes: 3 additions & 0 deletions src/components/CaseCardComponent/CaseCardComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ export const CaseCardComponent = ({
subTitle,
localList,
addCase,
isOwner,
}: {
children: React.ReactNode;
title: string;
resultCard?: boolean;
subTitle?: string;
localList?: ComputeCaseDto[];
addCase?: (methodType: string) => void;
isOwner: () => boolean;
}) => {
return (
<Styled.CaseBorder>
Expand All @@ -32,6 +34,7 @@ export const CaseCardComponent = ({
title={title}
localList={localList}
addCase={addCase}
isOwner={isOwner}
thomaslf97 marked this conversation as resolved.
Show resolved Hide resolved
></AddCaseButtons>
</Styled.ButtonGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ export const GrossDepositionEnviromentGroup = ({
defaultMetadata,
gdeGroups,
deleteGdeRow,
hideContent,
}: {
modelIdParent?: string;
defaultMetadata: AnalogueModelDetail;
gdeGroups: GeologicalGroupDto[];
deleteGdeRow: (
geologicalGroupId: string,
) => Promise<DeleteGeologicalGroupCommandResponse | undefined>;
hideContent: () => boolean;
}) => {
const [showGdeDialog, setShowGdeDialog] = useState<boolean>(false);
const [gdeObject, setGdeObject] = useState<GdeType>(defaultGdeData);
Expand Down Expand Up @@ -142,15 +144,17 @@ export const GrossDepositionEnviromentGroup = ({
{gdeGroups.map((row) => (
<Table.Row key={row.geologicalGroupId}>
<Table.Cell>
<Button
variant="ghost_icon"
onClick={() => deleteGdeRow(row.geologicalGroupId)}
>
<Icon
data={deleteIcon}
title={'Delete gross deposition enviroment row'}
/>
</Button>
{hideContent() && (
<Button
variant="ghost_icon"
onClick={() => deleteGdeRow(row.geologicalGroupId)}
>
<Icon
data={deleteIcon}
title={'Delete gross deposition enviroment row'}
/>
</Button>
)}
</Table.Cell>
<Table.Cell>
{row.grossDepEnv.equinorCode +
Expand Down Expand Up @@ -180,9 +184,11 @@ export const GrossDepositionEnviromentGroup = ({
</Table>
)}
<div>
<Button variant="outlined" onClick={handleGdeDialog}>
Add GDE…
</Button>
{hideContent() && (
<Button variant="outlined" onClick={handleGdeDialog}>
Add GDE…
</Button>
)}
</div>
</Styled.Wrapper>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ export const OutcropAnalogueGroup = ({
modelIdParent,
defaultMetadata,
outcropGroup,
hideContent,
}: {
modelIdParent?: string;
defaultMetadata: AnalogueModelDetail;
outcropGroup: OutcropDto[];
hideContent: () => boolean;
}) => {
const [showOutcropDialog, setShowOutcropDialog] = useState<boolean>(false);
const [errors, setErrors] = useState<OutcropErrorType>({});
Expand Down Expand Up @@ -115,16 +117,21 @@ export const OutcropAnalogueGroup = ({
{outcropGroup.map((row) => (
<Table.Row key={row.outcropId}>
<Table.Cell>
<Button
variant="ghost_icon"
onClick={() =>
handleDeleteOutcropAnalogue(
row.outcropId ? row.outcropId : 'none',
)
}
>
<Icon data={deleteIcon} title={'Delete strat column row'} />
</Button>
{hideContent() && (
<Button
variant="ghost_icon"
onClick={() =>
handleDeleteOutcropAnalogue(
row.outcropId ? row.outcropId : 'none',
)
}
>
<Icon
data={deleteIcon}
title={'Delete strat column row'}
/>
</Button>
)}
</Table.Cell>
<Table.Cell>
<Styled.StratColCell>{row.name}</Styled.StratColCell>
Expand All @@ -146,9 +153,11 @@ export const OutcropAnalogueGroup = ({
</Table>
)}
<div>
<Button variant="outlined" onClick={handleOutcropDialog}>
Add outcrop analogue…
</Button>
{hideContent() && (
<Button variant="outlined" onClick={handleOutcropDialog}>
Add outcrop analogue…
</Button>
)}
</div>
<StyledDialog.DialogWindow open={showOutcropDialog}>
<Dialog.Header>Add Outcrop Analogue</Dialog.Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ export const StratigrapicGroups = ({
defaultMetadata,
stratColumnGroups,
deleteStratColRow,
hideContent,
}: {
modelIdParent?: string;
defaultMetadata: AnalogueModelDetail;
stratColumnGroups: StratigraphicGroupDto[];
deleteStratColRow: (
stratigraphicGroupId: string,
) => Promise<DeleteStratigraphicGroupCommandResponse | undefined>;
hideContent: () => boolean;
}) => {
const [stratColumnObject, setStratColumnObject] = useState<StratColumnType>(
defaultStratColumnData,
Expand Down Expand Up @@ -169,12 +171,17 @@ export const StratigrapicGroups = ({
{stratColumnGroups.map((row) => (
<Table.Row key={row.stratigraphicGroupId}>
<Table.Cell>
<Button
variant="ghost_icon"
onClick={() => deleteRow(row.stratigraphicGroupId)}
>
<Icon data={deleteIcon} title={'Delete strat column row'} />
</Button>
{hideContent() && (
<Button
variant="ghost_icon"
onClick={() => deleteRow(row.stratigraphicGroupId)}
>
<Icon
data={deleteIcon}
title={'Delete strat column row'}
/>
</Button>
)}
</Table.Cell>
<Table.Cell>{row.country.identifier}</Table.Cell>
<Table.Cell>
Expand Down Expand Up @@ -221,9 +228,11 @@ export const StratigrapicGroups = ({
)}

<div>
<Button variant="outlined" onClick={handleStratColDialog}>
Add stratigraphic column…
</Button>
{hideContent() && (
<Button variant="outlined" onClick={handleStratColDialog}>
Add stratigraphic column…
</Button>
)}
</div>
<StyledDialog.DialogWindow open={showStratColDialog}>
<Dialog.Header>Add stratigraphic column</Dialog.Header>
Expand Down
13 changes: 9 additions & 4 deletions src/features/Compute/CaseGroup/CaseButtons/CaseButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const CaseButtons = ({
saved,
isProcessed,
caseStatus,
isOwner,
hasUnsavedCase,
saveCase,
runCase,
Expand All @@ -33,6 +34,7 @@ export const CaseButtons = ({
saved: boolean;
isProcessed?: boolean;
caseStatus: ComputeJobStatus;
isOwner: () => boolean;
hasUnsavedCase: boolean;
runCase?: () => void;
saveCase: () => void;
Expand Down Expand Up @@ -60,7 +62,7 @@ export const CaseButtons = ({

return (
<Styled.ButtonDiv>
{id.length < 3 ? (
{id.length < 3 || !isOwner() ? (
<Tooltip title={'Can not delete unsaved case.'}>
<Button disabled variant="ghost_icon" aria-label="remove">
<Icon data={DELETE} size={24}></Icon>
Expand All @@ -78,7 +80,7 @@ export const CaseButtons = ({

{caseType === 'Variogram' && (
<>
{id.length < 3 ? (
{id.length < 3 || !isOwner() ? (
<Tooltip title={'Can not duplicate unsaved case.'}>
<Button disabled variant="ghost_icon" aria-label="duplicate">
<Icon data={COPY} size={24}></Icon>
Expand Down Expand Up @@ -140,7 +142,8 @@ export const CaseButtons = ({
!isProcessed ||
caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running'
caseStatus === 'Running' ||
!isOwner()
}
>
<Icon data={PLAY} size={18}></Icon>
Expand Down Expand Up @@ -192,7 +195,8 @@ export const CaseButtons = ({
id.length < 3 ||
caseStatus === 'Created' ||
caseStatus === 'Waiting' ||
caseStatus === 'Running'
caseStatus === 'Running' ||
!isOwner()
}
>
<Icon data={PLAY} size={18}></Icon>
Expand All @@ -207,6 +211,7 @@ export const CaseButtons = ({
)}
</Tooltip>
<Button
disabled={!isOwner()}
variant="outlined"
onClick={id.length > 3 ? () => setSaveConfirm(true) : saveCase}
>
Expand Down
7 changes: 6 additions & 1 deletion src/features/Compute/CaseGroup/CaseGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export const CaseGroup = ({
setAlertMessage,
updateLocalCaseList,
runCase,
isOwner,
}: {
caseList: ComputeCaseDto[];
methodName: string;
triggerAddCase?: string;
setAlertMessage: (message: string) => void;
updateLocalCaseList?: (type: string, add: boolean) => void;
runCase: (computeCaseId: string) => void;
isOwner: () => boolean;
}) => {
const [localList, setLocalList] = useState<ComputeCaseDto[]>([]);
const { data, isLoading } = useFetchCases();
Expand Down Expand Up @@ -339,7 +341,7 @@ export const CaseGroup = ({
<Button
variant="outlined"
onClick={() => addCase(methodName)}
disabled={localList.length >= 1}
disabled={localList.length >= 1 || !isOwner()}
>
<Icon data={ADD} size={18}></Icon>
{methodName}
Expand All @@ -354,6 +356,7 @@ export const CaseGroup = ({
key={caseList.length > 0 ? caseList[0].computeCaseId : null}
addCase={addCase}
localList={localList}
isOwner={isOwner}
>
<Styled.CaseList>
{methodName === 'Channel' || methodName === 'Mouthbar' ? (
Expand All @@ -376,6 +379,7 @@ export const CaseGroup = ({
runCase={runCase}
removeLocalCase={removeLocalCase}
settingsFilter={settingsFilter}
isOwner={isOwner}
/>
))}
</>
Expand All @@ -397,6 +401,7 @@ export const CaseGroup = ({
removeLocalCase={removeLocalCase}
settingsFilter={settingsFilter}
duplicateCase={duplicateCase}
isOwner={isOwner}
/>
))}
</>
Expand Down
Loading