Skip to content

Commit

Permalink
feat(issue and respond to RAIs): Implement post sub actions for issui…
Browse files Browse the repository at this point in the history
…ng and responding to RAIs (#197)

* Show issue rai for all records for cms user

* basic routing setup

* base

* form work

* nothing

* basic func

* sink

* yut

* brians lib

* fix thing

* bringing in brian

* add functionality for sinking actions to opensearch

* remove action-type from schema (not needed)

* fix breadcrumb type error

* finished up flow (fingers crossed)

* fix typescript error for tombstone

* get the last item in array

* update with timestamp from frontend

* update status

* move to using a transaction with rollback etc

* REVERTME  push raw onemac records to other index

* fix thing

* fix for attachments ullish

* increase timeout

* stop custom compaction for onemac

* fix deletes

* udpates per brian

* pass action on enable thing

* asdf

* Change how we get state

* put id in the payload, as it doesnt come back from safe parse

* sending stuff to onemac

* yut

* rework.  change state cms to request response

* set sinkSeatool to start putting the timestamps in the right place

* fixes

* breadcrumbs

* turn modal on

* cleanup

* show rais

* remove check

* rename to make more sense

* update getAttachmentUrl to allow download of rai attachments

* change format

* rm debug

* handle old rais

* ok

* k

* add a thing to catch rais with no requested date

* functional ui etc

* add seatool status

* correction

* pushing the logic on package actions further

* start showing response data and fix some issues

* working with reindex

* danger

* set explicit dep

* Add explicit dependency so we dont start sinking before weve setup the index

* frontend stuff

* yut

* get actie

* fix get package actions

* functional, but the timestamps on response is getting jacked

* open collapsed

* enumerte and stuff

* updates

* https://qmacbis.atlassian.net/browse/OY2-26267 fix

* fixes etc

* Add submitter name

* Whered he go      Whered whooooo go.  REVERT ME

* Fix logic

* who are we to limit ourselves.  how arrogant

* correct helper

* Fix attachmenturl thing to include response attachments

* some fixes per padma

* drop these cases

* fixes

* Let all pending statuses issue an rai

* response fixes

* yut

* modals for issue

* modals for response

* remove dev thing

* i think this looks bad and is redundant

* language

* 11

* error handling and fixes

* fix 13

* add package details consistently

* put a sentence back

* language

* fix up role logic.. user helper could probably go for some refactoring

* Update text at bottom

* fix broken disable bit

* use blank value

* remove

* update  faq links

* drop unneeded markup

* little bit of cleanup

---------

Co-authored-by: 13bfrancis <[email protected]>
  • Loading branch information
mdial89f and 13bfrancis authored Nov 20, 2023
1 parent b7d3c8f commit 03472d1
Show file tree
Hide file tree
Showing 32 changed files with 1,437 additions and 372 deletions.
36 changes: 36 additions & 0 deletions src/libs/opensearch-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,40 @@ export async function getItem(host:string, index:string, id:string){
} catch(e) {
console.log({e})
}
}

export async function createIndexIfNotExists(host:string, index:string) {
client = client || (await getClient(host));
try {
const indexExists = await client.indices.exists({ index, });
if (!indexExists.body) {
const createResponse = await client.indices.create({
index,
});

console.log('Index created:', createResponse);
} else {
console.log('Index already exists.');
}
} catch (error) {
console.error('Error creating index:', error);
throw error;
}
}

export async function updateFieldMapping(host:string, index:string, properties: object) {
client = client || (await getClient(host));
try {
const response = await client.indices.putMapping({
index: index,
body: {
properties,
},
});

console.log('Field mapping updated:', response);
} catch (error) {
console.error('Error updating field mapping:', error);
throw error;
}
}
1 change: 0 additions & 1 deletion src/packages/shared-types/action-types/withdraw-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ import { z } from "zod";
export const withdrawRecordSchema = z.object({
raiWithdrawEnabled: z.boolean(),
});

export type WithdrawRecord = z.infer<typeof withdrawRecordSchema>;
1 change: 1 addition & 0 deletions src/packages/shared-types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export enum Action {
ENABLE_RAI_WITHDRAW = "enable-rai-withdraw",
DISABLE_RAI_WITHDRAW = "disable-rai-withdraw",
ISSUE_RAI = "issue-rai",
RESPOND_TO_RAI = "respond-to-rai",
}
204 changes: 140 additions & 64 deletions src/packages/shared-types/onemac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,88 @@ const onemacAttachmentSchema = z.object({
key: z.string().nullish(),
uploadDate: z.number().nullish(),
});
export type OnemacAttachmentSchema = z.infer<typeof onemacAttachmentSchema>;

export const raiSchema = z.object({
id: z.string(),
requestedDate: z.number(),
responseDate: z.number().nullish(),
withdrawnDate: z.number().nullish(),
attachments: z.array(onemacAttachmentSchema).nullish(),
additionalInformation: z.string().nullable().default(null),
submitterName: z.string(),
submitterEmail: z.string(),
});
export type RaiSchema = z.infer<typeof raiSchema>;

export interface RaiData {
[key: number]: {
requestedDate?: string;
responseDate?: string;
withdrawnDate?: string;
response?: {
additionalInformation: string;
submitterName: string | null;
submitterEmail: string | null;
attachments: any[] | null; // You might want to specify the type of attachments
};
request?: {
additionalInformation: string;
submitterName: string | null;
submitterEmail: string | null;
attachments: any[] | null; // You might want to specify the type of attachments
};
};
}

export const transformRaiIssue = (id: string) => {
return raiSchema.transform((data) => ({
id,
rais: {
[data.requestedDate]: {
request: {
attachments:
data.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
additionalInformation: data.additionalInformation,
submitterName: data.submitterName,
submitterEmail: data.submitterEmail,
},
},
},
}));
};
export type RaiIssueTransform = z.infer<ReturnType<typeof transformRaiIssue>>;

export const transformRaiResponse = (id: string) => {
return raiSchema.transform((data) => ({
id,
rais: {
[data.requestedDate]: {
response: {
attachments:
data.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
additionalInformation: data.additionalInformation,
submitterName: data.submitterName,
submitterEmail: data.submitterEmail,
},
},
},
}));
};
export type RaiResponseTransform = z.infer<
ReturnType<typeof transformRaiResponse>
>;

export const onemacSchema = z.object({
additionalInformation: z.string().nullable().default(null),
submitterName: z.string(),
submitterEmail: z.string(),
attachments: z.array(onemacAttachmentSchema).nullish(),
raiWithdrawEnabled: z.boolean().optional(),
raiWithdrawEnabled: z.boolean().default(false),
raiResponses: z
.array(
z.object({
Expand All @@ -30,75 +105,76 @@ export const onemacSchema = z.object({
});

export const transformOnemac = (id: string) => {
return onemacSchema.transform((data) => ({
id,
attachments:
data.attachments?.map((attachment) => {
// this is a legacy onemac attachment
let bucket = "";
let key = "";
let uploadDate = 0;
if ("bucket" in attachment) {
bucket = attachment.bucket as string;
}
if ("key" in attachment) {
key = attachment.key as string;
}
if ("uploadDate" in attachment) {
uploadDate = attachment.uploadDate as number;
}
if (bucket == "") {
const parsedUrl = s3ParseUrl(attachment.url || "");
if (!parsedUrl) return null;
bucket = parsedUrl.bucket;
key = parsedUrl.key;
uploadDate = parseInt(attachment.s3Key?.split("/")[0] || "0");
}

return {
title: attachment.title,
filename: attachment.filename,
uploadDate,
bucket,
key,
return onemacSchema.transform((data) => {
const transformedData = {
id,
attachments:
data.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
raiWithdrawEnabled: data.raiWithdrawEnabled,
additionalInformation: data.additionalInformation,
submitterEmail: data.submitterEmail,
submitterName: data.submitterName === "-- --" ? null : data.submitterName,
origin: "oneMAC",
rais: {} as RaiData,
};
if (data.raiResponses) {
data.raiResponses.forEach((raiResponse, index) => {
// We create an rai keyed off the index, because we don't know which rai it was in response to. Best we can do.
transformedData["rais"][index] = {
responseDate: raiResponse.submissionTimestamp.toString(),
response: {
additionalInformation: raiResponse.additionalInformation || "",
submitterName: null,
submitterEmail: null,
attachments:
raiResponse.attachments?.map((attachment) => {
return handleAttachment(attachment);
}) ?? null,
},
};
}) ?? null,
raiWithdrawEnabled: data.raiWithdrawEnabled,
raiResponses:
data.raiResponses?.map((response) => {
return {
additionalInformation: response.additionalInformation,
submissionTimestamp: response.submissionTimestamp,
attachments:
response.attachments?.map((attachment) => {
const uploadDate = parseInt(
attachment.s3Key?.split("/")[0] || "0"
);
const parsedUrl = s3ParseUrl(attachment.url || "");
if (!parsedUrl) return null;
const { bucket, key } = parsedUrl;

return {
...attachment,
uploadDate,
bucket,
key,
};
}) ?? null,
};
}) ?? null,
additionalInformation: data.additionalInformation,
submitterEmail: data.submitterEmail,
submitterName: data.submitterName === "-- --" ? null : data.submitterName,
origin: "oneMAC",
}));
});
}
return transformedData;
});
};

export type OneMacSink = z.infer<typeof onemacSchema>;
export type OneMacTransform = z.infer<ReturnType<typeof transformOnemac>>;
export type OneMacRecordsToDelete = Omit<
{
[Property in keyof OneMacTransform]: undefined;
[Property in keyof OneMacTransform]: null;
},
"id"
"id" | "rais"
> & { id: string };

function handleAttachment(attachment: OnemacAttachmentSchema) {
let bucket = "";
let key = "";
let uploadDate = 0;
if ("bucket" in attachment) {
bucket = attachment.bucket as string;
}
if ("key" in attachment) {
key = attachment.key as string;
}
if ("uploadDate" in attachment) {
uploadDate = attachment.uploadDate as number;
}
if (bucket == "") {
const parsedUrl = s3ParseUrl(attachment.url || "");
if (!parsedUrl) return null;
bucket = parsedUrl.bucket;
key = parsedUrl.key;
uploadDate = parseInt(attachment.s3Key?.split("/")[0] || "0");
}

return {
title: attachment.title,
filename: attachment.filename,
uploadDate,
bucket,
key,
};
}
6 changes: 4 additions & 2 deletions src/packages/shared-types/opensearch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SeaToolTransform } from "./seatool";
import { OneMacTransform } from "./onemac";
import { OneMacTransform, RaiIssueTransform } from "./onemac";
import { Action } from "./actions";

export type OsHit<T> = {
Expand Down Expand Up @@ -32,7 +32,9 @@ export type OsResponse<T> = {
aggregations?: OsAggResult;
};

export type OsMainSourceItem = OneMacTransform & SeaToolTransform;
export type OsMainSourceItem = OneMacTransform &
SeaToolTransform &
RaiIssueTransform;
export type OsMainSearchResponse = OsResponse<OsMainSourceItem>;
export type SearchData = OsHits<OsMainSourceItem>;
export type ItemResult = OsHit<OsMainSourceItem> & {
Expand Down
Loading

0 comments on commit 03472d1

Please sign in to comment.