Skip to content

Commit

Permalink
Merge pull request #206 from bitovi/TR-100-Team-Issue-Configuration
Browse files Browse the repository at this point in the history
Tr 100 team issue configuration
  • Loading branch information
DavidNic11 authored Nov 15, 2024
2 parents 7b16a0d + fcd6a62 commit 186f93f
Show file tree
Hide file tree
Showing 17 changed files with 461 additions and 263 deletions.
47 changes: 23 additions & 24 deletions public/jira-oidc-helpers/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@ import { hasValidAccessToken } from "./auth";
import { Config, FieldsRequest } from "./types";

export function fetchJiraFields(config: Config) {
return () => {
return config.requestHelper(`/api/3/field`);
};
return () => {
return config.requestHelper(`/api/3/field`);
};
}
export function makeFieldsRequest(config: Config, setFieldsRequest: (req: FieldsRequest) => void) {
if (config.host === "jira" || hasValidAccessToken()) {
const req = fetchJiraFields(config)().then((fields) => {
const nameMap: Record<string, any> = {};
const idMap: Record<string, any> = {};
// @ts-ignore
fields.forEach((f) => {
// @ts-ignore
idMap[f.id] = f.name;
// @ts-ignore
nameMap[f.name] = f.id;
});
console.log(nameMap);
if (config.host === "jira" || hasValidAccessToken()) {
const req = fetchJiraFields(config)().then((fields) => {
const nameMap: Record<string, any> = {};
const idMap: Record<string, any> = {};
// @ts-ignore
fields.forEach((f) => {
// @ts-ignore
idMap[f.id] = f.name;
// @ts-ignore
nameMap[f.name] = f.id;
});

return {
list: fields,
nameMap: nameMap,
idMap: idMap,
};
});
return {
list: fields,
nameMap: nameMap,
idMap: idMap,
};
});

setFieldsRequest(req)
}
}
setFieldsRequest(req);
}
}
6 changes: 3 additions & 3 deletions public/jira/normalized/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test("getParentKeyDefault", () => {
});

test("getDaysPerSprintDefault", () => {
expect(getDaysPerSprintDefault("")).toBe(10);
expect(getDaysPerSprintDefault(createFields())).toBe(10);
});

test("getStartDateDefault", () => {
Expand Down Expand Up @@ -134,11 +134,11 @@ test("getTypeDefault", () => {
});

test("getVelocityDefault", () => {
expect(getVelocityDefault("")).toBe(21);
expect(getVelocityDefault(createFields())).toBe(21);
});

test("getParallelWorkLimitDefault", () => {
expect(getParallelWorkLimitDefault("")).toBe(1);
expect(getParallelWorkLimitDefault(createFields())).toBe(1);
});

test("getSprintsDefault", () => {
Expand Down
143 changes: 118 additions & 25 deletions public/jira/normalized/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { parseDateISOString } from "../../date-helpers";
import { JiraIssue, NormalizedIssue, ParentIssue } from "../shared/types";
import { NormalizeIssueConfig } from "./normalize";

type Prettify<T> = {
[K in keyof T]: T[K];
} & {};

type ParentField<F extends keyof ParentIssue["fields"]> = {
fields: Pick<ParentIssue["fields"], F>;
Expand All @@ -19,42 +24,100 @@ export function getSummaryDefault({ fields }: ParentField<"summary"> | ChildFiel
return fields.Summary;
}

export function getDueDateDefault({ key, fields }: Pick<JiraIssue, "key" | "fields">): string | null {
type DueDateMinimalIssue = {
fields: {
"Due date"?: JiraIssue["fields"]["Due date"];
[key: string]: unknown;
};
} & MinimalIssueTypeIssue &
MinimalHierarchyLevelIssue &
MinimalTeamKeyIssue;

export function getDueDateDefault(
{ fields }: DueDateMinimalIssue,
otpions?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): string | null {
return fields["Due date"] || null;
}

export function getStartDateDefault({ key, fields }: Pick<JiraIssue, "key" | "fields">): string | null {
type StartDateMinimalIssue = {
fields: {
"Start date"?: JiraIssue["fields"]["Start date"];
[key: string]: unknown;
};
} & MinimalIssueTypeIssue &
MinimalHierarchyLevelIssue &
MinimalTeamKeyIssue;

export function getStartDateDefault(
{ fields }: StartDateMinimalIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): string | null {
return fields["Start date"] || null;
}

export function getStoryPointsDefault({
key,
fields,
}: Pick<JiraIssue, "key" | "fields">): NormalizedIssue["storyPoints"] {
type StoryPointsMinimalIssue = {
fields: {
"Story points"?: JiraIssue["fields"]["Story points"];
[key: string]: unknown;
};
} & MinimalIssueTypeIssue &
MinimalHierarchyLevelIssue &
MinimalTeamKeyIssue;

export function getStoryPointsDefault(
{ key, fields }: StoryPointsMinimalIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["storyPoints"] {
return fields["Story points"] || null;
}

export function getStoryPointsMedianDefault({
key,
fields,
}: Pick<JiraIssue, "key" | "fields">): NormalizedIssue["storyPointsMedian"] {
type StoryPointsMedianMinimalIssue = {
fields: {
"Story points median"?: JiraIssue["fields"]["Story points median"];
[key: string]: unknown;
};
} & MinimalIssueTypeIssue &
MinimalHierarchyLevelIssue &
MinimalTeamKeyIssue;

export function getStoryPointsMedianDefault(
{ key, fields }: StoryPointsMedianMinimalIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["storyPointsMedian"] {
return fields["Story points median"] || null;
}

export function getRankDefault({ fields }: Fields): NormalizedIssue["rank"] {
return fields?.Rank || null;
}

export function getConfidenceDefault({
key,
fields,
}: Pick<JiraIssue, "key" | "fields">): NormalizedIssue["confidence"] {
type ConfidenceMinimalIssue = {
fields: {
"Story points confidence"?: JiraIssue["fields"]["Story points confidence"];
Confidence?: JiraIssue["fields"]["Confidence"];
[key: string]: unknown;
};
} & MinimalIssueTypeIssue &
MinimalHierarchyLevelIssue &
MinimalTeamKeyIssue;

export function getConfidenceDefault(
{ fields }: ConfidenceMinimalIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["confidence"] {
return fields["Story points confidence"] || fields?.Confidence || null;
}

export function getHierarchyLevelDefault({
fields,
}: ChildField<"Issue Type"> | ParentField<"issuetype">): NormalizedIssue["hierarchyLevel"] {
type MinimalHierarchyLevelIssue = {
fields:
| {
issuetype: ParentIssue["fields"]["issuetype"];
}
| { "Issue Type": JiraIssue["fields"]["Issue Type"] };
};

export function getHierarchyLevelDefault({ fields }: MinimalHierarchyLevelIssue): NormalizedIssue["hierarchyLevel"] {
const issueType = "Issue Type" in fields ? fields["Issue Type"] : fields.issuetype;

if (typeof issueType === "string") {
Expand All @@ -80,16 +143,28 @@ export function getUrlDefault({ key }: Pick<JiraIssue, "key">): NormalizedIssue[
return "javascript://";
}

export function getTeamKeyDefault({ key, fields }: Pick<JiraIssue, "key" | "fields">): NormalizedIssue["team"]["name"] {
interface MinimalTeamKeyIssue {
key: JiraIssue["key"];
fields: { Team: JiraIssue["fields"]["Team"] };
}

export function getTeamKeyDefault({ key, fields }: MinimalTeamKeyIssue): NormalizedIssue["team"]["name"] {
if (fields.Team?.name) {
return fields.Team.name;
}

return key.replace(/-.*/, "");
}

export function getTypeDefault({
fields,
}: ChildField<"Issue Type"> | ParentField<"issuetype">): NormalizedIssue["type"] {
type MinimalIssueTypeIssue = {
fields:
| {
issuetype: ParentIssue["fields"]["issuetype"];
}
| { "Issue Type": JiraIssue["fields"]["Issue Type"] };
};

export function getTypeDefault({ fields }: MinimalIssueTypeIssue): NormalizedIssue["type"] {
const issueType = "Issue Type" in fields ? fields["Issue Type"] : fields.issuetype;

if (typeof issueType === "string") {
Expand Down Expand Up @@ -146,20 +221,38 @@ export function getReleasesDefault({ fields }: Fields): NormalizedIssue["release
});
}

export function getVelocityDefault(teamKey: string): NormalizedIssue["team"]["velocity"] {
type MinimalVelocityIssue = Prettify<MinimalTeamKeyIssue & MinimalIssueTypeIssue & MinimalHierarchyLevelIssue>;

export function getVelocityDefault(
issue: MinimalVelocityIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["team"]["velocity"] {
return 21;
}

export function getParallelWorkLimitDefault(teamKey: string): NormalizedIssue["team"]["parallelWorkLimit"] {
type MinimalParallelWorkLimitIssue = Prettify<MinimalTeamKeyIssue & MinimalIssueTypeIssue & MinimalHierarchyLevelIssue>;

export function getParallelWorkLimitDefault(
issue: MinimalParallelWorkLimitIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["team"]["parallelWorkLimit"] {
return 1;
}

export function getDaysPerSprintDefault(teamKey: string): NormalizedIssue["team"]["daysPerSprint"] {
type MinimalDaysPerSprintIssue = Prettify<MinimalTeamKeyIssue & MinimalIssueTypeIssue & MinimalHierarchyLevelIssue>;

export function getDaysPerSprintDefault(
issue: MinimalDaysPerSprintIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["team"]["daysPerSprint"] {
return 10;
}

type MinimalTeamSpreadEffortIssue = Prettify<MinimalTeamKeyIssue & MinimalIssueTypeIssue & MinimalHierarchyLevelIssue>;

export function getTeamSpreadsEffortAcrossDatesDefault(
teamKey?: string
issue: MinimalTeamSpreadEffortIssue,
options?: Pick<NormalizeIssueConfig, "getTeamKey" | "getType" | "getHierarchyLevel">
): NormalizedIssue["team"]["spreadEffortAcrossDates"] {
return false;
}
Loading

0 comments on commit 186f93f

Please sign in to comment.