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

Feature: Cookie Landing page - Part-1 #94

Merged
merged 4 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@
}
}
},
"ignorePatterns": ["**/node_modules/**", "dist/**", "out/**", "data/"],
"ignorePatterns": [
"**/node_modules/**",
"dist/**",
"out/**",
"data/**",
"coverage/**"
],
"rules": {
"array-callback-return": "error",
"block-scoped-var": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies.
*/
import type { Meta, StoryObj } from '@storybook/react';

/**
* Internal dependencies.
*/
import Circle from '..';
import { COLOR_MAP } from '../../../theme/colors';

const meta: Meta<typeof Circle> = {
title: 'Extension/DesignSystem/Circle',
component: Circle,
tags: ['autodocs'],
};

export default meta;

export const Primary: StoryObj<typeof meta> = {
args: {
color: COLOR_MAP.functional,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

/**
* Internal dependencies.
*/
import Circle from '..';
import { COLOR_MAP } from '../../../theme/colors';

describe('Circle', () => {
it('renders the Circle with the correct background color', () => {
const { container } = render(<Circle color={COLOR_MAP.functional} />);

// Check if the Circle div has the correct background color style
const circleDiv = container.querySelector('.rounded-full');
expect(circleDiv).toHaveStyle(`background-color: ${COLOR_MAP.functional}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import React from 'react';
import { VictoryPie } from 'victory';

interface PieChartProps {
interface CirclePieChartProps {
centerCount: number;
data: { count: number; color: string }[];
}
const PieChart = ({ centerCount, data }: PieChartProps) => {
const CirclePieChart = ({ centerCount, data }: CirclePieChartProps) => {
return (
<div className="w-full h-full">
<div className="w-full h-full max-w-xs">
<div className="w-full h-full relative">
<VictoryPie
padding={0}
Expand All @@ -43,4 +43,4 @@ const PieChart = ({ centerCount, data }: PieChartProps) => {
);
};

export default PieChart;
export default CirclePieChart;
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies.
*/
import type { Meta, StoryObj } from '@storybook/react';

/**
* Internal dependencies.
*/
import CirclePieChart from '..';
import { COLOR_MAP } from '../../../theme/colors';

const meta: Meta<typeof CirclePieChart> = {
title: 'Extension/DesignSystem/CirclePieChart',
component: CirclePieChart,
tags: ['autodocs'],
};

export default meta;

export const Primary: StoryObj<typeof meta> = {
args: {
centerCount: 5,
data: [
{
count: 5,
color: COLOR_MAP.functional,
},
{
count: 4,
color: COLOR_MAP.marketing,
},
{
count: 0,
color: COLOR_MAP.analytics,
},
{
count: 9,
color: COLOR_MAP.uncategorised,
},
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

/**
* Internal dependencies.
*/
import CirclePieChart from '..';

describe('CirclePieChart', () => {
const testData = [
{ count: 25, color: 'red' },
{ count: 50, color: 'blue' },
{ count: 75, color: 'green' },
];
const centerCount = 150;

it('renders the VictoryPie chart with the correct data', () => {
const { container } = render(
<CirclePieChart centerCount={centerCount} data={testData} />
);

// Check if the VictoryPie is rendered with the correct data
const paths = container.querySelectorAll('path[role="presentation"]');
expect(paths.length).toBe(testData.length);
});

it('renders the centerCount text', () => {
const { getByText } = render(
<CirclePieChart centerCount={centerCount} data={testData} />
);

// Check if the centerCount text is rendered
const text: string = centerCount.toString();
const centerCountElement = getByText(text);
expect(centerCountElement).toBeInTheDocument();
});
});
17 changes: 17 additions & 0 deletions packages/extension/src/view/design-system/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { default as CirclePieChart } from './circlePieChart';
export { default as Circle } from './circle';
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Accordion from '..';
// @todo To be removed after we add any story.
// More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
const meta: Meta<typeof Accordion> = {
title: 'Extension/Accordion',
title: 'Extension/DevTools/Accordion',
component: Accordion,
tags: ['autodocs'],
argTypes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Meta, StoryObj } from '@storybook/react';
import { CookieDetails } from '../..';

const meta = {
title: 'Extension/CookiesPanel/CookieDetails',
title: 'Extension/DevTools/CookiesPanel/CookieDetails',
component: CookieDetails,
tags: ['autodocs'],
} as Meta<typeof CookieDetails>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Details from '../details';
import type { CookieTableData } from '../../../../../../stateProviders/syncCookieStore';

const meta = {
title: 'Extension/CookiesPanel/CookieDetails/Details',
title: 'Extension/DevTools/CookiesPanel/CookieDetails/Details',
component: Details,
tags: ['autodocs'],
} as Meta<typeof Details>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { TempCookieData } from './tempData';
import { CookieTable } from '../..';

const meta = {
title: 'Extension/CookiesPanel/CookieTable',
title: 'Extension/DevTools/CookiesPanel/CookieTable',
component: CookieTable,
tags: ['autodocs'],
} as Meta<typeof CookieTable>;
Expand Down
9 changes: 5 additions & 4 deletions packages/extension/src/view/popup/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import React from 'react';
* Internal dependencies.
*/
import './app.css';
import { PieChart, Legend } from './components';
import { Legend } from './components';
import { useCookieStore } from './stateProviders/syncCookieStore';
import { COLOR_MAP } from './const';
import { COLOR_MAP } from '../design-system/theme/colors';
import { CirclePieChart } from '../design-system/components';

const App: React.FC = () => {
const { cookieStats } = useCookieStore(({ state }) => ({
Expand Down Expand Up @@ -124,7 +125,7 @@ const App: React.FC = () => {
<div className="w-full h-full flex flex-col justify-center items-center">
<div className="flex-1 w-full">
{cookieStats.firstParty.total ? (
<PieChart
<CirclePieChart
centerCount={cookieStats.firstParty.total}
data={firstPartyPiechartData}
/>
Expand All @@ -141,7 +142,7 @@ const App: React.FC = () => {
<div className="w-full h-full flex flex-col justify-center items-center">
<div className="flex-1 w-full h-full">
{cookieStats.thirdParty.total ? (
<PieChart
<CirclePieChart
centerCount={cookieStats.thirdParty.total}
data={thirdPartyPiechartData}
/>
Expand Down
2 changes: 0 additions & 2 deletions packages/extension/src/view/popup/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export { default as PieChart } from './pieChart';
export { default as Legend } from './legend';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react';
/**
* Internal dependencies.
*/
import Circle from './circle';
import { Circle } from '../../../design-system/components';

interface LegendProps {
legendItemList: { label: string; count: number; color: string }[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* External dependencies.
*/
import type { Meta, StoryObj } from '@storybook/react';

/**
* Internal dependencies.
*/
import Legend from '..';
import { COLOR_MAP } from '../../../../design-system/theme/colors';

const meta: Meta<typeof Legend> = {
title: 'Extension/Popup/Legend',
component: Legend,
tags: ['autodocs'],
};

export default meta;

export const Primary: StoryObj<typeof meta> = {
args: {
legendItemList: [
{ label: 'Functional', count: 10, color: COLOR_MAP.functional },
{ label: 'Marketing', count: 20, color: COLOR_MAP.marketing },
{ label: 'Analytics', count: 22, color: COLOR_MAP.analytics },
{ label: 'Uncategorised', count: 11, color: COLOR_MAP.uncategorised },
],
},
};
Loading