Skip to content

Commit

Permalink
fix: now OSCR column is hidden if feature flag is not enabled for OSCR (
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytonline committed Jul 3, 2024
1 parent cf58545 commit 061c590
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ import Checkbox from "components/atoms/Checkbox/checkbox";
interface ContributorListTableHeadersProps {
selected?: boolean;
handleOnSelectAllContributor?: (checked: boolean) => void;
showOscr?: boolean;
}

const ContributorListTableHeaders = ({ selected, handleOnSelectAllContributor }: ContributorListTableHeadersProps) => {
const ContributorListTableHeaders = ({
selected,
handleOnSelectAllContributor,
showOscr = false,
}: ContributorListTableHeadersProps) => {
const router = useRouter();
const { range } = router.query;

Expand Down Expand Up @@ -43,11 +48,13 @@ const ContributorListTableHeaders = ({ selected, handleOnSelectAllContributor }:
<TableTitle>Contributor</TableTitle>
</div>

<div className={clsx("flex-1 lg:flex justify-center lg:max-w-[5rem]")}>
<TableTitle>Rating</TableTitle>
</div>
{showOscr ? (
<div className={clsx("flex-1 lg:flex justify-center lg:max-w-[5rem]")}>
<TableTitle>Rating</TableTitle>
</div>
) : null}

<div className={clsx("flex-1 hidden lg:max-w-[6.25rem] ")}>
<div className={clsx("flex-1 hidden lg:flex lg:max-w-[6.25rem] ")}>
<TableTitle>Repositories</TableTitle>
</div>
<div className={clsx("flex-1 lg:max-w-[8.1rem] ")}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface ContributorListTableRow {
selected?: boolean;
handleOnSelectContributor?: (state: boolean, contributor: DbPRContributor) => void;
range: string;
showOscr?: boolean;
}

function getLastContributionDate(contributions: DbRepoPREvents[]) {
Expand Down Expand Up @@ -75,6 +76,7 @@ const ContributorListTableRow = ({
selected,
handleOnSelectContributor,
range,
showOscr = false,
}: ContributorListTableRow) => {
const [tableOpen, setTableOpen] = useState(false);
const login = contributor.author_login || contributor.username;
Expand Down Expand Up @@ -197,12 +199,14 @@ const ContributorListTableRow = ({
</div>

{/* Column: OSCR */}
<div className={clsx("flex-1 lg:max-w-[5rem] text-light-slate-11 justify-center lg:flex ")}>
<div className="flex gap-x-3">{contributor.oscr ? <OscrPill rating={contributor.oscr} /> ?? "-" : "-"}</div>
</div>
{showOscr ? (
<div className={clsx("flex-1 lg:max-w-[5rem] text-light-slate-11 justify-center lg:flex ")}>
<div className="flex gap-x-3">{contributor.oscr ? <OscrPill rating={contributor.oscr} /> ?? "-" : "-"}</div>
</div>
) : null}

{/* Column Repositories */}
<div className={clsx("hidden flex-1 lg:max-w-[6.25rem] flex justify-center ")}>
<div className={clsx("flex-1 hidden lg:flex lg:max-w-[6.25rem] justify-center")}>
{contributor.author_login ? repoList.length : "-"}
</div>

Expand Down
20 changes: 17 additions & 3 deletions components/organisms/ContributorsList/contributors-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface ContributorsListProps {
meta: Meta;
setPage: (page: number) => void;
range: string;
showOscr?: boolean;
}

interface ContributorCardListProps {
Expand All @@ -32,7 +33,14 @@ const ContributorCardList = ({ contributors = [], topic, range }: ContributorCar
);
};

const ContributorsList = ({ contributors, isLoading, meta, setPage, range }: ContributorsListProps) => {
const ContributorsList = ({
contributors,
isLoading,
meta,
setPage,
range,
showOscr = false,
}: ContributorsListProps) => {
const [layout, setLayout] = useState<ToggleValue>("list");

return (
Expand All @@ -48,8 +56,14 @@ const ContributorsList = ({ contributors, isLoading, meta, setPage, range }: Con
<ClientOnly>
{layout !== "grid" ? (
<>
<ContributorListTableHeaders />
<ContributorTable loading={isLoading} topic={"*"} contributors={contributors} range={range ?? 30} />
<ContributorListTableHeaders showOscr={showOscr} />
<ContributorTable
loading={isLoading}
topic={"*"}
contributors={contributors}
range={range ?? 30}
showOscr={showOscr}
/>
</>
) : (
<ContributorCardList contributors={contributors} topic={"*"} range={range ?? 30} />
Expand Down
3 changes: 3 additions & 0 deletions components/organisms/ContributorsTable/contributors-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ContributorTableProps {
handleSelectContributors?: (state: boolean, contributor: DbPRContributor) => void;
range?: string;
noContributorsMessage?: string;
showOscr?: boolean;
}

const ContributorTable = ({
Expand All @@ -20,6 +21,7 @@ const ContributorTable = ({
handleSelectContributors,
range = "30",
noContributorsMessage = "Sorry! We couldn't find any contributors.",
showOscr = false,
}: ContributorTableProps) => {
return (
<div className="flex flex-col overflow-hidden border rounded-md">
Expand All @@ -38,6 +40,7 @@ const ContributorTable = ({
}
handleOnSelectContributor={handleSelectContributors}
range={range}
showOscr={showOscr}
/>
))
) : (
Expand Down
7 changes: 3 additions & 4 deletions lib/hooks/api/useContributorList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useContributorsList = ({
initialPage = 1,
defaultLimit = 10,
defaultRange = "30",
featureFlags = {},
showOscr = false,
username,
}: {
workspaceId: string | undefined;
Expand All @@ -46,7 +46,7 @@ export const useContributorsList = ({
initialPage?: number;
defaultLimit?: number;
defaultRange?: string;
featureFlags?: Record<string, boolean>;
showOscr?: boolean;
username: string;
}) => {
const [page, setPage] = useState(initialPage);
Expand All @@ -64,8 +64,7 @@ export const useContributorsList = ({
}
);

const oscrEnabled = featureFlags ? featureFlags["oscr-rating"] : false;
const contributors = convertToContributors({ rawContributors: data?.data, username, oscrEnabled });
const contributors = convertToContributors({ rawContributors: data?.data, username, oscrEnabled: showOscr });

return {
setPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ export default function ContributorInsightEditPage({
featureFlags,
username,
}: ContributorInsightEditPageProps) {
const showOscr = featureFlags && featureFlags["oscr-rating"];
const {
data: { data: contributors },
} = useContributorsList({ workspaceId, listId: list?.id, featureFlags, username });
} = useContributorsList({ workspaceId, listId: list?.id, showOscr, username });
const initialTrackedContributors = new Map([
...contributors.map((contributor) => [contributor.author_login, true] as const),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const ListsOverview = ({
featureFlags,
username,
}: ListsOverviewProps): JSX.Element => {
const showOscr = featureFlags && featureFlags["oscr-rating"];
const router = useRouter();
const { listId, range, limit } = router.query;

Expand All @@ -117,7 +118,7 @@ const ListsOverview = ({
listId: list?.id,
defaultRange: range ? (range as string) : "30",
defaultLimit: limit ? (limit as unknown as number) : 10,
featureFlags,
showOscr,
username,
});

Expand Down Expand Up @@ -231,6 +232,7 @@ const ListsOverview = ({
isLoading={isLoading}
setPage={setPage}
range={String(range ?? "30")}
showOscr={showOscr}
/>
</ErrorBoundary>
)}
Expand Down

0 comments on commit 061c590

Please sign in to comment.