Skip to content

feat: archive template versions to hide them from the ui #10179

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

Merged
merged 17 commits into from
Oct 11, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Oct 10, 2023

What this does

Allows "archiving" template versions to clean them up from the UX. By default archived are not listed when calling /versions for a template. This action is reversible. Archived versions cannot be promoted or used in workspace builds.

Template versions that are in use or the current active template version cannot be archived.

Closes #9478

Cli Commands

Archive a template

# Archive all failed template versions for the template 'docker'
$ coder templates archive docker
# Archive all unused template versions
$ coder templates archive docker --all

Screenshot from 2023-10-09 18-21-59

Archive a template version

Archive/unarchive specific versions.

# Archive
$ coder templates versions archive docker strange_khorana9
Version strange_khorana9 archived at Oct  9 18:22:41


# Unarchive
$ coder templates versions unarchive docker strange_khorana9
Version strange_khorana9 unarchived at Oct  9 18:22:41

Future Work

  • Allow the UI to see archived versions with some toggle
  • Allow UI to archive/unarchive versions

}

if !templateVersion.TemplateID.Valid {
// Maybe we should allow this?
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not allowing arching orphaned versions atm, as it makes them impossible to find. Not sure what we should do with orphaned versions, but we can make this a follow up.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what a user could even do with these? I think it makes sense to kick this one down the road.

Base automatically changed from stevenmasley/add_archive_column to main October 10, 2023 15:52
@Emyrk Emyrk requested a review from johnstcn October 10, 2023 16:29
Comment on lines +62 to +84
func(next clibase.HandlerFunc) clibase.HandlerFunc {
return func(i *clibase.Invocation) error {
// This is the only way to dynamically add the "archived"
// column if '--include-archived' is true.
// It does not make sense to show this column if the
// flag is false.
if includeArchived {
for _, opt := range i.Command.Options {
if opt.Flag == "column" {
if opt.ValueSource == clibase.ValueSourceDefault {
v, ok := opt.Value.(*clibase.StringArray)
if ok {
// Add the extra new default column.
*v = append(*v, "Archived")
}
}
break
}
}
}
return next(i)
}
},
Copy link
Member

Choose a reason for hiding this comment

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

👀 That's cool, didn't know you could do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, it's a little janky imo, but the value is tied to the option 😢.

If we have to do this more often, I can create a helper Middleware to do this more generally.

Copy link
Member Author

Choose a reason for hiding this comment

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

This only adds the column if the user is using the default columns

}

if !templateVersion.TemplateID.Valid {
// Maybe we should allow this?
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what a user could even do with these? I think it makes sense to kick this one down the road.

@Emyrk Emyrk requested a review from johnstcn October 10, 2023 19:27
Comment on lines 8 to 17
"github.com/coder/coder/v2/provisioner/echo"

"github.com/coder/coder/v2/codersdk"

"github.com/coder/coder/v2/testutil"

"github.com/coder/coder/v2/coderd/rbac"

"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/coderd/coderdtest"
Copy link
Member

Choose a reason for hiding this comment

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

imports

Comment on lines +5348 to +5349
q.mutex.Lock()
defer q.mutex.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

I always forget this

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently same lol

@Emyrk Emyrk merged commit 1e950fa into main Oct 11, 2023
@Emyrk Emyrk deleted the stevenmasley/archive_api_cli branch October 11, 2023 14:26
@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Archive old template versions
2 participants