I'm trying to make this component into a generic component that can be used anywhere:…
- User
I'm trying to make this component into a generic component that can be used anywhere:
(defn quote-actions [sales-contractor? _ id {{:keys [status sales-order-file-url editable] :as quote} :raw-data idx :idx}] (ra/with-let [is-open (ra/atom false)] [ui/dropdown-button {:key "dropdown" :is-open @is-open :direction "down" :toggle #(reset! is-open (not @is-open)) :style {:height "44px"}} [ui/dropdown-toggle {:key "dropdown-toggle" :style {:width 150} :caret true :color (dropdown-color-logic status sales-order-file-url)} "Quote Actions"] [ui/dropdown-menu {:key "dropdown-menu" :class "dropdown-menu-right"}
[ui/dropdown-item {:key "approve" :disabled @(subscribe [:quote.job/approve-button-disabled? idx]) :on-click #(do (dispatch [:quote.job/open-comment-modal id :approved]) (reset! is-open false))} [:div.d-flex "Approve" (when (and (not (= status :approved)) @(subscribe [:quote.job/approved-quotes-exist?])) [ui/with-popover [:i.fas.fa-question-circle.fa-md.ml-2 {:id (str "approved-existing-" id)}] "An approved quote already exists. If you wish to approve this quote, reject that one first."])]] [ui/dropdown-item {:key "reject" :disabled @(subscribe [:quote.job/reject-button-disabled? idx]) :on-click #(do (dispatch [:quote.job/open-comment-modal id :rejected]) (reset! is-open false))} "Reject"] [ui/dropdown-item {:key "sales-order" :disabled (or (not (= status :approved)) (not (:sales-orders @(subscribe [:organisation/branding-themes]))) ;; Old quotes which don't store quote data cannot make sales orders (not editable)) :on-click #(dispatch [:quote.job/api-create-sales-order id])} [:div.d-flex (if sales-order-file-url "Recreate Sales Order" "Create Sales Order") [ui/with-popover [:i.fas.fa-question-circle.fa-md.ml-2 {:id (str "sales-order-comment-" id)}] (if-not (= status :approved) "In order to create a sales order, the quote needs to be approved first." (if-not editable "This quote was created by an older release and so can not have sales orders." [:p "Please make sure the sales order branding theme is set up in the " [:a {:href "/organisation/config" :target "#"} "organisation settings"] " first. Sales orders are for distribution to people who don't need to see the financial information on a quote, such as employees who will be picking the items."]))]]] (when-not sales-contractor? [:div [:hr] [ui/dropdown-item {:key "delete" :on-click #(dispatch [::events/api-delete-quote id])} "Delete"]])]]))I got about this far:
(defn dropdown-menu-button "Standard dropdown menu button. Takes a config map. Required: :key :title :items" [config] (ra/with-let [is-open (ra/atom false)] [components/dropdown-button {:key (when-not (:key config) (:title config)) :is-open @is-open :toggle #(reset! is-open (not @is-open)) :style (when-not (:style config) {:height "44px"})} [components/dropdown-toggle {:key "dropdown-toggle" :style (when-not (:width config) {:width 150}) :caret (when-not (:caret config) true) :color (when-not (:color config) "primary")} (:title config)] [components/dropdown-menu {:key "dropdown-menu" :class "dropdown-menu-right"} (:items config)]]))
- Assistant
- User
I want it to be structured more in line with this kind of code:
(defn with-popover ([element pop-over-content] (with-popover element pop-over-content {})) ([element pop-over-content {:keys [on-open on-close] :as pop-over-settings}] (assert (or (nil? on-open) (fn? on-open)) "on-open must be a valid function") (assert (or (nil? on-close) (fn? on-close)) "on-close must be a valid function") (ra/with-let [show-popover? (ra/atom false) element-id (str "popover-" (random-uuid))] [:<> [:div {:id element-id :style {:display :inline}} element] [popover (merge {:trigger :hover :placement :top} pop-over-settings {:target element-id :toggle (fn [_] (if @show-popover? (when (fn? on-close) (on-close)) (when (fn? on-open) (on-open))) (ra/rswap! show-popover? not)) :isOpen @show-popover?}) [popover-body pop-over-content]]])))
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.