-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin partners page improvements (#7140)
* Import stylesheet * Add admin component, add width variable * Adjust adverts perk width + add track slugs * Add track slugs col * Add TrackSlugselector, Save values in a hidden field * Set up default values * Correctly type multiselect ref, permit track_slugs * Clarify comment * Remove logging * Tiny visual adjustments (#7142) * Optimise
- Loading branch information
Showing
12 changed files
with
192 additions
and
9 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
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,23 @@ | ||
body.namespace-admin.controller-partners.action-show, | ||
body.namespace-admin.controller-perks.action-show, | ||
body.namespace-admin.controller-adverts.action-show { | ||
.c-perk-a { | ||
width: var(--c-perk-a-width); | ||
} | ||
|
||
.c-perk-status-tag { | ||
@apply border-1 px-2 py-[1px] rounded-5; | ||
&.active { | ||
@apply border-[#22c55e] text-[#22c55e]; | ||
} | ||
&.retired { | ||
@apply border-[#3b82f6] text-[#3b82f6]; | ||
} | ||
&.pending { | ||
@apply border-[#facc15] text-[#facc15]; | ||
} | ||
&.out_of_budget { | ||
@apply border-[#ef4444] text-[#ef4444]; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
@import "../pages/admin/page"; | ||
@import "../pages/admin/table"; | ||
@import "../components/admin"; |
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
11 changes: 11 additions & 0 deletions
11
app/helpers/react_components/common/track_slugs_multiselector.rb
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,11 @@ | ||
module ReactComponents | ||
module Common | ||
class TrackSlugsMultiselector < ReactComponent | ||
initialize_with :track_slugs, :selected_track_slugs | ||
|
||
def to_s | ||
super("common-track-slugs-multiselector", { track_slugs:, selected_track_slugs: }) | ||
end | ||
end | ||
end | ||
end |
117 changes: 117 additions & 0 deletions
117
app/javascript/components/common/TrackSlugsMultiselector.tsx
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,117 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import { SelectInstance, GroupBase } from 'react-select' | ||
import CreatableSelect from 'react-select/creatable' | ||
|
||
type OptionType = { | ||
label: string | ||
value: string | ||
} | ||
|
||
export default function TrackSlugsMultiselector({ | ||
trackSlugs, | ||
selectedTrackSlugs, | ||
}: { | ||
trackSlugs: string[] | ||
selectedTrackSlugs: string // comes as a JSON array | ||
}): JSX.Element { | ||
const trackSlugsHiddenInputRef = useRef<HTMLInputElement | null>(null) | ||
const selectRef = | ||
useRef<SelectInstance<OptionType, true, GroupBase<OptionType>>>(null) | ||
|
||
useEffect(() => { | ||
trackSlugsHiddenInputRef.current = document.querySelector( | ||
'#partner_advert_track_slugs' | ||
) as HTMLInputElement | ||
|
||
if (trackSlugsHiddenInputRef.current) { | ||
trackSlugsHiddenInputRef.current.value = | ||
JSON.stringify(selectedTrackSlugs) | ||
} | ||
}, [selectedTrackSlugs]) | ||
|
||
// Removes the annoying blue box-shadow on the embedded input | ||
const handleFocus = () => { | ||
if (selectRef.current) { | ||
const input = selectRef.current.inputRef | ||
|
||
if (input) { | ||
input.style.boxShadow = 'none' | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<CreatableSelect | ||
isMulti | ||
ref={selectRef} | ||
defaultValue={formatTags(JSON.parse(selectedTrackSlugs))} | ||
options={formatTags(trackSlugs)} | ||
isClearable={false} | ||
maxMenuHeight={100} | ||
onFocus={handleFocus} | ||
styles={{ | ||
valueContainer: (base) => ({ | ||
...base, | ||
padding: '8px', | ||
}), | ||
|
||
indicatorSeparator: (base) => ({ | ||
...base, | ||
display: 'none', | ||
'&:focus': { | ||
border: 'none', | ||
outline: 'none', | ||
}, | ||
}), | ||
indicatorsContainer: (base) => ({ | ||
...base, | ||
display: 'none', | ||
border: 'none', | ||
'&:focus': { | ||
border: 'none', | ||
outline: 'none', | ||
}, | ||
}), | ||
|
||
multiValue: (base) => ({ | ||
...base, | ||
borderRadius: '8px', | ||
overflow: 'hidden', | ||
backgroundColor: 'var(--backgroundColorI)', | ||
border: '1px solid', | ||
borderColor: '#2E57E8', | ||
margin: '4px', | ||
}), | ||
multiValueLabel: (base) => ({ | ||
...base, | ||
fontSize: '16px', | ||
padding: '4px', | ||
paddingLeft: '8px', | ||
}), | ||
multiValueRemove: (base) => ({ | ||
...base, | ||
paddingRight: '8px', | ||
color: 'var(--textColor6)', | ||
'&:hover': { | ||
background: '#E27979', | ||
color: 'var(--textColor1)', | ||
}, | ||
}), | ||
}} | ||
onChange={(selected): void => { | ||
if (trackSlugsHiddenInputRef.current) { | ||
trackSlugsHiddenInputRef.current.value = JSON.stringify( | ||
selected.map((s) => s.value) | ||
) | ||
} | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
function formatTags(tags: string[]) { | ||
return tags.map((tag) => ({ | ||
label: tag, | ||
value: tag, | ||
})) | ||
} |
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
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
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