Skip to content

Conversation

@shahrokni
Copy link
Contributor

Closes perses/perses#3771

Description 🖊️

This feature lets users clone dashboard variables. I am not sure if it makes sense to have it for the external variables, so this is only for the internal ones.

image

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the
    following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, DOC,IGNORE.
  • All commits have DCO signoffs.

UI Changes

  • Changes that impact the UI include screenshots and/or screencasts of the relevant changes.
  • Code follows the UI guidelines.
  • E2E tests are stable and unlikely to be flaky.
    See e2e docs for more details. Common issues include:
    • Is the data inconsistent? You need to mock API requests.
    • Does the time change? You need to use consistent time values or mock time utilities.
    • Does it have loading states? You need to wait for loading to complete.

@shahrokni shahrokni requested a review from a team as a code owner January 14, 2026 15:14
@shahrokni shahrokni requested review from AntoineThebaud, Gladorme and jgbernalp and removed request for a team January 14, 2026 15:14
if (v.kind === 'TextVariable') {
draft.push({
...v,
spec: { ...v.spec, value: v.spec.value, name: `${v.spec.name}_copy` },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
spec: { ...v.spec, value: v.spec.value, name: `${v.spec.name}_copy` },
spec: { ...v.spec, name: `${v.spec.name}_copy` },

I think this is redundant, as ...v.spec already copies all properties of v.spec, including value. Then we don't need the if. Or am i missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same idea, but TS throws an exception :(

Property 'value' is missing in type '{ defaultValue?: VariableValue; allowMultiple: boolean; allowAllValue: boolean; customAllValue?: string; capturingRegexp?: string; sort?: string; plugin: Definition<...>; name: VariableName; display?: VariableDisplay; }' but required in type 'WritableDraft'.ts(2345)
variables.d.ts(17, 5): 'value' is declared here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange, ok.

Another potential issue: The current code does a shallow clone, for example v.spec.display on the clone will reference to the display property of the original variable.

I'm not sure if this is an issue when using immer. Could you test to clone a variable, and click hide on the original variable (which sets spec.display.hidden) and make sure the cloned variable is not hidden?

Copy link
Member

@Gladorme Gladorme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we could remove the if condition, but TS is not happy, except if we force with as 😒 Maybe we should enforce with as in this case and remove a if.

>
<ArrowDown />
</IconButton>
<IconButton
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add this new button after the Edit one (next one), as people are more likely to edit variables rather than duplicating them.

As a side note: there may be a broader UX topic to address here but out of scope of this issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

image

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>

Signed-off-by: Mahmoud Shahrokni <seyedmahmoud.shahrokni@amadeus.com>
@shahrokni shahrokni force-pushed the feat/clone_dashboard_variable branch from 4b9fc4f to 199b23f Compare January 14, 2026 15:37
@shahrokni shahrokni merged commit 6f883e6 into main Jan 14, 2026
11 checks passed
@shahrokni shahrokni deleted the feat/clone_dashboard_variable branch January 14, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate dashboard variables

5 participants