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

Search Console date range select #79

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/google-search-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@ataverascrespo/react18-ts-textfit": "^1.0.0",
"@triozer/framer-toolbox": "^0.1.14",
"aveta": "^1.4.1",
"downshift": "^9.0.8",
"framer-plugin": "^1.0.0",
"react": "^18",
"react-dom": "^18",
Expand Down
78 changes: 78 additions & 0 deletions plugins/google-search-console/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,81 @@ body[data-framer-theme='dark'] .chart-tooltip-wrapper {
.recharts-cartesian-axis-ticks {
font-variant-numeric: tabular-nums !important;
}

.date-range-header {
text-align: right;
margin-bottom: 1em;
}

.select-container {
position: relative;
padding-top: 1px;
}

.select-button {
display: inline-block;
padding: 0.5em 1em;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
border-radius: 4px;
border: 1px solid rgba(0, 0, 0, 0.1);
}

body[data-framer-theme='dark'] .select-button {
background: var(--framer-color-bg-secondary);
}

.select-button:focus {
outline: none;
}

.select-button:focus-visible {
outline: 2px solid var(--framer-color-tint);
outline-offset: -1px;
}

.select-button:hover,
.select-button:focus-visible,
.select-container--open .select-button {
border-color: rgba(0, 0, 0, 0.2);
}

.select-button--arrow {
display: inline-block;
margin-left: 0.25em;
}

.select-options {
position: absolute;
background-color: var(--framer-color-bg, #fff);
right: 0;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
border: 1px solid var(--framer-color-bg-tertiary);
padding: 0.5em;
text-align: left;
border-radius: 4px;
margin-top: 4px;
display: none;
z-index: 100;
}

.select-container--open .select-options {
display: block;
}

.select-option {
display: block;
padding: 0.5em 2em 0.5em 1em;
border-radius: 4px;
}

.select-option--highlighted {
background-color: rgba(0, 0, 0, 0.025);
}

body[data-framer-theme='dark'] .select-option--highlighted {
background: var(--framer-color-bg-secondary);
}

.select-option--selected {
font-weight: 600;
}
79 changes: 79 additions & 0 deletions plugins/google-search-console/src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { useSelect, UseSelectSelectedItemChange } from 'downshift';

export interface SelectOption {
id: number | string;
title: string;
}

interface SelectProps {
selected: SelectOption;
options: SelectOption[];
onChange: (changes: UseSelectSelectedItemChange<SelectOption>) => void;
}

function itemToString(item: SelectOption | null) {
return item ? item.title : '';
}

export default function Select({
selected: selectedItem,
options,
onChange,
}: SelectProps) {
const {
isOpen,
getToggleButtonProps,
getMenuProps,
highlightedIndex,
getItemProps,
} = useSelect({
items: options,
itemToString,
selectedItem,
onSelectedItemChange: onChange,
});

return (
<div
className={[
'select-container',
isOpen ? 'select-container--open' : undefined,
].join(' ')}
>
<div className="w-72 flex flex-col gap-1">
<div className="select-button" {...getToggleButtonProps()}>
<span>{selectedItem ? selectedItem.title : 'Select a range'}</span>
<span className="select-button--arrow">
{isOpen ? <>&#8593;</> : <>&#8595;</>}
</span>
</div>
</div>
<ul
// className={`absolute w-72 bg-white mt-1 shadow-md max-h-80 overflow-scroll p-0 z-10 ${
// !isOpen && 'hidden'
// }`}
className="select-options"
{...getMenuProps()}
>
{isOpen &&
options.map((item, index) => (
<li
className={[
'select-option',
highlightedIndex === index
? 'select-option--highlighted'
: undefined,
selectedItem.id === item.id
? 'select-option--selected'
: undefined,
].join(' ')}
key={item.id}
{...getItemProps({ item, index })}
>
<span>{item.title}</span>
</li>
))}
</ul>
</div>
);
}
9 changes: 6 additions & 3 deletions plugins/google-search-console/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,23 @@ function randomIntFromInterval(min: number, max: number) {
return Math.floor(min + Math.random() * (max - min + 1));
}

export function useMockPerformanceResults(): {
export function useMockPerformanceResults(
siteUrl: string,
dates: string[],
): {
dailyPerformance: GoogleQueryResult;
queryPerformance: GoogleQueryResult;
} {
const getRandomData = (): number[][] => {
const savedData = window.localStorage.getItem(
'searchConsoleRandomChartData',
`searchConsoleRandomChartData_${dates.length}`,
) as string;

if (savedData) {
return JSON.parse(savedData);
}

const randomDataGen = [...new Array(14)].map(() => {
const randomDataGen = [...new Array(dates.length)].map(() => {
const clicks = randomIntFromInterval(1000, 3000);
const impressions = clicks + randomIntFromInterval(1000, 3000);

Expand Down
Loading