-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
packages/design-system/src/components/cookieTable/utils/conditionalTableRowClassesHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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 { CookieTableData, getCookieKey } from '@ps-analysis-tool/common'; | ||
import classnames from 'classnames'; | ||
|
||
import { TableRow } from '../../table'; | ||
|
||
// eslint-disable-next-line complexity | ||
const conditionalTableRowClassesHandler = ( | ||
row: TableRow, | ||
isRowFocused: boolean, | ||
rowIndex: number, | ||
selectedKey: string | null | ||
) => { | ||
const rowKey = getCookieKey( | ||
(row?.originalData as CookieTableData).parsedCookie | ||
) as string; | ||
const isBlocked = | ||
(row.originalData as CookieTableData)?.isBlocked || | ||
(((row.originalData as CookieTableData)?.isBlocked ?? false) && | ||
(row.originalData as CookieTableData)?.blockedReasons && | ||
(row.originalData as CookieTableData)?.blockedReasons?.length); | ||
const isHighlighted = row.originalData?.highlighted; | ||
const isDomainInAllowList = (row.originalData as CookieTableData) | ||
?.isDomainInAllowList; | ||
|
||
const tableRowClassName = classnames( | ||
isBlocked && | ||
(rowKey !== selectedKey | ||
? rowIndex % 2 | ||
? 'dark:bg-flagged-row-even-dark bg-flagged-row-even-light' | ||
: 'dark:bg-flagged-row-odd-dark bg-flagged-row-odd-light' | ||
: isRowFocused | ||
? 'bg-gainsboro dark:bg-outer-space' | ||
: 'bg-royal-blue text-white dark:bg-medium-persian-blue dark:text-chinese-silver'), | ||
isDomainInAllowList && | ||
!isBlocked && | ||
(rowKey !== selectedKey | ||
? rowIndex % 2 | ||
? 'dark:bg-jungle-green-dark bg-leaf-green-dark' | ||
: 'dark:bg-jungle-green-light bg-leaf-green-light' | ||
: isRowFocused | ||
? 'bg-gainsboro dark:bg-outer-space' | ||
: 'bg-royal-blue text-white dark:bg-medium-persian-blue dark:text-chinese-silver'), | ||
rowKey !== selectedKey && | ||
!isBlocked && | ||
!isDomainInAllowList && | ||
(rowIndex % 2 | ||
? isHighlighted | ||
? 'bg-dirty-pink' | ||
: 'bg-anti-flash-white dark:bg-charleston-green' | ||
: isHighlighted | ||
? 'bg-dirty-pink text-dirty-red dark:text-dirty-red text-dirty-red' | ||
: 'bg-white dark:bg-raisin-black'), | ||
rowKey === selectedKey && | ||
!isBlocked && | ||
!isDomainInAllowList && | ||
(isRowFocused | ||
? isHighlighted | ||
? 'bg-dirty-red' | ||
: 'bg-gainsboro dark:bg-outer-space' | ||
: isHighlighted | ||
? 'bg-dirty-pink text-dirty-red' | ||
: 'bg-royal-blue text-white dark:bg-medium-persian-blue dark:text-chinese-silver') | ||
); | ||
|
||
return tableRowClassName; | ||
}; | ||
|
||
export default conditionalTableRowClassesHandler; |
37 changes: 37 additions & 0 deletions
37
packages/design-system/src/components/cookieTable/utils/exportCookies.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 { CookieTableData } from '@ps-analysis-tool/common'; | ||
import { saveAs } from 'file-saver'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { TableRow } from '../../table'; | ||
import { generateCookieTableCSV } from '../../table/utils'; | ||
|
||
const exportCookies = (rows: TableRow[]) => { | ||
const _cookies = rows.map(({ originalData }) => originalData); | ||
if (_cookies.length > 0 && 'parsedCookie' in _cookies[0]) { | ||
const csvTextBlob = generateCookieTableCSV(_cookies as CookieTableData[]); | ||
saveAs(csvTextBlob, 'Cookies Report.csv'); | ||
} | ||
}; | ||
|
||
export default exportCookies; |
18 changes: 18 additions & 0 deletions
18
packages/design-system/src/components/cookieTable/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 exportCookies } from './exportCookies'; | ||
export { default as conditionalTableRowClassesHandler } from './conditionalTableRowClassesHandler'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters