Skip to content

Commit

Permalink
feat(OY2-26203): Add OS Action Column
Browse files Browse the repository at this point in the history
  • Loading branch information
pkim-gswell committed Dec 11, 2023
1 parent 113db94 commit 2bdb7e5
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 261 deletions.
1 change: 1 addition & 0 deletions src/packages/shared-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from "./authority";
export * from "./action-types/withdraw-record";
export * from "./forms";
export * from "./inputs";
export * from "./statusHelper";
1 change: 1 addition & 0 deletions src/packages/shared-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from "./s3-url-parser";
export { isStateUser } from "./is-state-user";
export * from "./rai-helper";
export * from "./regex";
export * from './package-actions'
56 changes: 56 additions & 0 deletions src/packages/shared-utils/package-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Action, CognitoUserAttributes, OsMainSourceItem, SEATOOL_STATUS } from "../shared-types";
import { getLatestRai } from './rai-helper'
import { isCmsWriteUser } from './user-helper'
import { isStateUser } from "./user-helper";

export const packageActionsForResult = (
user: CognitoUserAttributes,
result: OsMainSourceItem
): Action[] => {
const actions = [] as any[];
const latestRai = getLatestRai(result?.rais || {});
if (isCmsWriteUser(user)) {
switch (result.seatoolStatus) {
case SEATOOL_STATUS.PENDING:
case SEATOOL_STATUS.PENDING_OFF_THE_CLOCK:
case SEATOOL_STATUS.PENDING_APPROVAL:
case SEATOOL_STATUS.PENDING_CONCURRENCE:
if (!latestRai || latestRai.status != "requested") {
// If there is no RAIs, or the latest RAI is in a state other than requested
actions.push(Action.ISSUE_RAI);
}
break;
}
if (latestRai?.status == "received") {
// There's an RAI and its been responded to
if (!result.raiWithdrawEnabled) {
actions.push(Action.ENABLE_RAI_WITHDRAW);
}
if (result.raiWithdrawEnabled) {
actions.push(Action.DISABLE_RAI_WITHDRAW);
}
}
} else if (isStateUser(user)) {
switch (result.seatoolStatus) {
case SEATOOL_STATUS.PENDING_RAI:
if (latestRai?.status == "requested") {
// If there is an active RAI
actions.push(Action.RESPOND_TO_RAI);
}
break;
case SEATOOL_STATUS.PENDING:
case SEATOOL_STATUS.PENDING_OFF_THE_CLOCK:
case SEATOOL_STATUS.PENDING_APPROVAL:
case SEATOOL_STATUS.PENDING_CONCURRENCE:
if (
latestRai?.status == "received" &&
result.raiWithdrawEnabled
) {
// There is an rai that's been responded to, but not withdrawn
actions.push(Action.WITHDRAW_RAI);
}
break;
}
}
return actions;
};
60 changes: 2 additions & 58 deletions src/services/api/handlers/getPackageActions.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,17 @@
import { APIGatewayEvent } from "aws-lambda";
import { Action, CognitoUserAttributes, ItemResult } from "shared-types";
import { isCmsUser, isCmsWriteUser, getLatestRai } from "shared-utils";
import { isStateUser } from "shared-utils/is-state-user";
import { packageActionsForResult } from "shared-utils";
import { getPackage } from "../libs/package/getPackage";
import {
getAuthDetails,
isAuthorized,
lookupUserAttributes,
} from "../libs/auth/user";
import { response } from "../libs/handler";
import { SEATOOL_STATUS } from "shared-types/statusHelper";

type GetPackageActionsBody = {
id: string;
};

/** Generates an array of allowed actions from a combination of user attributes
* and OS result data */
export const packageActionsForResult = (
user: CognitoUserAttributes,
result: ItemResult
): Action[] => {
const actions = [];
const latestRai = getLatestRai(result._source.rais);
if (isCmsWriteUser(user)) {
switch (result._source.seatoolStatus) {
case SEATOOL_STATUS.PENDING:
case SEATOOL_STATUS.PENDING_OFF_THE_CLOCK:
case SEATOOL_STATUS.PENDING_APPROVAL:
case SEATOOL_STATUS.PENDING_CONCURRENCE:
if (!latestRai || latestRai.status != "requested") {
// If there is no RAIs, or the latest RAI is in a state other than requested
actions.push(Action.ISSUE_RAI);
}
break;
}
if (latestRai?.status == "received") {
// There's an RAI and its been responded to
if (!result._source.raiWithdrawEnabled) {
actions.push(Action.ENABLE_RAI_WITHDRAW);
}
if (result._source.raiWithdrawEnabled) {
actions.push(Action.DISABLE_RAI_WITHDRAW);
}
}
} else if (isStateUser(user)) {
switch (result._source.seatoolStatus) {
case SEATOOL_STATUS.PENDING_RAI:
if (latestRai?.status == "requested") {
// If there is an active RAI
actions.push(Action.RESPOND_TO_RAI);
}
break;
case SEATOOL_STATUS.PENDING:
case SEATOOL_STATUS.PENDING_OFF_THE_CLOCK:
case SEATOOL_STATUS.PENDING_APPROVAL:
case SEATOOL_STATUS.PENDING_CONCURRENCE:
if (
latestRai?.status == "received" &&
result._source.raiWithdrawEnabled
) {
// There is an rai that's been responded to, but not withdrawn
actions.push(Action.WITHDRAW_RAI);
}
break;
}
}
return actions;
};
export const getPackageActions = async (event: APIGatewayEvent) => {
const body = JSON.parse(event.body) as GetPackageActionsBody;
try {
Expand All @@ -94,7 +38,7 @@ export const getPackageActions = async (event: APIGatewayEvent) => {
return response({
statusCode: 200,
body: {
actions: packageActionsForResult(userAttr, result),
actions: packageActionsForResult(userAttr, result._source),
},
});
} catch (err) {
Expand Down
19 changes: 11 additions & 8 deletions src/services/ui/src/components/Opensearch/Settings/Visibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cn } from "@/lib/utils";
import { EyeIcon, EyeOffIcon } from "lucide-react";
import * as UI from "@/components/Popover";

type Item = { label: string; field: string; hidden: boolean };
type Item = { label: string; field?: string; hidden: boolean };

type Props<T extends Item> = {
list: T[];
Expand Down Expand Up @@ -51,13 +51,16 @@ export const VisiblityItem = <T extends Item>(
export const VisibilityMenu = <T extends Item>(props: Props<T>) => {
return (
<div className="flex flex-col gap-2">
{props.list.map((IT) => (
<VisiblityItem
key={`vis-${IT.field}`}
onClick={() => props.onItemClick(IT.field)}
{...IT}
/>
))}
{props.list.map((IT) => {
if (!IT.field) return null;
return (
<VisiblityItem
key={`vis-${IT.field}`}
onClick={() => props.onItemClick(IT.field as string)}
{...IT}
/>
);
})}
</div>
);
};
13 changes: 8 additions & 5 deletions src/services/ui/src/components/Opensearch/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useOsContext } from "../Provider";
import { useOsParams } from "../useOpensearch";
import { VisibilityPopover } from "../Settings";
import { BLANK_VALUE } from "@/consts";
import { OsField } from "shared-types";

export const OsTable: FC<{
columns: OsTableColumn[];
Expand Down Expand Up @@ -39,7 +40,7 @@ export const OsTable: FC<{
className="w-[10px]"
icon={
<VisibilityPopover
list={osColumns.filter((COL) => !COL.locked)}
list={osColumns.filter((COL) => !COL.locked || COL.field)}
onItemClick={onToggle}
/>
}
Expand All @@ -52,15 +53,17 @@ export const OsTable: FC<{
key={`TH-${TH.field}`}
isActive={params.state.sort.field === TH.field}
desc={params.state.sort.order === "desc"}
onClick={() =>
{...(TH.isSystem && { className: "pointer-events-none" })}
onClick={() => {
if (!TH.field) return;
params.onSet((s) => ({
...s,
sort: {
field: TH.field,
field: TH.field as OsField,
order: s.sort.order === "desc" ? "asc" : "desc",
},
}))
}
}));
}}
>
{TH.label}
</UI.TableHead>
Expand Down
3 changes: 2 additions & 1 deletion src/services/ui/src/components/Opensearch/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import type { OsField, OsHit, OsMainSourceItem } from "shared-types";
import type { ReactNode } from "react";

export type OsTableColumn = {
field: OsField;
field?: OsField;
label: string;
visible?: boolean;
locked?: boolean;
isSystem?: boolean;
props?: any;
cell: (data: OsHit<OsMainSourceItem>["_source"]) => ReactNode;
};
Loading

0 comments on commit 2bdb7e5

Please sign in to comment.